Пример #1
0
        //***********************************************
        //
        // 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> ...
                    // @todo: fill the signature blob
                    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
                // lower bound.
                for (index = m_cRank - 1; index >= 0 && m_iaLowerBound[index] == 0; index--)
                {
                    ;
                }
                sigBuf.AddData(index + 1);
                for (i = 0; i <= index; i++)
                {
                    sigBuf.AddInteger(m_iaLowerBound[i]);
                }
            }
        }