private static void ReadMethods(TypeDefinition type)
        {
            Collection <MethodDefinition> methods = type.Methods;

            for (int i = 0; i < methods.Count; i++)
            {
                MethodDefinition item = methods[i];
                ImmediateModuleReader.ReadGenericParameters(item);
                if (item.HasParameters)
                {
                    ImmediateModuleReader.ReadParameters(item);
                }
                if (item.HasOverrides)
                {
                    ImmediateModuleReader.Read(item.Overrides);
                }
                if (item.IsPInvokeImpl)
                {
                    ImmediateModuleReader.Read(item.PInvokeInfo);
                }
                ImmediateModuleReader.ReadSecurityDeclarations(item);
                ImmediateModuleReader.ReadCustomAttributes(item);
                MethodReturnType methodReturnType = item.MethodReturnType;
                if (methodReturnType.HasConstant)
                {
                    ImmediateModuleReader.Read(methodReturnType.Constant);
                }
                if (methodReturnType.HasMarshalInfo)
                {
                    ImmediateModuleReader.Read(methodReturnType.MarshalInfo);
                }
                ImmediateModuleReader.ReadCustomAttributes(methodReturnType);
            }
        }
Example #2
0
        private void ReadMethods(TypeDefinition type)
        {
            Collection <MethodDefinition> methods = type.Methods;

            for (int i = 0; i < methods.Count; i++)
            {
                MethodDefinition methodDefinition = methods[i];
                ReadGenericParameters(methodDefinition);
                if (methodDefinition.HasParameters)
                {
                    ReadParameters(methodDefinition);
                }
                if (methodDefinition.HasOverrides)
                {
                    Mixin.Read(methodDefinition.Overrides);
                }
                if (methodDefinition.IsPInvokeImpl)
                {
                    Mixin.Read(methodDefinition.PInvokeInfo);
                }
                ReadSecurityDeclarations(methodDefinition);
                ReadCustomAttributes(methodDefinition);
                MethodReturnType methodReturnType = methodDefinition.MethodReturnType;
                if (methodReturnType.HasConstant)
                {
                    Mixin.Read(methodReturnType.Constant);
                }
                if (methodReturnType.HasMarshalInfo)
                {
                    Mixin.Read(methodReturnType.MarshalInfo);
                }
                ReadCustomAttributes(methodReturnType);
            }
        }
Example #3
0
        internal MethodReference(string name)
            : base(name)
        {
            m_returnType = new MethodReturnType (null);

            AllReferences.Add(this);
        }
Example #4
0
 public MethodReference(string name, TypeReference returnType)
     : base(name)
 {
     Mixin.CheckType(returnType, Mixin.Argument.returnType);
     return_type            = new MethodReturnType(this);
     return_type.ReturnType = returnType;
     base.token             = new MetadataToken(TokenType.MemberRef);
 }
 public MethodReference(string name,
                        TypeReference declaringType, TypeReference returnType,
                        bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
     this(name, hasThis, explicitThis, callConv)
 {
     this.DeclaringType         = declaringType;
     this.ReturnType.ReturnType = returnType;
 }
Example #6
0
        /*Telerik Authorship*/
        /// <summary>
        /// Performs shallow clone of the MethodReturnType of <paramref name="method"/>
        /// </summary>
        private MethodReturnType DeepCloneMethodReturnType(MethodReference method)
        {
            MethodReturnType result = new MethodReturnType(this);             // not sure how will this behave

            result.parameter  = method.MethodReturnType.parameter;
            result.ReturnType = DeepCloneType(method.ReturnType);

            return(result);
        }
        public MethodReference(string name, TypeReference returnType)
            : base(name)
        {
            if (returnType == null)
                throw new ArgumentNullException ("returnType");

            this.return_type = new MethodReturnType (this);
            this.return_type.ReturnType = returnType;
            this.token = new MetadataToken (TokenType.MemberRef);
        }
Example #8
0
 public static void CopyReturnTypeTo(MethodReturnType dst, MethodReturnType src)
 {
     dst.Attributes = src.Attributes;
       dst.Constant = src.Constant;
       dst.CustomAttributes.Clear();
       foreach (var attr in src.CustomAttributes)
     dst.CustomAttributes.Add(attr);
       dst.HasConstant = src.HasConstant;
       dst.HasDefault = src.HasDefault;
       dst.HasFieldMarshal = src.HasFieldMarshal;
       dst.MarshalInfo = src.MarshalInfo;
       dst.ReturnType = src.ReturnType;
 }
        internal MethodReturnType ResolveGenericTypes(Collection <GenericParameter> parameters, Collection <TypeReference> arguments)
        {
            TypeReference    resolved = MemberReference.ResolveType(return_type, parameters, arguments);
            MethodReturnType result;

            if (resolved == return_type)
            {
                return(this);
            }

            result            = new MethodReturnType(method);
            result.ReturnType = resolved;
            if (parameter != null)
            {
                result.MetadataToken = MetadataToken;
                result.MarshalInfo   = MarshalInfo;
                result.Constant      = Constant;
                //TODO: result.m_param.CustomAttributes = CustomAttributes;
            }
            return(result);
        }
Example #10
0
		void ConvertAttributes(AttributedNode attributedNode, MethodReturnType methodReturnType, ModuleDefinition module)
		{
			ConvertCustomAttributes(attributedNode, methodReturnType, "return");
			if (methodReturnType.HasMarshalInfo) {
				var marshalInfo = ConvertMarshalInfo(methodReturnType, module);
				attributedNode.Attributes.Add(new AttributeSection(marshalInfo) { AttributeTarget = "return" });
			}
		}
        void CompleteMethods()
        {
            TypeDefTable tdefTable = m_tableReader.GetTypeDefTable();

            if (!m_tHeap.HasTable(MethodTable.RId))
            {
                m_meths = new MethodDefinition [0];
                return;
            }

            MethodTable methTable  = m_tableReader.GetMethodTable();
            ParamTable  paramTable = m_tableReader.GetParamTable();

            if (!m_tHeap.HasTable(ParamTable.RId))
            {
                m_parameters = new ParameterDefinition [0];
            }
            else
            {
                m_parameters = new ParameterDefinition [paramTable.Rows.Count];
            }

            for (int i = 0; i < m_typeDefs.Length; i++)
            {
                TypeDefinition dec = m_typeDefs [i];

                int index = i, next;

                if (index == tdefTable.Rows.Count - 1)
                {
                    next = methTable.Rows.Count + 1;
                }
                else
                {
                    next = (int)(tdefTable [index + 1]).MethodList;
                }

                for (int j = (int)tdefTable [index].MethodList; j < next; j++)
                {
                    MethodRow        methRow = methTable [j - 1];
                    MethodDefinition mdef    = m_meths [j - 1];
                    if (mdef.IsConstructor)
                    {
                        dec.Constructors.Add(mdef);
                    }
                    else
                    {
                        dec.Methods.Add(mdef);
                    }
                    GenericContext context = new GenericContext(mdef);

                    MethodDefSig msig = m_sigReader.GetMethodDefSig(methRow.Signature);
                    mdef.HasThis           = msig.HasThis;
                    mdef.ExplicitThis      = msig.ExplicitThis;
                    mdef.CallingConvention = msig.MethCallConv;

                    int prms;
                    if (j == methTable.Rows.Count)
                    {
                        prms = m_parameters.Length + 1;
                    }
                    else
                    {
                        prms = (int)(methTable [j]).ParamList;
                    }

                    ParameterDefinition retparam = null;

                    //TODO: optimize this
                    ParamRow pRow  = null;
                    int      start = (int)methRow.ParamList - 1;

                    if (paramTable != null && start < prms - 1)
                    {
                        pRow = paramTable [start];
                    }

                    if (pRow != null && pRow.Sequence == 0)                       // ret type
                    {
                        retparam = new ParameterDefinition(
                            m_root.Streams.StringsHeap [pRow.Name],
                            0,
                            pRow.Flags,
                            null);
                        retparam.Method      = mdef;
                        m_parameters [start] = retparam;
                        start++;
                    }

                    for (int k = 0; k < msig.ParamCount; k++)
                    {
                        int pointer = start + k;

                        if (paramTable != null && pointer < prms - 1)
                        {
                            pRow = paramTable [pointer];
                        }

                        Param psig = msig.Parameters [k];

                        ParameterDefinition pdef;
                        if (pRow != null)
                        {
                            pdef = BuildParameterDefinition(
                                m_root.Streams.StringsHeap [pRow.Name],
                                pRow.Sequence, pRow.Flags, psig, context);
                            pdef.MetadataToken     = MetadataToken.FromMetadataRow(TokenType.Param, pointer);
                            m_parameters [pointer] = pdef;
                        }
                        else
                        {
                            pdef = BuildParameterDefinition(
                                string.Concat("A_", mdef.IsStatic ? k : k + 1),
                                k + 1, (ParamAttributes)0, psig, context);
                        }

                        pdef.Method = mdef;
                        mdef.Parameters.Add(pdef);
                    }

                    mdef.ReturnType = GetMethodReturnType(msig, context);
                    MethodReturnType mrt = mdef.ReturnType as MethodReturnType;
                    mrt.Method = mdef;
                    if (retparam != null)
                    {
                        mrt.Parameter = retparam;
                        mrt.Parameter.ParameterType = mrt.ReturnType;
                    }
                }
            }

            uint eprid = CodeReader.GetRid((int)m_reader.Image.CLIHeader.EntryPointToken);

            if (eprid > 0 && eprid <= m_meths.Length)
            {
                m_module.Assembly.EntryPoint = GetMethodDefAt(eprid);
            }
        }
Example #12
0
		static bool IsIgnored (ICollection<IMetadataTokenProvider> list, MethodReturnType returnType)
		{
			return (list.Contains (returnType) || IsIgnored (list, returnType.Method));
		}
 internal MethodReference(string name) : base(name)
 {
     m_returnType = new MethodReturnType(null);
 }
Example #14
0
 void addMethodReturnType(MethodReturnType methodReturnType)
 {
     if (methodReturnType == null)
         return;
     pushMember(methodReturnType.Method as MemberReference);
     pushMember(methodReturnType.ReturnType);
     addParameterDefinition(methodReturnType.Parameter);
 }
Example #15
0
        public static TypeDefinition CreateDelegate(ModuleDefinition module, string @namespace, string name,
            TypeAttributes delegateVisibility = TypeAttributes.NotPublic, MethodReturnType returnType = null,
            IEnumerable<ParameterDefinition> parameters = null)
        {
            if ((delegateVisibility & TypeAttributes.VisibilityMask) != delegateVisibility)
            throw new ArgumentException("Parameter may only contain visibility attributes.", "delegateVisibility");
              var objectRef = module.TypeSystem.Object;
              var voidRef = module.TypeSystem.Void;
              var intPtrRef = module.TypeSystem.IntPtr;
              var multicastDelegateRef = module.Import(typeof(MulticastDelegate));
              var asyncCallbackRef = module.Import(typeof(AsyncCallback));
              var iAsyncResultRef = module.Import(typeof(IAsyncResult));

              if (returnType == null)
            returnType = new MethodReturnType(null) { ReturnType = voidRef };
              if (parameters == null)
            parameters = Enumerable.Empty<ParameterDefinition>();

              TypeAttributes typeAttributes = delegateVisibility | TypeAttributes.AnsiClass | TypeAttributes.Sealed;
              TypeDefinition td = new TypeDefinition(@namespace, name, typeAttributes, multicastDelegateRef);
              MethodAttributes ctorAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
            MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
              //.ctor
              MethodDefinition ctor = new MethodDefinition(".ctor", ctorAttributes, voidRef) {
            IsRuntime = true, IsManaged = true
              };
              ctor.Parameters.Add(new ParameterDefinition("object", ParameterAttributes.None, objectRef));
              ctor.Parameters.Add(new ParameterDefinition("method", ParameterAttributes.None, intPtrRef));
              td.Methods.Add(ctor);
              //Invoke
              MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
            MethodAttributes.NewSlot | MethodAttributes.Virtual;
              MethodDefinition InvokeMethod = new MethodDefinition("Invoke", methodAttributes, returnType.ReturnType) {
            IsRuntime = true, IsManaged = true
              };
              CopyReturnTypeTo(InvokeMethod.MethodReturnType, returnType);
              foreach (var p in parameters)
            InvokeMethod.Parameters.Add(p);
              td.Methods.Add(InvokeMethod);
              //BeginInvoke
              MethodDefinition BeginInvokeMethod = new MethodDefinition("BeginInvoke", methodAttributes, iAsyncResultRef) {
            IsRuntime = true, IsManaged = true
              };
              foreach (var p in parameters)
            BeginInvokeMethod.Parameters.Add(p);
              BeginInvokeMethod.Parameters.Add(new ParameterDefinition("callback", ParameterAttributes.None, asyncCallbackRef));
              BeginInvokeMethod.Parameters.Add(new ParameterDefinition("object", ParameterAttributes.None, objectRef));
              td.Methods.Add(BeginInvokeMethod);
              //EndInvoke
              MethodDefinition EndInvokeMethod = new MethodDefinition("EndInvoke", methodAttributes, returnType.ReturnType) {
            IsRuntime = true, IsManaged = true
              };
              CopyReturnTypeTo(EndInvokeMethod.MethodReturnType, returnType);
              EndInvokeMethod.Parameters.Add(new ParameterDefinition("result", ParameterAttributes.None, iAsyncResultRef));
              td.Methods.Add(EndInvokeMethod);
              return td;
        }
Example #16
0
 public CallSite(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
 {
     m_function            = new MethodReference(string.Empty, hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
Example #17
0
 private void Merge(DeepCopier copier, MethodReturnType def1, MethodReturnType def2)
 {
     copier.MergeAll(def1,def2,def2,"Method","ReturnType");
 }
		public MethodReference (string name,
			TypeReference declaringType, TypeReference returnType,
			bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
			this (name, hasThis, explicitThis, callConv)
		{
			this.DeclaringType = declaringType;
			this.ReturnType.ReturnType = returnType;
		}
		internal MethodReference ()
		{
			this.return_type = new MethodReturnType (this);
			this.token = new MetadataToken (TokenType.MemberRef);
		}
Example #20
0
 public static bool MethodReturnTypeEquals(MethodReturnType a, MethodReturnType b)
 {
     return a.HasConstant == b.HasConstant && TypeReferenceEquals(a.ReturnType, b.ReturnType);
 }
 private Type MapReturnType(MethodReturnType returnType)
 {
     return outer.ResolveReturnType(returnType);
 }
		/*Telerik Authorship*/
		/// <summary>
		/// Performs shallow clone of the MethodReturnType of <paramref name="method"/>
		/// </summary>
		private MethodReturnType DeepCloneMethodReturnType(MethodReference method)
		{
			MethodReturnType result = new MethodReturnType(this); // not sure how will this behave
			result.parameter = method.MethodReturnType.parameter;
			result.ReturnType = DeepCloneType(method.ReturnType);

			return result;
		}
 private IEnumerable<ProjectReference> GetMethodReturnAttributesReferences(
     MethodReturnType methodReturnType, AuditEntryParameters parameters)
 {
     if (methodReturnType.HasCustomAttributes)
     {
         var references = methodReturnType.CustomAttributes.
                     SelectMany(ca => GetCustomAttributeReferences(ca, parameters));
         foreach(var projectReference in references)
             yield return projectReference;
     }
     if (methodReturnType.HasMarshalInfo)
     {
         var projectReference = GetMarshalInfoReference(methodReturnType.MarshalInfo, parameters);
         if (projectReference != null)
             yield return projectReference;
     }
     yield break;
 }
 protected DefaultMarshalInfoWriter MarshalInfoWriterFor(MethodReturnType methodReturnType)
 {
     return this._marshaler.MarshalInfoWriterFor(methodReturnType);
 }
Example #25
0
        private MethodReturnType Copy(DeepCopier copier, MethodReturnType def, IMethodSignature parent)
        {
            var ret= new MethodReturnType(parent);
            ret.ReturnType = CopyReference(copier,def.ReturnType);

            copier.Log("< MethodReturnType ");
            copier.CopyAll(def,ret,ret,"Method","ReturnType");

            return ret;
        }
 internal Type ResolveReturnType(MethodReturnType returnType)
 {
     return ResolveType(returnType.ReturnType);
 }
 bool RequiresParameterRow(MethodReturnType mrt)
 {
     return mrt.HasConstant || mrt.MarshalSpec != null ||
         mrt.CustomAttributes.Count > 0 || mrt.Parameter.Attributes != (ParamAttributes) 0;
 }
Example #28
0
 public FunctionPointerType(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
     : base(retType.ReturnType)
 {
     m_function = new MethodReference ("method", hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
Example #29
0
 public static string ForReturnType(MethodReturnType methodReturnType)
 {
     var name = methodReturnType.GetNamedAttributeName();
     return ForType(methodReturnType.ReturnType, name);
 }
Example #30
0
        internal MethodReturnType ResolveGenericTypes(Collection<GenericParameter> parameters, Collection<TypeReference> arguments)
        {
            TypeReference resolved = MemberReference.ResolveType (return_type, parameters, arguments);
            MethodReturnType result;

            if (resolved == return_type)
                return this;

            result = new MethodReturnType (method);
            result.ReturnType = resolved;
            if (parameter != null) {
                result.MetadataToken = MetadataToken;
                result.MarshalInfo = MarshalInfo;
                result.Constant = Constant;
                //TODO: result.m_param.CustomAttributes = CustomAttributes;
            }
            return result;
        }
Example #31
0
 public FunctionPointerType(bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType) :
     base(retType.ReturnType)
 {
     m_function            = new MethodReference("method", hasThis, explicitThis, callConv);
     m_function.ReturnType = retType;
 }
        private void InitializeReturnType(MethodBuilder methodBuilder, MethodReturnType returnType)
        {
            methodBuilder.SetReturnType(ResolveReturnType(returnType));

            ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0,
                System.Reflection.ParameterAttributes.Retval, null);

            if (returnType.HasConstant)
                parameterBuilder.SetConstant(returnType.Constant);

            metadataPass.Add(delegate
            {
                InitializeCustomAttributes(parameterBuilder.SetCustomAttribute, returnType.CustomAttributes);
            });
        }
		public CallSite (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
		{
			m_function = new MethodReference (string.Empty, hasThis, explicitThis, callConv);
			m_function.ReturnType = retType;
		}
Example #34
0
 internal MethodReference()
 {
     return_type = new MethodReturnType(this);
     base.token  = new MetadataToken(TokenType.MemberRef);
 }