Beispiel #1
0
        public TypeReference GetTypeRefFromSig(SigType t, GenericContext context)
        {
            switch (t.ElementType) {
            case ElementType.Class :
                CLASS c = t as CLASS;
                return GetTypeDefOrRef (c.Type, context);
            case ElementType.ValueType :
                VALUETYPE vt = t as VALUETYPE;
                TypeReference vtr = GetTypeDefOrRef (vt.Type, context);
                vtr.IsValueType = true;
                return vtr;
            case ElementType.String :
                return SearchCoreType (Constants.String);
            case ElementType.Object :
                return SearchCoreType (Constants.Object);
            case ElementType.Void :
                return SearchCoreType (Constants.Void);
            case ElementType.Boolean :
                return SearchCoreType (Constants.Boolean);
            case ElementType.Char :
                return SearchCoreType (Constants.Char);
            case ElementType.I1 :
                return SearchCoreType (Constants.SByte);
            case ElementType.U1 :
                return SearchCoreType (Constants.Byte);
            case ElementType.I2 :
                return SearchCoreType (Constants.Int16);
            case ElementType.U2 :
                return SearchCoreType (Constants.UInt16);
            case ElementType.I4 :
                return SearchCoreType (Constants.Int32);
            case ElementType.U4 :
                return SearchCoreType (Constants.UInt32);
            case ElementType.I8 :
                return SearchCoreType (Constants.Int64);
            case ElementType.U8 :
                return SearchCoreType (Constants.UInt64);
            case ElementType.R4 :
                return SearchCoreType (Constants.Single);
            case ElementType.R8 :
                return SearchCoreType (Constants.Double);
            case ElementType.I :
                return SearchCoreType (Constants.IntPtr);
            case ElementType.U :
                return SearchCoreType (Constants.UIntPtr);
            case ElementType.TypedByRef :
                return SearchCoreType (Constants.TypedReference);
            case ElementType.Array :
                ARRAY ary = t as ARRAY;
                return new ArrayType (GetTypeRefFromSig (ary.Type, context), ary.Shape);
            case ElementType.SzArray :
                SZARRAY szary = t as SZARRAY;
                ArrayType at = new ArrayType (GetTypeRefFromSig (szary.Type, context));
                return at;
            case ElementType.Ptr :
                PTR pointer = t as PTR;
                if (pointer.Void)
                    return new PointerType (SearchCoreType (Constants.Void));
                return new PointerType (GetTypeRefFromSig (pointer.PtrType, context));
            case ElementType.FnPtr :
                FNPTR funcptr = t as FNPTR;
                FunctionPointerType fnptr = new FunctionPointerType (funcptr.Method.HasThis, funcptr.Method.ExplicitThis,
                    funcptr.Method.MethCallConv, GetMethodReturnType (funcptr.Method, context));

                for (int i = 0; i < funcptr.Method.ParamCount; i++) {
                    Param p = funcptr.Method.Parameters [i];
                    fnptr.Parameters.Add (BuildParameterDefinition (i, p, context));
                }

                CreateSentinelIfNeeded (fnptr, funcptr.Method);

                return fnptr;
            case ElementType.Var:
                VAR var = t as VAR;
                context.CheckProvider (context.Type, var.Index + 1);

                if (context.Type is GenericInstanceType)
                    return (context.Type as GenericInstanceType).GenericArguments [var.Index];
                else
                    return context.Type.GenericParameters [var.Index];
            case ElementType.MVar:
                MVAR mvar = t as MVAR;
                context.CheckProvider (context.Method, mvar.Index + 1);

                if (context.Method is GenericInstanceMethod)
                    return (context.Method as GenericInstanceMethod).GenericArguments [mvar.Index];
                else
                    return context.Method.GenericParameters [mvar.Index];
            case ElementType.GenericInst:
                GENERICINST ginst = t as GENERICINST;
                GenericInstanceType instance = new GenericInstanceType (GetTypeDefOrRef (ginst.Type, context));
                instance.IsValueType = ginst.ValueType;
                context.CheckProvider (instance.GetOriginalType (), ginst.Signature.Arity);

                for (int i = 0; i < ginst.Signature.Arity; i++)
                    instance.GenericArguments.Add (GetGenericArg (
                        ginst.Signature.Types [i], context));

                return instance;
            default:
                break;
            }
            return null;
        }
Beispiel #2
0
        public GenericInstanceMethod GetMethodSpecAt(uint rid, GenericContext context)
        {
            int index = (int) rid - 1;
            GenericInstanceMethod gim = m_methodSpecs [index];
            if (gim != null)
                return gim;

            MethodSpecTable msTable = m_tableReader.GetMethodSpecTable ();
            MethodSpecRow msRow = msTable [index];

            MethodSpec sig = m_sigReader.GetMethodSpec (msRow.Instantiation);

            MethodReference meth;
            if (msRow.Method.TokenType == TokenType.Method)
                meth = GetMethodDefAt (msRow.Method.RID);
            else if (msRow.Method.TokenType == TokenType.MemberRef)
                meth = (MethodReference) GetMemberRefAt (msRow.Method.RID, context);
            else
                throw new ReflectionException ("Unknown method type for method spec");

            gim = new GenericInstanceMethod (meth);
            context.CheckProvider (meth, sig.Signature.Arity);
            foreach (GenericArg arg in sig.Signature.Types)
                gim.GenericArguments.Add (GetGenericArg (arg, context));

            m_methodSpecs [index] = gim;

            return gim;
        }