本文整理汇总了C#中Mono.Cecil.MethodReference.ChangeDeclaringType方法的典型用法代码示例。如果您正苦于以下问题:C# MethodReference.ChangeDeclaringType方法的具体用法?C# MethodReference.ChangeDeclaringType怎么用?C# MethodReference.ChangeDeclaringType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.MethodReference
的用法示例。
在下文中一共展示了MethodReference.ChangeDeclaringType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFunction
/// <summary>
/// Creates the function.
/// </summary>
/// <param name="method">The method.</param>
/// <returns></returns>
Function CreateFunction(MethodReference method)
{
Function function;
if (functions.TryGetValue(method, out function))
return function;
var resolvedMethod = method.Resolve();
var declaringType = GetType(ResolveGenericsVisitor.Process(method, method.DeclaringType), TypeState.Opaque);
// Check if method is only defined in a parent class (can happen in some rare case, i.e. PCL TypeInfo.get_Assembly()).
bool hasMatch = MetadataResolver.GetMethod(declaringType.TypeDefinitionCecil.Methods, method.GetElementMethod()) != null;
if (resolvedMethod != null && !hasMatch)
{
var parentType = declaringType.TypeDefinitionCecil.BaseType != null ? ResolveGenericsVisitor.Process(declaringType.TypeReferenceCecil, declaringType.TypeDefinitionCecil.BaseType) : null;
if (parentType == null)
throw new InvalidOperationException(string.Format("Could not find a matching method in any of the type or its parent for {0}", method));
// Create function with parent type
// TODO: Maybe we need to replace generic context with parent type?
var parentMethod = method.ChangeDeclaringType(parentType);
function = CreateFunction(parentMethod);
// Register it so that it can be cached
functions.Add(method, function);
return function;
}
var returnType = GetType(ResolveGenericsVisitor.Process(method, method.ReturnType), TypeState.StackComplete);
var parameterTypesBuilder = new List<Type>();
if (method.HasThis)
{
var parameterType = declaringType.TypeReferenceCecil;
// Value type uses ByReference type for this
if (declaringType.TypeDefinitionCecil.IsValueType)
parameterType = parameterType.MakeByReferenceType();
parameterTypesBuilder.Add(GetType(parameterType, TypeState.StackComplete));
}
foreach (var parameter in method.Parameters)
{
parameterTypesBuilder.Add(GetType(ResolveGenericsVisitor.Process(method, parameter.ParameterType), TypeState.StackComplete));
}
var parameterTypes = parameterTypesBuilder.ToArray();
// Find calling convention
var callingConvention = method.CallingConvention;
PInvokeInfo pinvokeInfo = null;
if (resolvedMethod != null && resolvedMethod.HasPInvokeInfo)
{
pinvokeInfo = resolvedMethod.PInvokeInfo;
if (resolvedMethod.PInvokeInfo.IsCallConvStdCall || resolvedMethod.PInvokeInfo.IsCallConvWinapi)
callingConvention = MethodCallingConvention.StdCall;
else if (resolvedMethod.PInvokeInfo.IsCallConvFastcall)
callingConvention = MethodCallingConvention.FastCall;
}
var functionSignature = new FunctionSignature(abi, returnType, parameterTypes, callingConvention, pinvokeInfo);
var functionType = CreateFunctionTypeLLVM(functionSignature);
// If we have an external with generic parameters, let's try to do some generic sharing (we can write only one in C++)
bool isInternal = resolvedMethod != null && ((resolvedMethod.ImplAttributes & MethodImplAttributes.InternalCall) != 0);
if (isInternal && resolvedMethod.HasGenericParameters && resolvedMethod.GenericParameters.All(x => x.HasReferenceTypeConstraint))
{
// Check if this isn't the shareable method (in which case we should do normal processing)
if (!((GenericInstanceMethod)method).GenericArguments.All(x => MemberEqualityComparer.Default.Equals(x, @object.TypeReferenceCecil)))
{
// Let's share it with default method
var sharedGenericInstance = new GenericInstanceMethod(resolvedMethod);
foreach (var genericParameter in resolvedMethod.GenericParameters)
{
sharedGenericInstance.GenericArguments.Add(@object.TypeReferenceCecil);
}
var sharedMethod = GetFunction(sharedGenericInstance);
// Cast shared function to appropriate pointer type
var sharedFunctionGlobal = LLVM.ConstPointerCast(sharedMethod.GeneratedValue, LLVM.PointerType(functionType, 0));
function = new Function(declaringType, method, functionType, sharedFunctionGlobal, functionSignature);
functions.Add(method, function);
return function;
}
}
// Determine if type and function is local, and linkage type
bool isLocal;
var linkageType = GetLinkageType(method.DeclaringType, out isLocal);
if (isInternal)
{
// Should be switched to non-weak when we have complete implementation of every internal calls
linkageType = Linkage.ExternalWeakLinkage;
}
else if (resolvedMethod != null && resolvedMethod.HasGenericParameters)
//.........这里部分代码省略.........