Inheritance: System.Type, _EnumBuilder
Example #1
0
 public void PosTest1()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     Assembly myAssem = _myEnumBuilder.Assembly;
     Assert.Equal(_myAssemblyBuilder.FullName, myAssem.FullName);
 }
 public void TestDeclaringTypeProperty()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     Type myDeclaringType = _myEnumBuilder.DeclaringType;
     Assert.Null(myDeclaringType);
 }
Example #3
0
 public void TestModuleProperty()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     Module myModule = _myEnumBuilder.Module;
     Assert.True(myModule.Equals(_myModuleBuilder));
 }
 public void PosTest1()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     Type myType = _myEnumBuilder.MakePointerType();
     Assert.True(myType.GetTypeInfo().BaseType.Equals(typeof(Array)));
     Assert.Equal(myType.Name, "myEnum*");
 }
Example #5
0
 public void TestBaseTypeProperty()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     Type myBaseType = _myEnumBuilder.BaseType;
     Assert.Equal(typeof(Enum), myBaseType);
 }
 public void TestNamespaceProperty()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     string myEnumNamespace = _myEnumBuilder.Namespace;
     Assert.Equal("", myEnumNamespace);
 }
Example #7
0
 public void TestFullNameProperty()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.AsType();
     string myFullName = _myEnumBuilder.FullName;
     Assert.Equal(_myEnumBuilder.FullName, myFullName);
 }
 public void TestDefineLiteral()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     FieldBuilder myField = _myEnumBuilder.DefineLiteral("FieldOne", 1);
     _myEnumBuilder.AsType();
     Assert.True(myField.IsLiteral);
     Assert.True(myField.IsPublic);
     Assert.True(myField.IsStatic);
 }
 public void TestSetCustomAttribute()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     _myEnumBuilder.CreateTypeInfo().AsType();
     _myEnumBuilder.SetCustomAttribute(_myInfo, new byte[] { 01, 00, 01 });
     object[] objVals = _myEnumBuilder.GetCustomAttributes(true).Select(a => (object)a).ToArray().Select(a => (object)a).ToArray();
     Assert.Equal(1, objVals.Length);
     Assert.True(objVals[0].Equals(new EBMyAttribute(true)));
 }
Example #10
0
        public EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type underlyingType)
        {
            if (name_cache.Contains(name))
            {
                throw new ArgumentException("Duplicate type name within an assembly.");
            }

            EnumBuilder eb  = new EnumBuilder(this, name, visibility, underlyingType);
            TypeBuilder res = eb.GetTypeBuilder();

            AddType(res);
            name_cache.Add(name, res);
            return(eb);
        }
Example #11
0
 // Get a type token by type.
 public TypeToken GetTypeToken(Type type)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     else if (type is TypeBuilder)
     {
         TypeBuilder tb = (type as TypeBuilder);
         if (tb.module == this)
         {
             return(tb.TypeToken);
         }
     }
     else if (type is EnumBuilder)
     {
         EnumBuilder eb = (type as EnumBuilder);
         if (eb.builder.module == this)
         {
             return(eb.builder.TypeToken);
         }
     }
     else if (type is ClrType)
     {
         if (type.IsByRef)
         {
             throw new ArgumentException
                       (_("Emit_CannotImportRefType"));
         }
         lock (typeof(AssemblyBuilder))
         {
             return(new TypeToken
                        (TypeBuilder.ClrTypeImport
                            (privateData, ((ClrType)type).ClrHandle)));
         }
     }
     throw new InvalidOperationException(_("Emit_CannotImportItem"));
 }
Example #12
0
 internal static void DefineCustomAttributes(EnumBuilder member, ReadOnlyCollection<AttributeAst> attributes, Parser parser, AttributeTargets attributeTargets)
 {
     if (attributes != null)
     {
         foreach (var attr in attributes)
         {
             var cabuilder = GetAttributeBuilder(parser, attr, attributeTargets);
             if (cabuilder != null)
             {
                 member.SetCustomAttribute(cabuilder);
             }
         }
     }
 }
 private EnumBuilder DefineEnumNoLock(string name, TypeAttributes visibility, Type underlyingType)
 {
     EnumBuilder type = new EnumBuilder(name, underlyingType, visibility, this);
     this.AddType(type);
     return type;
 }
Example #14
0
		private static FieldBuilder GenerateField (EnumBuilder enumBuilder)
		{
			return enumBuilder.DefineLiteral (_fieldName, _fieldValue);
		}
Example #15
0
		public EnumBuilder DefineEnum( string name, TypeAttributes visibility, Type underlyingType) {
			if (name_cache.Contains (name))
				throw new ArgumentException ("Duplicate type name within an assembly.");

			EnumBuilder eb = new EnumBuilder (this, name, visibility, underlyingType);
			TypeBuilder res = eb.GetTypeBuilder ();
			AddType (res);
			name_cache.Add (name, res);
			return eb;
		}
Example #16
0
 private void AddEnumToCloseList(EnumBuilder emb)
 {
     enums.Add(emb);
 }
 public void NegTest1()
 {
     CreateCallee();
     _myEnumBuilder = _myModuleBuilder.DefineEnum("myEnum", TypeAttributes.Public, typeof(int));
     Assert.Throws<NotSupportedException>(() => { Type typeVal = _myEnumBuilder.GetElementType(); });
 }
Example #18
0
        // Define Enum
        /// <include file='doc\ModuleBuilder.uex' path='docs/doc[@for="ModuleBuilder.DefineEnum"]/*' />
        
        public EnumBuilder DefineEnum(            
            String      name,                       // name of type
            TypeAttributes visibility,              // any bits on TypeAttributes.VisibilityMask)
            Type        underlyingType)             // underlying type for an Enum
        {
            CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit);
            try
            {
                Enter();

                BCLDebug.Log("DYNIL","## DYNIL LOGGING: ModuleBuilder.DefineEnum( " + name + " )");
                EnumBuilder enumBuilder;
                enumBuilder = new EnumBuilder(name, underlyingType, visibility, this);
                m_TypeBuilderList.Add(enumBuilder);
                return enumBuilder;
            }
            finally
            {
                Exit();
            }
        }
		void Add(string name, EnumBuilder builder) {
			if (enumBuilders.ContainsKey(name))
				throw new ApplicationException(string.Format("Enum {0} already exists", name));
			enumBuilders[name] = builder;
		}
Example #20
0
 public EnumLambda(EnumBuilder enumBuilder)
 {
     this.EnumBuilder = enumBuilder;
 }
Example #21
0
 public TypeInfo AddEnum(ITypeNode type, EnumBuilder emb)
 {
     TypeInfo ti = new TypeInfo(emb);
     defs[type] = ti;
     return ti;
 }
Example #22
0
 [System.Security.SecurityCritical]  // auto-generated
 private EnumBuilder DefineEnumNoLock(String name, TypeAttributes visibility, Type underlyingType)
 {
     EnumBuilder enumBuilder; 
     enumBuilder = new EnumBuilder(name, underlyingType, visibility, this);
     AddType(enumBuilder); 
     return enumBuilder; 
 }