public void AsEnumTest() { using DataTarget dt = TestTargets.Types.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule typesModule = runtime.GetModule(ModuleName); ClrType type = typesModule.GetTypeByName("Types"); ClrStaticField field = type.GetStaticFieldByName("s_enum"); Assert.True(field.Type.IsEnum); ClrEnum clrEnum = field.Type.AsEnum(); Assert.NotNull(clrEnum); string[] propertyNames = clrEnum.GetEnumNames().ToArray(); Assert.NotEmpty(propertyNames); Assert.Contains(nameof(FileAccess.Read), propertyNames); Assert.Contains(nameof(FileAccess.Write), propertyNames); Assert.Contains(nameof(FileAccess.ReadWrite), propertyNames); Assert.Equal(ClrElementType.Int32, clrEnum.ElementType); Assert.Equal(FileAccess.Read, clrEnum.GetEnumValue <FileAccess>(nameof(FileAccess.Read))); Assert.Equal(FileAccess.Write, clrEnum.GetEnumValue <FileAccess>(nameof(FileAccess.Write))); Assert.Equal(FileAccess.ReadWrite, clrEnum.GetEnumValue <FileAccess>(nameof(FileAccess.ReadWrite))); }
public void Test10() { var choices = Choices.FromEnum <Pick>(); claim.count(ClrEnum.Get <Pick>().Literals.Count, choices.Stream()); }
/// <summary> /// Returns the identifiers as determined by defined enum literals and/or attributions /// </summary> /// <typeparam name="E">The enum type</typeparam> /// <returns></returns> public static IReadOnlyList <string> identifiers <E>() where E : Enum => _enumIdentifiers.GetOrAdd(typeof(E), _ => ClrEnum.Get <E>().Identifiers.Stream().ToReadOnlyList());
public static ClrEnumInfo FromType(ClrEnum e) => new ClrEnumInfo(e.Name, e.GetLiteralType().Name, from l in e.Literals select new ClrEnumLiteralInfo(l.LiteralName, l.LiteralValue) );
public static Seq <EnumChoice <E> > FromEnum <E>() where E : Enum => from l in ClrEnum.Get <E>().Literals select new EnumChoice <E>(parseEnum <E>(l.LiteralName));