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


C# ModuleBuilder.GetTypeToken方法代码示例

本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder.GetTypeToken方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.GetTypeToken方法的具体用法?C# ModuleBuilder.GetTypeToken怎么用?C# ModuleBuilder.GetTypeToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.ModuleBuilder的用法示例。


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

示例1: Init

        private void Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module,
            PackingSize iPackingSize, int iTypeSize, TypeBuilder enclosingType)
        {
            int i;
            int[] interfaceTokens;
            m_bIsGenTypeDef = false;
            interfaceTokens = null;
            m_bIsGenParam = false;
            m_hasBeenCreated = false;
            m_runtimeType = null;
            m_isHiddenGlobalType = false;
            m_isHiddenType = false;
            m_module =(ModuleBuilder) module;
            m_DeclaringType = enclosingType;
            Assembly containingAssem = m_module.Assembly;
            m_underlyingSystemType = null;          // used when client use TypeBuilder to define Enum

            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");

            // 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");
            }

            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];
                for(i = 0; i < interfaces.Length; i++)
                {
                    interfaceTokens[i] = m_module.GetTypeToken(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 ArrayList();

            SetInterfaces(interfaces);

            m_constructorCount=0;

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

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

            m_tdType = new TypeToken(InternalDefineClass(
                fullname, tkParent, interfaceTokens, m_iAttr, m_module, Guid.Empty, tkEnclosingType, 0));

            m_iPackingSize = iPackingSize;
            m_iTypeSize = iTypeSize;
            if ((m_iPackingSize != 0) ||(m_iTypeSize != 0))
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:typebuilder.cs

示例2: ToSigBytes

        //***********************************************
        //
        // Translate the type into signature format
        // 
        //***********************************************
        internal void ToSigBytes(ModuleBuilder moduleBuilder, SignatureBuffer sigBuf)
        {

            bool        isArray = false;

            // now process whatever information that we have here.
            if (m_typeKind == TypeKind.IsArray)
            {
                if (m_cRank == 1 && m_iaLowerBound[0] == 0 && m_iaUpperBound[0] == -1)
                {
                    // zero lower bound, unspecified count. So simplify to SZARRAY
                    sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_SZARRAY);
                }
                else
                {
                    // ELEMENT_TYPE_ARRAY :  ARRAY <type> <rank> <bcount> <bound1> ... <lbcount> <lb1> ...  
                    sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_ARRAY);
                    isArray = true;
                }
            }
            else if (m_typeKind == TypeKind.IsPointer)
            {
                sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_PTR);
            }
            else if (m_typeKind == TypeKind.IsByRef)
            {
                sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_BYREF);
            }

            if (m_baseType is SymbolType)
            {
                // the base type is still a SymbolType. So recursively form the signature blob
                ((SymbolType) m_baseType).ToSigBytes(moduleBuilder, sigBuf);
            }
            else
            {
                // we have walked to the most nested class.
				
				int     cvType;
                if (m_baseType is RuntimeType)
                    cvType = SignatureHelper.GetCorElementTypeFromClass((RuntimeType)m_baseType);
				else
					cvType = SignatureHelper.ELEMENT_TYPE_MAX;
					
                if (SignatureHelper.IsSimpleType(cvType)) 
                {
                    sigBuf.AddElementType(cvType);
                } 
                else 
                {
                    if (m_baseType.IsValueType) 
                    {                 
                        sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_VALUETYPE);
                        sigBuf.AddToken(moduleBuilder.GetTypeToken(m_baseType).Token);
                    } 
                    else if (m_baseType == SignatureHelper.SystemObject)
						sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_OBJECT);
					else if (m_baseType == SignatureHelper.SystemString)
						sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_STRING);
					else
                    {
                        sigBuf.AddElementType(SignatureHelper.ELEMENT_TYPE_CLASS);
                        sigBuf.AddToken(moduleBuilder.GetTypeToken(m_baseType).Token);
                    }
                }
            }
            if (isArray)
            {
                // ELEMENT_TYPE_ARRAY :  ARRAY <type> <rank> <bcount> <bound1> ... <lbcount> <lb1> ...  
                // generic array!! Put in the dimension, sizes and lower bounds information.
                
                int     index;
                int     i;

                sigBuf.AddData(m_cRank);
                
                // determine the number of dimensions that we have to specify the size
                for (index = m_cRank - 1; index >= 0 && m_iaLowerBound[index] > m_iaUpperBound[index]; index--);
                sigBuf.AddData(index + 1);
                for (i=0; i <= index; i++)
                {
                    if (m_iaLowerBound[index] > m_iaUpperBound[index])
                    {
                        // bad signature!!
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                    }
                    else
                    {
                        sigBuf.AddData(m_iaUpperBound[i] - m_iaLowerBound[i] + 1);
                    }
                }


                // loop from last dimension back to first dimension. Look for the first one that does
                // not have lower bound equals to zero. If this is index, then 0..index has to specify the
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:symboltype.cs

示例3: TypeBuilder

	// 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);
					}
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:79,代码来源:TypeBuilder.cs


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