本文整理汇总了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;
}
示例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);
}
}
示例3: FunctionPointerType
public FunctionPointerType()
: base(null)
{
this.function = new MethodReference ();
this.function.Name = "method";
this.etype = MD.ElementType.FnPtr;
}
示例4: add
public void add(MethodReference calledMethod)
{
int count;
var key = new MethodReferenceAndDeclaringTypeKey(calledMethod);
calls.TryGetValue(key, out count);
calls[key] = count + 1;
}
示例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);
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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;
}
示例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");
}
示例11: Create
public static GenericBindingContext Create(MethodReference methodReference)
{
var genericMethod = methodReference as GenericInstanceMethod;
return genericMethod != null
? new GenericBindingContext(genericMethod)
: new GenericBindingContext();
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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")));
}