示例#1
0
        public DynamicType DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
        {
            TypeBuilder typeBuilder = builder.DefineType(name, attr, parent, packingSize, typesize);
            DynamicType type        = new DynamicType(typeBuilder, this);

            return(type);
        }
示例#2
0
 public TypeBuilder DefineType(String name, TypeAttributes attr,
                               Type parent, PackingSize packSize,
                               int typeSize)
 {
     return(DefineType(name, attr, parent, null,
                       packSize, typeSize));
 }
示例#3
0
 public TypeBuilder DefineStructType(string name, TypeAttributes attr, PackingSize packingSize, int typesize)
 {
     lock (gate)
     {
         return(moduleBuilder.DefineType(name, attr, typeof(ValueType), packingSize, typesize));
     }
 }
示例#4
0
 // Define a type witin this module.
 private TypeBuilder DefineType(String name, TypeAttributes attr,
                                Type parent, Type[] interfaces,
                                PackingSize packSize, int typeSize)
 {
     try
     {
         StartSync();
         int    index = name.LastIndexOf('.');
         String nspace;
         if (index != -1)
         {
             nspace = name.Substring(0, index);
             name   = name.Substring(index + 1);
         }
         else
         {
             nspace = null;
         }
         return(new TypeBuilder(this, name, nspace, attr,
                                parent, interfaces, packSize,
                                typeSize, null));
     }
     finally
     {
         EndSync();
     }
 }
        public void DefineNestedType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
        {
            bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
            bool isDefaultPackingSize = packingSize == PackingSize.Unspecified;
            bool isDefaultSize = typesize == 0;
            bool isDefaultParent = parent == null;
            bool isDefaultAttributes = attributes == TypeAttributes.NestedPrivate;

            Action<TypeBuilder, TypeBuilder> verify = (type, declaringType) =>
            {
                bool allowsNullParent = attributes.HasFlag(TypeAttributes.Abstract) && attributes.HasFlag(TypeAttributes.ClassSemanticsMask);
                Type baseType = allowsNullParent ? parent : (parent ?? typeof(object));
                Helpers.VerifyType(type, declaringType.Module, declaringType, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
            };

            if (isDefaultImplementedInterfaces)
            {
                if (isDefaultSize && isDefaultPackingSize)
                {
                    if (isDefaultParent)
                    {
                        if (isDefaultAttributes)
                        {
                            // Use DefineNestedType(string)
                            TypeBuilder type1 = Helpers.DynamicType(TypeAttributes.Public);
                            verify(type1.DefineNestedType(name), type1);
                        }
                        // Use DefineNestedType(string, TypeAttributes)
                        TypeBuilder type2 = Helpers.DynamicType(TypeAttributes.Public);
                        verify(type2.DefineNestedType(name, attributes), type2);
                    }
                    // Use DefineNestedType(string, TypeAttributes, Type)
                    TypeBuilder type3 = Helpers.DynamicType(TypeAttributes.Public);
                    verify(type3.DefineNestedType(name, attributes, parent), type3);
                }
                else if (isDefaultSize)
                {
                    // Use DefineNestedType(string, TypeAttributes, Type, PackingSize)
                    TypeBuilder type4 = Helpers.DynamicType(TypeAttributes.Public);
                    verify(type4.DefineNestedType(name, attributes, parent, packingSize), type4);
                }
                else if (isDefaultPackingSize)
                {
                    // Use DefineNestedType(string, TypeAttributes, Type, int)
                    TypeBuilder type5 = Helpers.DynamicType(TypeAttributes.Public);
                    verify(type5.DefineNestedType(name, attributes, parent, typesize), type5);
                }
                // Use DefineNestedType(string, TypeAttributes, Type, PackingSize, int);
                TypeBuilder type6 = Helpers.DynamicType(TypeAttributes.Public);
                verify(type6.DefineNestedType(name, attributes, parent, packingSize, typesize), type6);
            }
            else
            {
                // Use DefineNestedType(string, TypeAttributes, Type, Type[])
                Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
                TypeBuilder type7 = Helpers.DynamicType(TypeAttributes.Public);
                verify(type7.DefineNestedType(name, attributes, parent, implementedInterfaces), type7);
            }
        }
        public void DefineType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
        {
            bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
            bool isDefaultPackingSize           = packingSize == PackingSize.Unspecified;
            bool isDefaultSize       = typesize == 0;
            bool isDefaultParent     = parent == null;
            bool isDefaultAttributes = attributes == TypeAttributes.NotPublic;

            void Verify(TypeBuilder type, Module module)
            {
                Type baseType = attributes.HasFlag(TypeAttributes.Abstract) && parent == null ? null : (parent ?? typeof(object));

                Helpers.VerifyType(type, module, null, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
            }

            if (isDefaultImplementedInterfaces)
            {
                if (isDefaultSize && isDefaultPackingSize)
                {
                    if (isDefaultParent)
                    {
                        if (isDefaultAttributes)
                        {
                            // Use DefineType(string)
                            ModuleBuilder module1 = Helpers.DynamicModule();
                            Verify(module1.DefineType(name), module1);
                        }
                        // Use DefineType(string, TypeAttributes)
                        ModuleBuilder module2 = Helpers.DynamicModule();
                        Verify(module2.DefineType(name, attributes), module2);
                    }
                    // Use DefineType(string, TypeAttributes, Type)
                    ModuleBuilder module3 = Helpers.DynamicModule();
                    Verify(module3.DefineType(name, attributes, parent), module3);
                }
                else if (isDefaultSize)
                {
                    // Use DefineType(string, TypeAttributes, Type, PackingSize)
                    ModuleBuilder module4 = Helpers.DynamicModule();
                    Verify(module4.DefineType(name, attributes, parent, packingSize), module4);
                }
                else if (isDefaultPackingSize)
                {
                    // Use DefineType(string, TypeAttributes, Type, int)
                    ModuleBuilder module5 = Helpers.DynamicModule();
                    Verify(module5.DefineType(name, attributes, parent, typesize), module5);
                }
                // Use DefineType(string, TypeAttributes, Type, PackingSize, int)
                ModuleBuilder module6 = Helpers.DynamicModule();
                Verify(module6.DefineType(name, attributes, parent, packingSize, typesize), module6);
            }
            else
            {
                // Use DefineType(string, TypeAttributes, Type, Type[])
                Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
                ModuleBuilder module7 = Helpers.DynamicModule();
                Verify(module7.DefineType(name, attributes, parent, implementedInterfaces), module7);
            }
        }
        public void DefineType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
        {
            bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
            bool isDefaultPackingSize = packingSize == PackingSize.Unspecified;
            bool isDefaultSize = typesize == 0;
            bool isDefaultParent = parent == null;
            bool isDefaultAttributes = attributes == TypeAttributes.NotPublic;

            Action<TypeBuilder, Module> verify = (type, module) =>
            {
                Type baseType = attributes.HasFlag(TypeAttributes.Abstract) && parent == null ? null : (parent ?? typeof(object));
                Helpers.VerifyType(type, module, null, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
            };

            if (isDefaultImplementedInterfaces)
            {
                if (isDefaultSize && isDefaultPackingSize)
                {
                    if (isDefaultParent)
                    {
                        if (isDefaultAttributes)
                        {
                            // Use DefineType(string)
                            ModuleBuilder module1 = Helpers.DynamicModule();
                            verify(module1.DefineType(name), module1);
                        }
                        // Use DefineType(string, TypeAttributes)
                        ModuleBuilder module2 = Helpers.DynamicModule();
                        verify(module2.DefineType(name, attributes), module2);
                    }
                    // Use DefineType(string, TypeAttributes, Type)
                    ModuleBuilder module3 = Helpers.DynamicModule();
                    verify(module3.DefineType(name, attributes, parent), module3);
                }
                else if (isDefaultSize)
                {
                    // Use DefineType(string, TypeAttributes, Type, PackingSize)
                    ModuleBuilder module4 = Helpers.DynamicModule();
                    verify(module4.DefineType(name, attributes, parent, packingSize), module4);
                }
                else if (isDefaultPackingSize)
                {
                    // Use DefineType(string, TypeAttributes, Type, int)
                    ModuleBuilder module5 = Helpers.DynamicModule();
                    verify(module5.DefineType(name, attributes, parent, typesize), module5);
                }
                // Use DefineType(string, TypeAttributes, Type, PackingSize, int)
                ModuleBuilder module6 = Helpers.DynamicModule();
                verify(module6.DefineType(name, attributes, parent, packingSize, typesize), module6);
            }
            else
            {
                // Use DefineType(string, TypeAttributes, Type, Type[])
                Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
                ModuleBuilder module7 = Helpers.DynamicModule();
                verify(module7.DefineType(name, attributes, parent, implementedInterfaces), module7);
            }
        }
        public void PackagingSize_Set_ReturnsExpected(PackingSize packingSize)
        {
            ModuleBuilder module = Helpers.DynamicModule();
            TypeBuilder type = module.DefineType("TestType", TypeAttributes.Class | TypeAttributes.Public, null, packingSize);
            Assert.Equal(packingSize, type.PackingSize);

            type.DefineGenericParameters("T", "U");
            Assert.Equal(packingSize, type.PackingSize);
        }
        public void PackagingSize_Set_ReturnsExpected(PackingSize packingSize)
        {
            ModuleBuilder module = Helpers.DynamicModule();
            TypeBuilder   type   = module.DefineType("TestType", TypeAttributes.Class | TypeAttributes.Public, null, packingSize);

            Assert.Equal(packingSize, type.PackingSize);

            type.DefineGenericParameters("T", "U");
            Assert.Equal(packingSize, type.PackingSize);
        }
示例#10
0
        public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
        {
            if (parent == null && (attr & TypeAttributes.Interface) == 0)
            {
                parent = universe.System_Object;
            }
            TypeBuilder typeBuilder = new TypeBuilder(this, name, parent, attr);

            PostDefineType(typeBuilder, packingSize, typesize);
            return(typeBuilder);
        }
示例#11
0
 private void PostDefineType(TypeBuilder typeBuilder, PackingSize packingSize, int typesize)
 {
     types.Add(typeBuilder);
     fullNameToType.Add(typeBuilder.FullName, typeBuilder);
     if (packingSize != PackingSize.Unspecified || typesize != 0)
     {
         ClassLayoutTable.Record rec = new ClassLayoutTable.Record();
         rec.PackingSize = (short)packingSize;
         rec.ClassSize   = typesize;
         rec.Parent      = typeBuilder.MetadataToken;
         this.ClassLayout.AddRecord(rec);
     }
 }
示例#12
0
 // Define a nested type within this class.
 private TypeBuilder DefineNestedType
     (String name, TypeAttributes attr, Type parent,
     Type[] interfaces, int typeSize, PackingSize packingSize)
 {
     try
     {
         StartSync();
         return(new TypeBuilder(module,
                                name, null, attr, parent,
                                interfaces, packingSize,
                                typeSize, this));
     }
     finally
     {
         EndSync();
     }
 }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Code))
            {
                yield return(new ValidationResult("Kode harus diisi", new List <string> {
                    "Code"
                }));
            }
            else if (!long.TryParse(Code, out long code))
            {
                yield return(new ValidationResult("Kode harus berupa angka", new List <string> {
                    "Code"
                }));
            }

            if (string.IsNullOrEmpty(Name))
            {
                yield return(new ValidationResult("Nama Packing harus diisi", new List <string> {
                    "Name"
                }));
            }

            if (ProductSKUId.GetValueOrDefault() <= 0)
            {
                yield return(new ValidationResult("Barang SKU harus diisi", new List <string> {
                    "ProductSKU"
                }));
            }

            if (UOMId.GetValueOrDefault() <= 0)
            {
                yield return(new ValidationResult("Satuan harus diisi", new List <string> {
                    "UOM"
                }));
            }

            if (PackingSize.GetValueOrDefault() <= 0)
            {
                yield return(new ValidationResult("Kuantiti per packing harus diisi", new List <string> {
                    "PackingSize"
                }));
            }
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (PackingSize.GetValueOrDefault() > 0)
            {
                yield return(new ValidationResult("Quantity harus diisi", new List <string> {
                    "PackingSize"
                }));
            }

            if (SKUId.GetValueOrDefault() > 0)
            {
                yield return(new ValidationResult("SKU harus diisi", new List <string> {
                    "SKUId"
                }));
            }

            if (PackingUOMId.GetValueOrDefault() > 0)
            {
                yield return(new ValidationResult("Jenis Packing harus diisi", new List <string> {
                    "PackingUOMId"
                }));
            }
        }
示例#15
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (PackingSize.GetValueOrDefault() > 0)
            {
                yield return(new ValidationResult("Quantity harus diisi", new List <string> {
                    "PackingSize"
                }));
            }

            if (string.IsNullOrWhiteSpace(SKUCode))
            {
                yield return(new ValidationResult("Kode SKU harus diisi", new List <string> {
                    "SKUCode"
                }));
            }

            if (string.IsNullOrWhiteSpace(PackingUOM))
            {
                yield return(new ValidationResult("Jenis Packing harus diisi", new List <string> {
                    "PackingUOM"
                }));
            }
        }
示例#16
0
        public static void VerifyType(TypeBuilder type, Module module, TypeBuilder declaringType, string name, TypeAttributes attributes, Type baseType, int size, PackingSize packingSize, Type[] implementedInterfaces)
        {
            Assert.Same(module, type.Module);
            Assert.Same(module.Assembly, type.Assembly);

            Assert.Equal(name, type.Name);
            if (declaringType == null)
            {
                Assert.Equal(GetFullName(name), type.FullName);
            }
            else
            {
                Assert.Equal(GetFullName(declaringType.Name) + "+" + GetFullName(type.Name), type.FullName);
            }

            Assert.Equal(attributes, type.Attributes);

            Assert.Equal(declaringType?.AsType(), type.DeclaringType);
            Assert.Equal(baseType, type.BaseType);

            Assert.Equal(size, type.Size);
            Assert.Equal(packingSize, type.PackingSize);

            Assert.Equal(implementedInterfaces ?? new Type[0], type.ImplementedInterfaces);

            if (declaringType == null && !type.IsInterface && (implementedInterfaces == null || implementedInterfaces.Length == 0))
            {
                Type createdType = type.CreateTypeInfo().AsType();
                Assert.Equal(createdType, module.GetType(name, false, false));
                Assert.Equal(createdType, module.GetType(name, true, false));

                // [ActiveIssue(10989, TestPlatforms.AnyUnix)]
                // Assert.Equal(createdType, module.GetType(name, true, true));
                // Assert.Equal(createdType, module.GetType(name.ToLowerInvariant(), true, true));
                // Assert.Equal(createdType, module.GetType(name.ToUpperInvariant(), true, true));
            }
        }
示例#17
0
 [System.Security.SecurityCritical]  // auto-generated
 private TypeBuilder DefineNestedTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packSize, int typeSize)
 {
     return new TypeBuilder(name, attr, parent, interfaces, m_module, packSize, typeSize, this);
 }
示例#18
0
        public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
        {
            string ns      = null;
            int    lastdot = name.LastIndexOf('.');

            if (lastdot > 0)
            {
                ns   = name.Substring(0, lastdot);
                name = name.Substring(lastdot + 1);
            }
            TypeBuilder typeBuilder = __DefineNestedType(ns, name);

            typeBuilder.__SetAttributes(attr);
            typeBuilder.SetParent(parent);
            if (packSize != PackingSize.Unspecified || typeSize != 0)
            {
                typeBuilder.__SetLayout((int)packSize, typeSize);
            }
            return(typeBuilder);
        }
示例#19
0
        private TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
        {
            string ns      = null;
            int    lastdot = name.LastIndexOf('.');

            if (lastdot > 0)
            {
                ns   = name.Substring(0, lastdot);
                name = name.Substring(lastdot + 1);
            }
            TypeBuilder typeBuilder = __DefineNestedType(ns, name);

            typeBuilder.__SetAttributes(attr);
            typeBuilder.SetParent(parent);
            this.ModuleBuilder.SetPackingSizeAndTypeSize(typeBuilder, PackingSize.Unspecified, typeSize);
            return(typeBuilder);
        }
示例#20
0
 public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize)
 {
     this.typeFlags |= TypeFlags.HasNestedTypes;
     return(this.ModuleBuilder.DefineNestedTypeHelper(this, name, attr, parent, packSize, 0));
 }
示例#21
0
        // Constructor.
        internal TypeBuilder(ModuleBuilder module, String name, String nspace,
                             TypeAttributes attr, Type parent, Type[] interfaces,
                             PackingSize packingSize, int typeSize,
                             TypeBuilder declaringType)
        {
            // Validate the parameters.
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            else if (name == String.Empty)
            {
                throw new ArgumentException(_("Emit_NameEmpty"));
            }
            if (nspace == null)
            {
                nspace = String.Empty;
            }

            // Initialize the internal state.
            this.module                  = module;
            this.name                    = name;
            this.nspace                  = nspace;
            this.attr                    = attr;
            this.parent                  = parent;
            this.interfaces              = null;
            this.declaringType           = declaringType;
            this.type                    = null;
            this.underlyingSystemType    = null;
            this.methods                 = new ArrayList();
            this.needsDefaultConstructor = true;

            // We need the AssemblyBuilder lock for the next part.
            lock (typeof(AssemblyBuilder))
            {
                // Determine the scope to use to declare the type.
                IntPtr scope;
                if (declaringType == null)
                {
                    scope = IntPtr.Zero;
                }
                else
                {
                    scope = ((IClrProgramItem)declaringType).ClrHandle;
                }

                // Create the type.
                privateData = ClrTypeCreate
                                  (((IClrProgramItem)module).ClrHandle, scope, name,
                                  (nspace == String.Empty ? null : nspace), attr,
                                  (parent == null
                                                        ? new System.Reflection.Emit.TypeToken(0)
                                                        : module.GetTypeToken(parent)));
                if (privateData == IntPtr.Zero)
                {
                    throw new ArgumentException
                              (_("Emit_TypeAlreadyExists"));
                }
                module.assembly.AddDetach(this);
                if (packingSize != PackingSize.Unspecified)
                {
                    ClrTypeSetPackingSize(privateData, (int)packingSize);
                }
                if (typeSize != UnspecifiedTypeSize)
                {
                    ClrTypeSetClassSize(privateData, typeSize);
                }
            }

            // Add the interfaces to the type.
            if (interfaces != null)
            {
                foreach (Type iface in interfaces)
                {
                    AddInterfaceImplementation(iface);
                }
            }
        }
示例#22
0
        [System.Security.SecurityCritical]  // auto-generated
        private TypeBuilder DefineTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, int typesize)
        {
            Contract.Ensures(Contract.Result<TypeBuilder>() != null);

            return new TypeBuilder(name, attr, parent, interfaces, this, packingSize, typesize, null); ;
        }
示例#23
0
        private void Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, ModuleBuilder module,
            PackingSize iPackingSize, int iTypeSize, TypeBuilder enclosingType)
        {
            if (fullname == null)
                throw new ArgumentNullException(nameof(fullname));

            if (fullname.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(fullname));

            if (fullname[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(fullname));


            if (fullname.Length > 1023)
                throw new ArgumentException(Environment.GetResourceString("Argument_TypeNameTooLong"), nameof(fullname));
            Contract.EndContractBlock();

            int i;
            m_module = module;
            m_DeclaringType = enclosingType;
            AssemblyBuilder containingAssem = m_module.ContainingAssemblyBuilder;

            // cannot have two types within the same assembly of the same name
            containingAssem.m_assemblyData.CheckTypeNameConflict(fullname, enclosingType);

            if (enclosingType != null)
            {
                // Nested Type should have nested attribute set.
                // If we are renumbering TypeAttributes' bit, we need to change the logic here.
                if (((attr & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||((attr & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic))
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadNestedTypeFlags"), nameof(attr));
            }

            int[] interfaceTokens = null;
            if (interfaces != null)
            {
                for(i = 0; i < interfaces.Length; i++)
                {
                    if (interfaces[i] == null)
                    {
                        // cannot contain null in the interface list
                        throw new ArgumentNullException(nameof(interfaces));
                    }
                }
                interfaceTokens = new int[interfaces.Length + 1];
                for(i = 0; i < interfaces.Length; i++)
                {
                    interfaceTokens[i] = m_module.GetTypeTokenInternal(interfaces[i]).Token;
                }
            }

            int iLast = fullname.LastIndexOf('.');
            if (iLast == -1 || iLast == 0)
            {
                // no name space
                m_strNameSpace = String.Empty;
                m_strName = fullname;
            }
            else
            {
                // split the name space
                m_strNameSpace = fullname.Substring(0, iLast);
                m_strName = fullname.Substring(iLast + 1);
            }

            VerifyTypeAttributes(attr);

            m_iAttr = attr;

            SetParent(parent);

            m_listMethods = new List<MethodBuilder>();
            m_lastTokenizedMethod = -1;

            SetInterfaces(interfaces);

            int tkParent = 0;
            if (m_typeParent != null)
                tkParent = m_module.GetTypeTokenInternal(m_typeParent).Token;

            int tkEnclosingType = 0;
            if (enclosingType != null)
            {
                tkEnclosingType = enclosingType.m_tdType.Token;
            }

            m_tdType = new TypeToken(DefineType(m_module.GetNativeHandle(),
                fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens));

            m_iPackingSize = iPackingSize;
            m_iTypeSize = iTypeSize;
            if ((m_iPackingSize != 0) ||(m_iTypeSize != 0))
                SetClassLayout(GetModuleBuilder().GetNativeHandle(), m_tdType.Token, m_iPackingSize, m_iTypeSize);

            m_module.AddType(FullName, this);
        }
示例#24
0
 [System.Security.SecuritySafeCritical]  // auto-generated 
 public TypeBuilder DefineType(String name, TypeAttributes attr, Type parent, PackingSize packsize)
 {
     lock(SyncRoot)
     { 
         return DefineTypeNoLock(name, attr, parent, packsize);
     } 
 } 
示例#25
0
 [System.Security.SecurityCritical]  // auto-generated 
 private TypeBuilder DefineTypeNoLock(String name, TypeAttributes attr, Type parent, PackingSize packsize)
 {
     TypeBuilder typeBuilder;
     typeBuilder = new TypeBuilder(name, attr, parent, null, this, packsize, null); 
     AddType(typeBuilder);
     return typeBuilder; 
 } 
        public TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packSize) {

          return default(TypeBuilder);
        }
示例#27
0
        public TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packSize)
        {
            Contract.Ensures(0 <= name.Length);
            Contract.Ensures(Contract.Result <System.Reflection.Emit.TypeBuilder>() != null);
            Contract.Ensures(name.Length <= 1023);

            return(default(TypeBuilder));
        }
示例#28
0
 public TypeBuilder DefineNestedType(string name, TypeAttributes attr,
                                     [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type?parent, PackingSize packSize)
 => DefineNestedType(name, attr, parent, packSize, TypeBuilder.UnspecifiedTypeSize);
示例#29
0
 [System.Security.SecurityCritical]  // auto-generated
 internal TypeBuilder(
     String name,
     TypeAttributes attr,
     Type parent,
     Type[] interfaces,
     ModuleBuilder module,
     PackingSize iPackingSize,
     int iTypeSize, 
     TypeBuilder enclosingType)
 {
     Init(name, attr, parent, interfaces, module, iPackingSize, iTypeSize, enclosingType);
 }
示例#30
0
        internal TypeBuilder DefineNestedTypeHelper(TypeBuilder enclosingType, string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
        {
            if (parent == null && (attr & TypeAttributes.Interface) == 0)
            {
                parent = universe.System_Object;
            }
            TypeBuilder typeBuilder = new TypeBuilder(enclosingType, name, parent, attr);

            PostDefineType(typeBuilder, packingSize, typesize);
            if (enclosingType != null)
            {
                NestedClassTable.Record rec = new NestedClassTable.Record();
                rec.NestedClass    = typeBuilder.MetadataToken;
                rec.EnclosingClass = enclosingType.MetadataToken;
                this.NestedClass.AddRecord(rec);
            }
            return(typeBuilder);
        }
示例#31
0
		public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize)
		{
			return DefineNestedType(name, attr, parent, packSize, 0);
		}
示例#32
0
 public TypeBuilder DefineType(string name, TypeAttributes attr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type?parent, PackingSize packingSize, int typesize)
 {
     return(DefineType(name, attr, parent, null, packingSize, typesize));
 }
示例#33
0
        [System.Security.SecurityCritical]  // auto-generated
        private TypeBuilder DefineTypeNoLock(String name, TypeAttributes attr, Type parent, PackingSize packsize)
        {
            Contract.Ensures(Contract.Result<TypeBuilder>() != null);

            return new TypeBuilder(name, attr, parent, null, this, packsize, TypeBuilder.UnspecifiedTypeSize, null);
        }
示例#34
0
		private TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
		{
			string ns = null;
			int lastdot = name.LastIndexOf('.');
			if (lastdot > 0)
			{
				ns = name.Substring(0, lastdot);
				name = name.Substring(lastdot + 1);
			}
			TypeBuilder typeBuilder = __DefineNestedType(ns, name);
			typeBuilder.__SetAttributes(attr);
			if (parent == null && (attr & TypeAttributes.Interface) == 0)
			{
				parent = this.ModuleBuilder.universe.System_Object;
			}
			typeBuilder.SetParent(parent);
			this.ModuleBuilder.SetPackingSizeAndTypeSize(typeBuilder, PackingSize.Unspecified, typeSize);
			return typeBuilder;
		}
示例#35
0
        public void DefineNestedType(string name, TypeAttributes attributes, Type parent, PackingSize packingSize, int typesize, Type[] implementedInterfaces)
        {
            bool isDefaultImplementedInterfaces = implementedInterfaces?.Length == 0;
            bool isDefaultPackingSize           = packingSize == PackingSize.Unspecified;
            bool isDefaultSize       = typesize == 0;
            bool isDefaultParent     = parent == null;
            bool isDefaultAttributes = attributes == TypeAttributes.NestedPrivate;

            void Verify(TypeBuilder type, TypeBuilder declaringType)
            {
                bool allowsNullParent = attributes.HasFlag(TypeAttributes.Abstract) && attributes.HasFlag(TypeAttributes.ClassSemanticsMask);
                Type baseType         = allowsNullParent ? parent : (parent ?? typeof(object));

                Helpers.VerifyType(type, declaringType.Module, declaringType, name, attributes, baseType, typesize, packingSize, implementedInterfaces);
            }

            if (isDefaultImplementedInterfaces)
            {
                if (isDefaultSize && isDefaultPackingSize)
                {
                    if (isDefaultParent)
                    {
                        if (isDefaultAttributes)
                        {
                            // Use DefineNestedType(string)
                            TypeBuilder type1 = Helpers.DynamicType(TypeAttributes.Public);
                            Verify(type1.DefineNestedType(name), type1);
                        }
                        // Use DefineNestedType(string, TypeAttributes)
                        TypeBuilder type2 = Helpers.DynamicType(TypeAttributes.Public);
                        Verify(type2.DefineNestedType(name, attributes), type2);
                    }
                    // Use DefineNestedType(string, TypeAttributes, Type)
                    TypeBuilder type3 = Helpers.DynamicType(TypeAttributes.Public);
                    Verify(type3.DefineNestedType(name, attributes, parent), type3);
                }
                else if (isDefaultSize)
                {
                    // Use DefineNestedType(string, TypeAttributes, Type, PackingSize)
                    TypeBuilder type4 = Helpers.DynamicType(TypeAttributes.Public);
                    Verify(type4.DefineNestedType(name, attributes, parent, packingSize), type4);
                }
                else if (isDefaultPackingSize)
                {
                    // Use DefineNestedType(string, TypeAttributes, Type, int)
                    TypeBuilder type5 = Helpers.DynamicType(TypeAttributes.Public);
                    Verify(type5.DefineNestedType(name, attributes, parent, typesize), type5);
                }
                // Use DefineNestedType(string, TypeAttributes, Type, PackingSize, int);
                TypeBuilder type6 = Helpers.DynamicType(TypeAttributes.Public);
                Verify(type6.DefineNestedType(name, attributes, parent, packingSize, typesize), type6);
            }
            else
            {
                // Use DefineNestedType(string, TypeAttributes, Type, Type[])
                Assert.True(isDefaultSize && isDefaultPackingSize); // Sanity check
                TypeBuilder type7 = Helpers.DynamicType(TypeAttributes.Public);
                Verify(type7.DefineNestedType(name, attributes, parent, implementedInterfaces), type7);
            }
        }
示例#36
0
		private TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces,
						      PackingSize packSize, int typeSize)
		{
			// Visibility must be NestedXXX
			/* This breaks mcs
			if (((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||
				((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic))
				throw new ArgumentException ("attr", "Bad type flags for nested type.");
			*/
			if (interfaces != null)
				foreach (Type iface in interfaces)
					if (iface == null)
						throw new ArgumentNullException ("interfaces");

			TypeBuilder res = new TypeBuilder (pmodule, name, attr, parent, interfaces, packSize, typeSize, this);
			res.fullname = res.GetFullName ();
			pmodule.RegisterTypeName (res, res.fullname);
			if (subtypes != null) {
				TypeBuilder[] new_types = new TypeBuilder [subtypes.Length + 1];
				System.Array.Copy (subtypes, new_types, subtypes.Length);
				new_types [subtypes.Length] = res;
				subtypes = new_types;
			} else {
				subtypes = new TypeBuilder [1];
				subtypes [0] = res;
			}
			return res;
		}
示例#37
0
        private TypeBuilder DefineType(string name, TypeAttributes attr, Type?parent, Type[]?interfaces, PackingSize packingSize, int typesize)
        {
            if (name == null)
            {
                throw new ArgumentNullException("fullname");
            }
            ITypeIdentifier ident = TypeIdentifiers.FromInternal(name);

            if (name_cache.ContainsKey(ident))
            {
                throw new ArgumentException("Duplicate type name within an assembly.");
            }
            TypeBuilder res = new TypeBuilder(this, name, attr, parent, interfaces, packingSize, typesize, null);

            AddType(res);

            name_cache.Add(ident, res);

            return(res);
        }
示例#38
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(ColorWay))
            {
                yield return(new ValidationResult("Warna harus diisi", new List <string> {
                    "ColorWay"
                }));
            }

            if (string.IsNullOrEmpty(ConstructionType))
            {
                yield return(new ValidationResult("Konstruksi harus diisi", new List <string> {
                    "ConstructionType"
                }));
            }

            if (string.IsNullOrEmpty(Grade))
            {
                yield return(new ValidationResult("Grade harus diisi", new List <string> {
                    "Grade"
                }));
            }

            if (PackingSize.GetValueOrDefault() > 0)
            {
                yield return(new ValidationResult("Quantity harus diisi", new List <string> {
                    "PackingSize"
                }));
            }

            if (string.IsNullOrEmpty(PackingType))
            {
                yield return(new ValidationResult("Jenis Packing harus diisi", new List <string> {
                    "Jenis Packing"
                }));
            }

            if (string.IsNullOrEmpty(ProcessType))
            {
                yield return(new ValidationResult("Jenis Proses harus diisi", new List <string> {
                    "ProcessType"
                }));
            }

            if (string.IsNullOrEmpty(UOM))
            {
                yield return(new ValidationResult("Satuan harus diisi", new List <string> {
                    "Satuan"
                }));
            }

            if (string.IsNullOrEmpty(WarpThread))
            {
                yield return(new ValidationResult("Benang Lusi harus diisi", new List <string> {
                    "WarpThread"
                }));
            }

            if (string.IsNullOrEmpty(WeftThread))
            {
                yield return(new ValidationResult("Benang Pakan harus diisi", new List <string> {
                    "WeftThread"
                }));
            }

            if (string.IsNullOrEmpty(Width))
            {
                yield return(new ValidationResult("Lebar harus diisi", new List <string> {
                    "Lebar"
                }));
            }

            if (string.IsNullOrEmpty(WovenType))
            {
                yield return(new ValidationResult("Jenis Anyaman harus diisi", new List <string> {
                    "WovenType"
                }));
            }
        }
    public TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packSize)
    {
      Contract.Ensures(0 <= name.Length);
      Contract.Ensures(Contract.Result<System.Reflection.Emit.TypeBuilder>() != null);
      Contract.Ensures(name.Length <= 1023);

      return default(TypeBuilder);
    }
示例#40
0
		internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size, Type nesting_type)
		{
			int sep_index;
			this.parent = ResolveUserType (parent);
			this.attrs = attr;
			this.class_size = type_size;
			this.packing_size = packing_size;
			this.nesting_type = nesting_type;

			check_name ("fullname", name);

			if (parent == null && (attr & TypeAttributes.Interface) != 0 && (attr & TypeAttributes.Abstract) == 0)
				throw new InvalidOperationException ("Interface must be declared abstract.");

			sep_index = name.LastIndexOf('.');
			if (sep_index != -1) {
				this.tname = name.Substring (sep_index + 1);
				this.nspace = name.Substring (0, sep_index);
			} else {
				this.tname = name;
				this.nspace = String.Empty;
			}
			if (interfaces != null) {
				this.interfaces = new Type[interfaces.Length];
				System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
			}
			pmodule = mb;

			if (((attr & TypeAttributes.Interface) == 0) && (parent == null))
				this.parent = typeof (object);

			// skip .<Module> ?
			table_idx = mb.get_next_table_index (this, 0x02, true);
			fullname = GetFullName ();
		}
示例#41
0
 public TypeBuilder DefineType(string name, TypeAttributes attr, Type?parent, PackingSize packsize)
 {
     return(DefineType(name, attr, parent, null, packsize, TypeBuilder.UnspecifiedTypeSize));
 }
 public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packsize)
 {
 }
示例#43
0
		public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
		{
			if (customBuilder == null)
				throw new ArgumentNullException ("customBuilder");

			string attrname = customBuilder.Ctor.ReflectedType.FullName;
			if (attrname == "System.Runtime.InteropServices.StructLayoutAttribute") {
				byte[] data = customBuilder.Data;
				int layout_kind; /* the (stupid) ctor takes a short or an int ... */
				layout_kind = (int)data [2];
				layout_kind |= ((int)data [3]) << 8;
				attrs &= ~TypeAttributes.LayoutMask;
				switch ((LayoutKind)layout_kind) {
				case LayoutKind.Auto:
					attrs |= TypeAttributes.AutoLayout;
					break;
				case LayoutKind.Explicit:
					attrs |= TypeAttributes.ExplicitLayout;
					break;
				case LayoutKind.Sequential:
					attrs |= TypeAttributes.SequentialLayout;
					break;
				default:
					// we should ignore it since it can be any value anyway...
					throw new Exception ("Error in customattr");
				}
				
				var ctor_type = customBuilder.Ctor is ConstructorBuilder ? ((ConstructorBuilder)customBuilder.Ctor).parameters[0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType;
				int pos = 6;
				if (ctor_type.FullName == "System.Int16")
					pos = 4;
				int nnamed = (int)data [pos++];
				nnamed |= ((int)data [pos++]) << 8;
				for (int i = 0; i < nnamed; ++i) {
					//byte named_type = data [pos++];
					pos ++;
					byte type = data [pos++];
					int len;
					string named_name;

					if (type == 0x55) {
						len = CustomAttributeBuilder.decode_len (data, pos, out pos);
						//string named_typename = 
						CustomAttributeBuilder.string_from_bytes (data, pos, len);
						pos += len;
						// FIXME: Check that 'named_type' and 'named_typename' match, etc.
						//        See related code/FIXME in mono/mono/metadata/reflection.c
					}

					len = CustomAttributeBuilder.decode_len (data, pos, out pos);
					named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
					pos += len;
					/* all the fields are integers in StructLayout */
					int value = (int)data [pos++];
					value |= ((int)data [pos++]) << 8;
					value |= ((int)data [pos++]) << 16;
					value |= ((int)data [pos++]) << 24;
					switch (named_name) {
					case "CharSet":
						switch ((CharSet)value) {
						case CharSet.None:
						case CharSet.Ansi:
							attrs &= ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass);
							break;
						case CharSet.Unicode:
							attrs &= ~TypeAttributes.AutoClass;
							attrs |= TypeAttributes.UnicodeClass;
							break;
						case CharSet.Auto:
							attrs &= ~TypeAttributes.UnicodeClass;
							attrs |= TypeAttributes.AutoClass;
							break;
						default:
							break; // error out...
						}
						break;
					case "Pack":
						packing_size = (PackingSize)value;
						break;
					case "Size":
						class_size = value;
						break;
					default:
						break; // error out...
					}
				}
				return;
			} else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
				attrs |= TypeAttributes.SpecialName;
				return;
			} else if (attrname == "System.SerializableAttribute") {
				attrs |= TypeAttributes.Serializable;
				return;
			} else if (attrname == "System.Runtime.InteropServices.ComImportAttribute") {
				attrs |= TypeAttributes.Import;
				return;
			} else if (attrname == "System.Security.SuppressUnmanagedCodeSecurityAttribute") {
				attrs |= TypeAttributes.HasSecurity;
			}

			if (cattrs != null) {
				CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
				cattrs.CopyTo (new_array, 0);
				new_array [cattrs.Length] = customBuilder;
				cattrs = new_array;
			} else {
				cattrs = new CustomAttributeBuilder [1];
				cattrs [0] = customBuilder;
			}
		}
示例#44
0
 public TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packSize)
 {
     return(default(TypeBuilder));
 }
示例#45
0
 public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
 {
     throw new PlatformNotSupportedException();
 }
示例#46
0
        // specifying packing size
        /// <include file='doc\ModuleBuilder.uex' path='docs/doc[@for="ModuleBuilder.DefineType6"]/*' />
        
        public TypeBuilder DefineType(
            String      name, 
            TypeAttributes attr, 
            Type        parent, 
            PackingSize packsize) 
        {
            CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit);
            try
            {
                Enter();

                BCLDebug.Log("DYNIL","## DYNIL LOGGING: ModuleBuilder.DefineType( " + name + " )");
                TypeBuilder typeBuilder;
                typeBuilder = new TypeBuilder(name, attr, parent, null, this, packsize, null);
                m_TypeBuilderList.Add(typeBuilder);
                return typeBuilder;
            }
            finally
            {
                Exit();
            }
        }
示例#47
0
 public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize)
 {
     return(DefineNestedType(name, attr, parent, packSize, 0));
 }
示例#48
0
		public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
		{
			throw new PlatformNotSupportedException ();
		}
示例#49
0
 public TypeBuilder DefineNestedType(String name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
 {
     lock (SyncRoot)
     {
         return DefineNestedTypeNoLock(name, attr, parent, null, packSize, typeSize);
     }
 }
示例#50
0
 public DynamicType DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
 {
     TypeBuilder typeBuilder = builder.DefineType(name, attr, parent, packingSize, typesize);
     DynamicType type = new DynamicType(typeBuilder, this);
     return type;
 }
示例#51
0
 internal static extern void SetClassLayout(RuntimeModule module, int tk, PackingSize iPackingSize, int iTypeSize);
示例#52
0
        private TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packsize, int typesize)
        {
            if (name_cache.Contains(name))
            {
                throw new ArgumentException("Duplicate type name within an assembly.");
            }

            TypeBuilder res = new TypeBuilder(this, name, attr, parent, interfaces, packsize, typesize, null);

            AddType(res);
            name_cache.Add(name, res);
            return(res);
        }
示例#53
0
        [System.Security.SecurityCritical]  // auto-generated
        private void Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, ModuleBuilder module,
            PackingSize iPackingSize, int iTypeSize, TypeBuilder enclosingType)
        {
            if (fullname == null)
                throw new ArgumentNullException("fullname");

            if (fullname.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fullname");

            if (fullname[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fullname");


            if (fullname.Length > 1023)
                throw new ArgumentException(Environment.GetResourceString("Argument_TypeNameTooLong"), "fullname");
            Contract.EndContractBlock();

            int i;
            m_module = module;
            m_DeclaringType = enclosingType;
            AssemblyBuilder containingAssem = m_module.ContainingAssemblyBuilder;

            // cannot have two types within the same assembly of the same name
            containingAssem.m_assemblyData.CheckTypeNameConflict(fullname, enclosingType);

            if (enclosingType != null)
            {
                // Nested Type should have nested attribute set.
                // If we are renumbering TypeAttributes' bit, we need to change the logic here.
                if (((attr & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||((attr & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic))
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadNestedTypeFlags"), "attr");
            }

            int[] interfaceTokens = null;
            if (interfaces != null)
            {
                for(i = 0; i < interfaces.Length; i++)
                {
                    if (interfaces[i] == null)
                    {
                        // cannot contain null in the interface list
                        throw new ArgumentNullException("interfaces");
                    }
                }
                interfaceTokens = new int[interfaces.Length + 1];
                for(i = 0; i < interfaces.Length; i++)
                {
                    interfaceTokens[i] = m_module.GetTypeTokenInternal(interfaces[i]).Token;
                }
            }

            int iLast = fullname.LastIndexOf('.');
            if (iLast == -1 || iLast == 0)
            {
                // no name space
                m_strNameSpace = String.Empty;
                m_strName = fullname;
            }
            else
            {
                // split the name space
                m_strNameSpace = fullname.Substring(0, iLast);
                m_strName = fullname.Substring(iLast + 1);
            }

            VerifyTypeAttributes(attr);

            m_iAttr = attr;

            SetParent(parent);

            m_listMethods = new List<MethodBuilder>();
            m_lastTokenizedMethod = -1;

            SetInterfaces(interfaces);

            int tkParent = 0;
            if (m_typeParent != null)
                tkParent = m_module.GetTypeTokenInternal(m_typeParent).Token;

            int tkEnclosingType = 0;
            if (enclosingType != null)
            {
                tkEnclosingType = enclosingType.m_tdType.Token;
            }

            m_tdType = new TypeToken(DefineType(m_module.GetNativeHandle(),
                fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens));

            m_iPackingSize = iPackingSize;
            m_iTypeSize = iTypeSize;
            if ((m_iPackingSize != 0) ||(m_iTypeSize != 0))
                SetClassLayout(GetModuleBuilder().GetNativeHandle(), m_tdType.Token, m_iPackingSize, m_iTypeSize);

#if !FEATURE_CORECLR
            // If the type is public and it is contained in a assemblyBuilder,
            // update the public COMType list.
            if (IsPublicComType(this))
            {
                if (containingAssem.IsPersistable() && m_module.IsTransient() == false)
                {
                    // This will throw InvalidOperationException if the assembly has been saved
                    // Ideally we should reject all emit operations if the assembly has been saved,
                    // but that would be a breaking change for some. Currently you cannot define 
                    // modules and public types, but you can still define private types and global methods.
                    containingAssem.m_assemblyData.AddPublicComType(this);
                }

                // Now add the type to the ExportedType table
                if (!m_module.Equals(containingAssem.ManifestModule))
                    containingAssem.DefineExportedTypeInMemory(this, m_module.m_moduleData.FileToken, m_tdType.Token);
            }
#endif
            m_module.AddType(FullName, this);
        }
示例#54
0
		private TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, int typesize) {
			if (name == null)
				throw new ArgumentNullException ("fullname");
			if (name_cache.ContainsKey (name))
				throw new ArgumentException ("Duplicate type name within an assembly.");
			TypeBuilder res = new TypeBuilder (this, name, attr, parent, interfaces, packingSize, typesize, null);
			AddType (res);

			name_cache.Add (name, res);
			
			return res;
		}
示例#55
0
		private TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
		{
			string ns = null;
			int lastdot = name.LastIndexOf('.');
			if (lastdot > 0)
			{
				ns = name.Substring(0, lastdot);
				name = name.Substring(lastdot + 1);
			}
			TypeBuilder typeBuilder = __DefineNestedType(ns, name);
			typeBuilder.__SetAttributes(attr);
			typeBuilder.SetParent(parent);
			if (packSize != PackingSize.Unspecified || typeSize != 0)
			{
				typeBuilder.__SetLayout((int)packSize, typeSize);
			}
			return typeBuilder;
		}
示例#56
0
		public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, PackingSize packsize) {
			return DefineType (name, attr, parent, null, packsize, TypeBuilder.UnspecifiedTypeSize);
		}
示例#57
0
        public TypeBuilder DefineType(String name, TypeAttributes attr, Type parent, PackingSize packsize)
        {
            Contract.Ensures(Contract.Result<TypeBuilder>() != null);

            lock(SyncRoot)
            {
                return DefineTypeNoLock(name, attr, parent, packsize);
            }
        }
示例#58
0
		public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize) {
			return DefineType (name, attr, parent, null, packingSize, typesize);
		}
	public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packsize) {}
示例#60
0
        public static void VerifyType(TypeBuilder type, Module module, TypeBuilder declaringType, string name, TypeAttributes attributes, Type baseType, int size, PackingSize packingSize, Type[] implementedInterfaces)
        {
            Assert.Equal(module, type.Module);
            Assert.Equal(module.Assembly, type.Assembly);

            Assert.Equal(name, type.Name);
            if (declaringType == null)
            {
                Assert.Equal(GetFullName(name), type.FullName);
            }
            else
            {
                Assert.Equal(GetFullName(declaringType.Name) + "+" + GetFullName(type.Name), type.FullName);
            }

            Assert.Equal(attributes, type.Attributes);

            Assert.Equal(declaringType?.AsType(), type.DeclaringType);
            Assert.Equal(baseType, type.BaseType);

            Assert.Equal(size, type.Size);
            Assert.Equal(packingSize, type.PackingSize);

            Assert.Equal(implementedInterfaces ?? new Type[0], type.GetInterfaces());

            if (declaringType == null && !type.IsInterface && (implementedInterfaces == null || implementedInterfaces.Length == 0))
            {
                Type createdType = type.CreateTypeInfo().AsType();
                Assert.Equal(createdType, module.GetType(name, false, false));
                Assert.Equal(createdType, module.GetType(name, true, false));

                Assert.Equal(type.AsType().GetNestedTypes(AllFlags), createdType.GetNestedTypes(AllFlags));
                Assert.Equal(type.AsType().GetNestedType(name, AllFlags), createdType.GetNestedType(name, AllFlags));

                // [ActiveIssue("https://github.com/dotnet/runtime/issues/18231", TestPlatforms.AnyUnix)]
                // Assert.Equal(createdType, module.GetType(name, true, true));
                // Assert.Equal(createdType, module.GetType(name.ToLowerInvariant(), true, true));
                // Assert.Equal(createdType, module.GetType(name.ToUpperInvariant(), true, true));
            }
        }