当前位置: 首页>>代码示例>>C#>>正文


C# PackingSize类代码示例

本文整理汇总了C#中PackingSize的典型用法代码示例。如果您正苦于以下问题:C# PackingSize类的具体用法?C# PackingSize怎么用?C# PackingSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PackingSize类属于命名空间,在下文中一共展示了PackingSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DefineNestedType

        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);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:59,代码来源:TypeBuilderDefineNestedType.cs

示例2: DefineType

        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);
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:58,代码来源:ModuleBuilderDefineType.cs

示例3: PackagingSize_Set_ReturnsExpected

        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);
        }
开发者ID:Corillian,项目名称:corefx,代码行数:9,代码来源:TypeBuilderPackingSize.cs

示例4: VerifyType

        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));
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:37,代码来源:Utilities.cs

示例5: DefineType

        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);
            }
        }
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:9,代码来源:ModuleBuilder.cs

示例6: Init

        [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))
            {
//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:typebuilder.cs

示例7: SetClassLayout

 internal static extern void SetClassLayout(RuntimeModule module, int tk, PackingSize iPackingSize, int iTypeSize);
开发者ID:uQr,项目名称:referencesource,代码行数:1,代码来源:typebuilder.cs

示例8: DefineNestedType

 public TypeBuilder DefineNestedType(String name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
 {
     lock (SyncRoot)
     {
         return DefineNestedTypeNoLock(name, attr, parent, null, packSize, typeSize);
     }
 }
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:typebuilder.cs

示例9: SetCustomAttribute

		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;
			}

//.........这里部分代码省略.........
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:101,代码来源:TypeBuilder.cs

示例10: DefineTypeNoLock

 [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; 
 } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:8,代码来源:ModuleBuilder.cs

示例11: DefineType

 [System.Security.SecuritySafeCritical]  // auto-generated 
 public TypeBuilder DefineType(String name, TypeAttributes attr, Type parent, PackingSize packsize)
 {
     lock(SyncRoot)
     { 
         return DefineTypeNoLock(name, attr, parent, packsize);
     } 
 } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:8,代码来源:ModuleBuilder.cs

示例12: DefineNestedType

        public TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packSize) {

          return default(TypeBuilder);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:4,代码来源:System.Reflection.Emit.TypeBuilder.cs

示例13: DefineNestedType

		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;
		}
开发者ID:luobailiang,项目名称:mono,代码行数:19,代码来源:TypeBuilder.cs

示例14: Init

        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);
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:96,代码来源:TypeBuilder.cs

示例15: TypeBuilder

		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 ();
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:35,代码来源:TypeBuilder.cs


注:本文中的PackingSize类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。