Exemple #1
0
        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)));
        }
Exemple #2
0
        public void Test10()
        {
            var choices = Choices.FromEnum <Pick>();

            claim.count(ClrEnum.Get <Pick>().Literals.Count, choices.Stream());
        }
Exemple #3
0
 /// <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());
Exemple #4
0
 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)
                    );
Exemple #5
0
 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));