當前位置: 首頁>>代碼示例>>C#>>正文


C# Cecil.MethodReference類代碼示例

本文整理匯總了C#中Mono.Cecil.MethodReference的典型用法代碼示例。如果您正苦於以下問題:C# MethodReference類的具體用法?C# MethodReference怎麽用?C# MethodReference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MethodReference類屬於Mono.Cecil命名空間,在下文中一共展示了MethodReference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CloneMethodWithDeclaringType

    private static MethodReference CloneMethodWithDeclaringType(MethodDefinition methodDef, TypeReference declaringTypeRef)
    {
        if (!declaringTypeRef.IsGenericInstance || methodDef == null)
        {
            return methodDef;
        }

        var methodRef = new MethodReference(methodDef.Name, methodDef.ReturnType, declaringTypeRef)
        {
            CallingConvention = methodDef.CallingConvention,
            HasThis = methodDef.HasThis,
            ExplicitThis = methodDef.ExplicitThis
        };

        foreach (var paramDef in methodDef.Parameters)
        {
            methodRef.Parameters.Add(new ParameterDefinition(paramDef.Name, paramDef.Attributes, paramDef.ParameterType));
        }

        foreach (var genParamDef in methodDef.GenericParameters)
        {
            methodRef.GenericParameters.Add(new GenericParameter(genParamDef.Name, methodRef));
        }

        return methodRef;
    }
開發者ID:mdabbagh88,項目名稱:Ionad,代碼行數:26,代碼來源:CecilExtensions.cs

示例2: Convert

    public IEnumerable<Instruction> Convert(MethodReference method)
    {
        if (method.Name != "IndexOf")
        {
            yield break;
        }

        if (method.Parameters.Matches("String"))
        {
            yield return Instruction.Create(OpCodes.Ldc_I4, StringComparisonConstant);
            yield return Instruction.Create(OpCodes.Callvirt, reference_String);
            yield break;
        }
        if (method.Parameters.Matches("String","Int32"))
        {
            yield return Instruction.Create(OpCodes.Ldc_I4, StringComparisonConstant);
            yield return Instruction.Create(OpCodes.Callvirt, reference_StringInt);
            yield break;
        }
        if (method.Parameters.Matches("String", "Int32", "Int32"))
        {
            yield return Instruction.Create(OpCodes.Ldc_I4, StringComparisonConstant);
            yield return Instruction.Create(OpCodes.Callvirt, reference_StringIntInt);
        }
    }
開發者ID:mdabbagh88,項目名稱:Caseless,代碼行數:25,代碼來源:IndexOfConverter.cs

示例3: FunctionPointerType

 public FunctionPointerType()
     : base(null)
 {
     this.function = new MethodReference ();
     this.function.Name = "method";
     this.etype = MD.ElementType.FnPtr;
 }
開發者ID:Tianjiao,項目名稱:cecil,代碼行數:7,代碼來源:FunctionPointerType.cs

示例4: add

 public void add(MethodReference calledMethod)
 {
     int count;
     var key = new MethodReferenceAndDeclaringTypeKey(calledMethod);
     calls.TryGetValue(key, out count);
     calls[key] = count + 1;
 }
開發者ID:n017,項目名稱:NETDeob,代碼行數:7,代碼來源:DotNetUtils.cs

示例5: BuildMethodParameterList

 internal static string BuildMethodParameterList(MethodReference interopMethod, MethodReference interfaceMethod, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, MarshalType marshalType, bool includeTypeNames)
 {
     List<string> elements = new List<string>();
     int num = 0;
     foreach (ParameterDefinition definition in interopMethod.Parameters)
     {
         MarshalInfo marshalInfo = interfaceMethod.Parameters[num].MarshalInfo;
         DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(typeResolver.Resolve(definition.ParameterType), marshalType, marshalInfo, true, false, false, null);
         foreach (MarshaledType type in writer.MarshaledTypes)
         {
             elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0} {1}", type.DecoratedName, Naming.ForParameterName(definition) + type.VariableName));
         }
         num++;
     }
     TypeReference reference2 = typeResolver.Resolve(interopMethod.ReturnType);
     if (reference2.MetadataType != MetadataType.Void)
     {
         MarshalInfo info2 = interfaceMethod.MethodReturnType.MarshalInfo;
         MarshaledType[] marshaledTypes = MarshalDataCollector.MarshalInfoWriterFor(reference2, marshalType, info2, true, false, false, null).MarshaledTypes;
         for (int i = 0; i < (marshaledTypes.Length - 1); i++)
         {
             elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[i].DecoratedName, Naming.ForComInterfaceReturnParameterName() + marshaledTypes[i].VariableName));
         }
         elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[marshaledTypes.Length - 1].DecoratedName, Naming.ForComInterfaceReturnParameterName()));
     }
     return EnumerableExtensions.AggregateWithComma(elements);
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:27,代碼來源:ComInterfaceWriter.cs

示例6: MakeHostInstanceGeneric

    public static MethodReference MakeHostInstanceGeneric(this MethodReference @this, params TypeReference[] genericArguments)
    {
        var genericDeclaringType = new GenericInstanceType(@this.DeclaringType);
        foreach (var genericArgument in genericArguments)
        {
            genericDeclaringType.GenericArguments.Add(genericArgument);
        }

        var reference = new MethodReference(@this.Name, @this.ReturnType, genericDeclaringType)
        {
            HasThis = @this.HasThis,
            ExplicitThis = @this.ExplicitThis,
            CallingConvention = @this.CallingConvention
        };

        foreach (var parameter in @this.Parameters)
        {
            reference.Parameters.Add(new ParameterDefinition(parameter.ParameterType));
        }

        foreach (var genericParam in @this.GenericParameters)
        {
            reference.GenericParameters.Add(new GenericParameter(genericParam.Name, reference));
        }

        return reference;
    }
開發者ID:realm,項目名稱:realm-dotnet,代碼行數:27,代碼來源:MethodReferenceExtensions.cs

示例7: FixArguments

		private void FixArguments(MethodReference method, ExpressionCollection arguments)
		{
			TypeDefinition declaringTypeDefinition = method.DeclaringType.Resolve();
			if (declaringTypeDefinition == null)
			{
				return;
			}
			List<MethodDefinition> sameNameMethods = GetSameNameMethods(declaringTypeDefinition, method, arguments);
			if (sameNameMethods.Count > 0)
			{
				for (int i = 0; i < arguments.Count; i++)
				{
					TypeReference paramType = method.Parameters[i].ResolveParameterType(method);
					if (!arguments[i].HasType)
					{
						continue;
					}
					if (arguments[i].ExpressionType.FullName == paramType.FullName)
					{
						continue;
					}
					if (ShouldAddCast(arguments[i], sameNameMethods, i, paramType))
					{
						arguments[i] = new CastExpression(arguments[i], paramType, null);
					}
				}
			}
		}
開發者ID:Feng2012,項目名稱:JustDecompileEngine,代碼行數:28,代碼來源:FixMethodOverloadsStep.cs

示例8: CastMethodArguments

		private void CastMethodArguments(MethodReference method, ExpressionCollection arguments)
		{
			for (int i = 0; i < arguments.Count; i++)
			{
				Expression argument = arguments[i];

				TypeReference parameterType = method.Parameters[i].ResolveParameterType(method);

				if (argument.HasType && parameterType != null && !(argument is LiteralExpression))
				{
					TypeReference argumentType = argument.ExpressionType;
					if ((IsUnsignedIntegerType(argumentType) && IsSignedIntegerType(parameterType)) || (IsSignedIntegerType(argumentType) && IsUnsignedIntegerType(parameterType)))
					{
						Expression toCast = argument;

						if (argument is CastExpression)
						{
							CastExpression argumentCast = argument as CastExpression;
							if (IsIntegerType(argumentCast.TargetType))
							{
								toCast = argumentCast.Expression;
							}
						}

						arguments[i] = new CastExpression(toCast, parameterType, null);
					}
				}
			}
		}
開發者ID:juancarlosbaezpozos,項目名稱:JustDecompileEngine,代碼行數:29,代碼來源:CastIntegersStep.cs

示例9: AreSame

        public static bool AreSame(this MethodReference method, MethodReference other)
        {
            var possiblyEqual =
                method.DeclaringType.FullName.Equals(other.DeclaringType.FullName, StringComparison.Ordinal)
                && method.FullName.Equals(other.FullName, StringComparison.Ordinal)
                && method.Parameters.Count == other.Parameters.Count
                && method.GenericParameters.Count == other.GenericParameters.Count
                && method.IsGenericInstance == other.IsGenericInstance;

            if (!possiblyEqual)
            {
                return false;
            }

            for (var i = 0; i < method.Parameters.Count; ++i)
            {
                var pThis = method.Parameters[i];
                var pThat = other.Parameters[i];

                if (!pThis.ParameterType.FullName.Equals(pThat.ParameterType.FullName, StringComparison.Ordinal))
                {
                    return false;
                }
            }

            return true;
        }
開發者ID:benjamin-bader,項目名稱:stiletto,代碼行數:27,代碼來源:MethodReferenceExtensions.cs

示例10: GetNormalOperand

 public MethodReference GetNormalOperand(MethodReference methodReference)
 {
     var name = methodReference.Name;
     if (name == "Trace")
     {
         return TraceMethod;
     }
     if (name == "Debug")
     {
         return DebugMethod;
     }
     if (name == "Info")
     {
         return InfoMethod;
     }
     if (name == "Warn")
     {
         return WarnMethod;
     }
     if (name == "Error")
     {
         return ErrorMethod;
     }
     if (name == "Fatal")
     {
         return FatalMethod;
     }
     throw new Exception("Invalid method name");
 }
開發者ID:AndreGleichner,項目名稱:Anotar,代碼行數:29,代碼來源:InjectorExtentions.cs

示例11: Create

 public static GenericBindingContext Create(MethodReference methodReference)
 {
     var genericMethod = methodReference as GenericInstanceMethod;
     return genericMethod != null
         ? new GenericBindingContext(genericMethod)
         : new GenericBindingContext();
 }
開發者ID:gmf520,項目名稱:Smocks,代碼行數:7,代碼來源:GenericBindingContext.cs

示例12: InjectEqualsObject

        public static MethodDefinition InjectEqualsObject(TypeDefinition type, TypeReference typeRef, MethodReference newEquals, int typeCheck)
        {
            var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
            var method = new MethodDefinition("Equals", methodAttributes, ReferenceFinder.Boolean.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var obj = method.Parameters.Add("obj", ReferenceFinder.Object.TypeReference);

            var body = method.Body;
            var result = body.Variables.Add("result", ReferenceFinder.Boolean.TypeReference);

            var ins = body.Instructions;

            var labelRet = Instruction.Create(OpCodes.Nop);

            AddCheckEqualsReference(type, ins);

            ins.If(
                c => AddTypeChecking(type, typeRef, typeCheck, c),
                t => AddInternalEqualsCall(type, typeRef, newEquals, t, result),
                e => AddReturnFalse(e));

            AddReturn(ins, labelRet, result);

            body.OptimizeMacros();

            type.Methods.Add(method);

            return method;
        }
開發者ID:kzaikin,項目名稱:Equals,代碼行數:30,代碼來源:EqualsInjector.cs

示例13: GetMethod

        public static MethodDefinition GetMethod(IList<MethodDefinition> methods, MethodReference reference)
        {
            for (int i = 0; i < methods.Count; i++) {
                var method = methods [i];

                if (method.Name != reference.Name)
                    continue;

                if (!AreSame (method.ReturnType, reference.ReturnType))
                    continue;

                if (method.HasParameters != reference.HasParameters)
                    continue;

                if (!method.HasParameters && !reference.HasParameters)
                    return method;

                if (!AreSame (method.Parameters, reference.Parameters))
                    continue;

                return method;
            }

            return null;
        }
開發者ID:peterwald,項目名稱:cecil,代碼行數:25,代碼來源:MetadataResolver.cs

示例14: ILBlockTranslator

        public ILBlockTranslator(AssemblyTranslator translator, DecompilerContext context, MethodReference methodReference, MethodDefinition methodDefinition, ILBlock ilb, IEnumerable<ILVariable> parameters, IEnumerable<ILVariable> allVariables)
        {
            Translator = translator;
            Context = context;
            ThisMethodReference = methodReference;
            ThisMethod = methodDefinition;
            Block = ilb;

            SpecialIdentifiers = new JSIL.SpecialIdentifiers(TypeSystem);

            if (methodReference.HasThis)
                Variables.Add("this", JSThisParameter.New(methodReference.DeclaringType, methodReference));

            foreach (var parameter in parameters) {
                if ((parameter.Name == "this") && (parameter.OriginalParameter.Index == -1))
                    continue;

                ParameterNames.Add(parameter.Name);
                Variables.Add(parameter.Name, new JSParameter(parameter.Name, parameter.Type, methodReference));
            }

            foreach (var variable in allVariables) {
                var v = JSVariable.New(variable, methodReference);
                if (Variables.ContainsKey(v.Identifier)) {
                    v = new JSVariable(variable.OriginalVariable.Name, variable.Type, methodReference);
                    RenamedVariables[variable] = v;
                    Variables.Add(v.Identifier, v);
                } else {
                    Variables.Add(v.Identifier, v);
                }
            }
        }
開發者ID:aprishchepov,項目名稱:JSIL,代碼行數:32,代碼來源:ILBlockTranslator.cs

示例15: Init

 public void Init()
 {
     var methods = MsCoreReferenceFinder.StringDefinition.Methods;
     reference_String = ModuleDefinition.ImportReference(methods.First(x => x.Name == "IndexOf" && x.Parameters.Matches("String", "StringComparison")));
     reference_StringInt = ModuleDefinition.ImportReference(methods.First(x => x.Name == "IndexOf" && x.Parameters.Matches("String", "Int32", "StringComparison")));
     reference_StringIntInt = ModuleDefinition.ImportReference(methods.First(x => x.Name == "IndexOf" && x.Parameters.Matches("String", "Int32", "Int32", "StringComparison")));
 }
開發者ID:mdabbagh88,項目名稱:Caseless,代碼行數:7,代碼來源:IndexOfConverter.cs


注:本文中的Mono.Cecil.MethodReference類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。