コード例 #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(
                                             string.Concat("A_", i),
                                             i, (ParamAttributes)0,
                                             p, context));
                }
                return(fnptr);

            case ElementType.Var:
                VAR var = t as VAR;
                if (context.AllowCreation)
                {
                    CheckGenericParameters(context, var);
                }

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

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

                return(instance);

            default:
                break;
            }
            return(null);
        }
コード例 #2
0
ファイル: Type.cs プロジェクト: sylviebatlis/ConfuserDumper
        public static TypeElement ReadType(SignatureReader rdr)
        {
            TypeElement ret;

            switch (rdr.GetElementTypeAhead())
            {
            case ElementType.Void:
            case ElementType.TypedByRef:
                ret = new BaseType(); break;

            case ElementType.Boolean:
            case ElementType.Char:
            case ElementType.Int8:
            case ElementType.UInt8:
            case ElementType.Int16:
            case ElementType.UInt16:
            case ElementType.Int32:
            case ElementType.UInt32:
            case ElementType.Int64:
            case ElementType.UInt64:
            case ElementType.Single:
            case ElementType.Double:
            case ElementType.IntPtr:
            case ElementType.UIntPtr:
            case ElementType.Object:
            case ElementType.String:
                ret = new BaseType(); break;

            case ElementType.Array:
                ret = new ARRAY(); break;

            case ElementType.Class:
                ret = new CLASS(); break;

            case ElementType.FnPtr:
                ret = new FNPTR(); break;

            case ElementType.GenericInstance:
                ret = new GENERICINST(); break;

            case ElementType.MethodGenericVar:
                ret = new MVAR(); break;

            case ElementType.Pointer:
                ret = new PTR(); break;

            case ElementType.SzArray:
                ret = new SZARRAY(); break;

            case ElementType.ValueType:
                ret = new VALUETYPE(); break;

            case ElementType.GenericVar:
                ret = new VAR(); break;

            default:
                throw new InvalidOperationException();
            }
            ret.Read(rdr);
            return(ret);
        }