|
6 | 6 | using System.CodeDom;
|
7 | 7 | using System.Collections.Generic;
|
8 | 8 | using System.Linq;
|
| 9 | +using System.Reflection; |
9 | 10 | using Microsoft.CSharp;
|
10 | 11 | using Microsoft.ML.Runtime.CommandLine;
|
11 | 12 | using Microsoft.ML.Runtime.EntryPoints;
|
@@ -279,10 +280,22 @@ public static string GetValue(ModuleCatalog catalog, Type fieldType, object fiel
|
279 | 280 | case TlcModule.DataKind.Bool:
|
280 | 281 | return (bool)fieldValue ? "true" : "false";
|
281 | 282 | case TlcModule.DataKind.Enum:
|
| 283 | + string enumAsString = fieldValue.ToString(); |
| 284 | + if (fieldType.GetField(enumAsString).GetCustomAttribute<HideEnumValueAttribute>() != null) |
| 285 | + { |
| 286 | + // The default value for the enum has the hiding attribute on it. We will search for |
| 287 | + // alternate names. Regrettably I see no way beyond a manual scan. |
| 288 | + |
| 289 | + string unhiddenName = Enum.GetNames(fieldType).Zip(Enum.GetValues(fieldType).Cast<object>(), (name, val) => (name, val)) |
| 290 | + .Where(pair => pair.val.Equals(fieldValue)) |
| 291 | + .Where(pair => fieldType.GetField(pair.name).GetCustomAttribute<HideEnumValueAttribute>() == null) |
| 292 | + .Select(pair => pair.name).FirstOrDefault(); |
| 293 | + enumAsString = unhiddenName ?? throw Contracts.Except($"Could not find unhidden alternative for '{fieldValue}' in type '{fieldType}'"); |
| 294 | + } |
282 | 295 | if (generatedClasses.IsGenerated(fieldType.FullName))
|
283 |
| - return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + fieldValue; |
| 296 | + return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + enumAsString; |
284 | 297 | else
|
285 |
| - return generatedClasses.GetApiName(fieldType, "Runtime") + "." + fieldValue; |
| 298 | + return generatedClasses.GetApiName(fieldType, "Runtime") + "." + enumAsString; |
286 | 299 | case TlcModule.DataKind.Char:
|
287 | 300 | return $"'{GetCharAsString((char)fieldValue)}'";
|
288 | 301 | case TlcModule.DataKind.Component:
|
|
0 commit comments