コード例 #1
0
        private void AddOneArgTypeHelper(Type clsArgument, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
        {
            // This function will not increase the argument count. It only fills in bytes
            // in the signature based on clsArgument. This helper is called for return type.

            ASSERT.PRECONDITION(clsArgument != null);
            ASSERT.PRECONDITION((optionalCustomModifiers == null && requiredCustomModifiers == null) || !clsArgument.ContainsGenericParameters);
            ASSERT.PRECONDITION(requiredCustomModifiers == null || Array.IndexOf(requiredCustomModifiers, null) == -1);
            ASSERT.PRECONDITION(optionalCustomModifiers == null || Array.IndexOf(optionalCustomModifiers, null) == -1);

            if (optionalCustomModifiers != null)
            {
                for (int i = 0; i < optionalCustomModifiers.Length; i++)
                {
                    AddElementType(ELEMENT_TYPE_CMOD_OPT);
                    ASSERT.CONSISTENCY_CHECK(!MetadataToken.IsNullToken(optionalCustomModifiers[i].MetadataTokenInternal));
                    AddToken(m_module.GetTypeToken(optionalCustomModifiers[i]).Token);
                }
            }

            if (requiredCustomModifiers != null)
            {
                for (int i = 0; i < requiredCustomModifiers.Length; i++)
                {
                    AddElementType(ELEMENT_TYPE_CMOD_REQD);
                    ASSERT.CONSISTENCY_CHECK(!MetadataToken.IsNullToken(requiredCustomModifiers[i].MetadataTokenInternal));
                    AddToken(m_module.GetTypeToken(requiredCustomModifiers[i]).Token);
                }
            }

            AddOneArgTypeHelper(clsArgument);
        }
コード例 #2
0
        internal static Attribute GetCustomAttribute(int token, Module scope)
        {
            UnmanagedType unmanagedType, arraySubType;
            VarEnum       safeArraySubType;
            int           sizeParamIndex = 0, sizeConst = 0;
            string        marshalTypeName = null, marshalCookie = null, safeArrayUserDefinedTypeName = null;
            int           iidParamIndex = 0;

            ConstArray nativeType = scope.ModuleHandle.GetMetadataImport().GetFieldMarshal(token);

            if (nativeType.Length == 0)
            {
                return(null);
            }

            MetadataImport.GetMarshalAs(nativeType,
                                        out unmanagedType, out safeArraySubType, out safeArrayUserDefinedTypeName, out arraySubType, out sizeParamIndex,
                                        out sizeConst, out marshalTypeName, out marshalCookie, out iidParamIndex);

            Type safeArrayUserDefinedType = safeArrayUserDefinedTypeName == null || safeArrayUserDefinedTypeName.Length == 0 ? null :
                                            RuntimeTypeHandle.GetTypeByNameUsingCARules(safeArrayUserDefinedTypeName, scope);
            Type marshalTypeRef = null;

            try
            {
                marshalTypeRef = marshalTypeName == null ? null : RuntimeTypeHandle.GetTypeByNameUsingCARules(marshalTypeName, scope);
            }
            catch (System.TypeLoadException)
            {
                // The user may have supplied a bad type name string causing this TypeLoadException
                // Regardless, we return the bad type name
                ASSERT.CONSISTENCY_CHECK(marshalTypeName != null);
            }

            return(new MarshalAsAttribute(
                       unmanagedType, safeArraySubType, safeArrayUserDefinedType, arraySubType,
                       (short)sizeParamIndex, sizeConst, marshalTypeName, marshalTypeRef, marshalCookie, iidParamIndex));
        }
コード例 #3
0
        public void AddArgument(Type argument, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
        {
            if (m_sigDone)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_SigIsFinalized"));
            }

            if (argument == null)
            {
                throw new ArgumentNullException("argument");
            }

            if (requiredCustomModifiers != null)
            {
                for (int i = 0; i < requiredCustomModifiers.Length; i++)
                {
                    Type t = requiredCustomModifiers[i];

                    if (t == null)
                    {
                        throw new ArgumentNullException("requiredCustomModifiers");
                    }

                    if (t.HasElementType)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), "requiredCustomModifiers");
                    }

                    if (t.ContainsGenericParameters)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "requiredCustomModifiers");
                    }

                    ASSERT.CONSISTENCY_CHECK(!MetadataToken.IsNullToken(t.MetadataTokenInternal));
                }
            }

            if (optionalCustomModifiers != null)
            {
                for (int i = 0; i < optionalCustomModifiers.Length; i++)
                {
                    Type t = optionalCustomModifiers[i];

                    if (t == null)
                    {
                        throw new ArgumentNullException("optionalCustomModifiers");
                    }

                    if (t.HasElementType)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), "optionalCustomModifiers");
                    }

                    if (t.ContainsGenericParameters)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "optionalCustomModifiers");
                    }

                    ASSERT.CONSISTENCY_CHECK(!MetadataToken.IsNullToken(t.MetadataTokenInternal));
                }
            }

            IncrementArgCounts();

            // Add an argument to the signature. Takes a Type and determines whether it
            // is one of the primitive types of which we have special knowledge or a more
            // general class.  In the former case, we only add the appropriate short cut encoding,
            // otherwise we will calculate proper description for the type.
            AddOneArgTypeHelper(argument, requiredCustomModifiers, optionalCustomModifiers);
        }