本文整理匯總了C#中Mono.Cecil.MethodDefinition.GetCacheName方法的典型用法代碼示例。如果您正苦於以下問題:C# MethodDefinition.GetCacheName方法的具體用法?C# MethodDefinition.GetCacheName怎麽用?C# MethodDefinition.GetCacheName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mono.Cecil.MethodDefinition
的用法示例。
在下文中一共展示了MethodDefinition.GetCacheName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TranslateGeneratedMethod
// This code has a lot of external dependencies.
// It depends on how the C# compiler lays out IL of anonymous methods in IL
// If compiler stops caching, this stops working.
// If mono does it even slightly differently it stops working
// If mspec changes the definition of their "It" this should still work
public static FieldDefinition TranslateGeneratedMethod(MethodDefinition definition)
{
try
{
if (definition == null) return null;
if (!definition.HasBody) return null;
var constructor = definition.DeclaringType.Methods.FirstOrDefault(x => x.Name == ".ctor");
if (constructor == null) return null;
var body = constructor.Body;
for (var i = 0; i < body.Instructions.Count; i++)
{
var instruction = body.Instructions[i];
if (instruction.OpCode.Code == Code.Ldftn)
{
var reference = instruction.Operand as MethodReference;
if (reference == null) continue;
var resolved = reference.ThreadSafeResolve();
if (resolved == null) continue;
if (resolved.GetCacheName() == definition.GetCacheName())
{
var nextstsfld = GetNextInstructionAfter(i, body.Instructions, Code.Stsfld);
if (nextstsfld == -1) continue;
var cachedfield = body.Instructions[nextstsfld].Operand as FieldReference;
if (cachedfield == null) continue;
var nextldsfld = GetNextInstructionAfter(nextstsfld, body.Instructions, Code.Ldsfld);
if (nextldsfld == -1 ||
cachedfield.FullName !=
((FieldReference) body.Instructions[nextldsfld].Operand).FullName) continue;
if (body.Instructions[nextldsfld + 1].OpCode.Code != Code.Stfld) continue;
return ((FieldReference) body.Instructions[nextldsfld + 1].Operand).Resolve();
}
}
}
} catch
{
}
return null;
}
示例2: ScanMethod
public static ScanResult ScanMethod(MethodDefinition method)
{
try
{
var dep = new List<MemberAccess>();
if (!method.HasBody) return new ScanResult(dep, method, 0);
int complexity = 0;
for (int index = 0; index < method.Body.Instructions.Count; index++)
{
var instruction = method.Body.Instructions[index];
var memberRef = instruction.Operand as MemberReference;
if (branches[(int) instruction.OpCode.Code])
{
complexity++;
}
if (memberRef != null)
{
var methodReference = memberRef as MethodReference;
var info = new MethodCallInfo(false, null, false);
if (methodReference != null && methodReference.HasThis)
{
info = GetEnhancedCallInformation(instruction, method.HasThis);
}
var methodDef = memberRef as MethodDefinition;
if (instruction.OpCode == OpCodes.Ldfld || instruction.OpCode == OpCodes.Ldsfld ||
(methodDef != null && methodDef.IsConstructor))
dep.AddNotExist(new MemberAccess(memberRef, true, info.IsSelfCall, info.FieldReference,
methodReference, info.IsLocal));
else
dep.AddNotExist(new MemberAccess(memberRef, false, info.IsSelfCall, info.FieldReference,
methodReference, info.IsLocal));
}
}
return new ScanResult(dep, method, complexity);
}
catch (Exception ex)
{
throw new MethodDependencyDetectionFailedException(method.GetCacheName(), ex);
}
}