コード例 #1
0
        void ReadMemberReferences()
        {
            if (!m_tHeap.HasTable(MemberRefTable.RId))
            {
                return;
            }

            MemberRefTable mrefTable = m_tableReader.GetMemberRefTable();

            m_memberRefs = new MemberReference [mrefTable.Rows.Count];
        }
コード例 #2
0
        public MemberReference GetMemberRefAt(uint rid, GenericContext context)
        {
            int             index  = (int)rid - 1;
            MemberReference member = m_memberRefs [rid - 1];

            if (member != null)
            {
                return(member);
            }

            MemberRefTable mrTable = m_tableReader.GetMemberRefTable();
            MemberRefRow   mrefRow = mrTable [index];

            Signature sig = m_sigReader.GetMemberRefSig(mrefRow.Class.TokenType, mrefRow.Signature);

            switch (mrefRow.Class.TokenType)
            {
            case TokenType.TypeDef:
            case TokenType.TypeRef:
            case TokenType.TypeSpec:
                TypeReference  declaringType = GetTypeDefOrRef(mrefRow.Class, context);
                GenericContext nc            = context.Clone();

                if (declaringType is GenericInstanceType)
                {
                    TypeReference ct = declaringType;
                    while (ct is GenericInstanceType)
                    {
                        ct = (ct as GenericInstanceType).ElementType;
                    }

                    nc.Type          = ct;
                    nc.AllowCreation = ct.GetType() == typeof(TypeReference);
                }

                if (sig is FieldSig)
                {
                    FieldSig fs = sig as FieldSig;
                    member = new FieldReference(
                        m_root.Streams.StringsHeap [mrefRow.Name],
                        declaringType,
                        GetTypeRefFromSig(fs.Type, nc));
                }
                else
                {
                    string    name = m_root.Streams.StringsHeap [mrefRow.Name];
                    MethodSig ms   = sig as MethodSig;

                    MethodReference methref = new MethodReference(
                        name, ms.HasThis, ms.ExplicitThis, ms.MethCallConv);
                    methref.DeclaringType = declaringType;

                    if (sig is MethodDefSig)
                    {
                        int arity = (sig as MethodDefSig).GenericParameterCount;
                        for (int i = 0; i < arity; i++)
                        {
                            methref.GenericParameters.Add(new GenericParameter(i, methref));
                        }
                    }

                    nc.Method = methref;

                    methref.ReturnType = GetMethodReturnType(ms, nc);

                    methref.ReturnType.Method = methref;
                    for (int j = 0; j < ms.ParamCount; j++)
                    {
                        Param p = ms.Parameters [j];
                        ParameterDefinition pdef = BuildParameterDefinition(
                            string.Concat("A_", j), j, new ParamAttributes(), p, nc);
                        pdef.Method = methref;
                        methref.Parameters.Add(pdef);
                    }
                    member    = methref;
                    nc.Method = methref;
                }
                break;

            case TokenType.Method:
                // really not sure about this
                MethodDefinition methdef = GetMethodDefAt(mrefRow.Class.RID);
                member = new MethodReference(
                    methdef.Name, methdef.HasThis,
                    methdef.ExplicitThis, methdef.CallingConvention);
                member.DeclaringType = methdef.DeclaringType;
                break;

            case TokenType.ModuleRef:
                break;                 // TODO, implement that, or not
            }

            member.MetadataToken = MetadataToken.FromMetadataRow(TokenType.MemberRef, index);
            m_module.MemberReferences.Add(member);
            m_memberRefs [index] = member;

            return(member);
        }