本文整理汇总了C#中MethodDefinition.Instantiate方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.Instantiate方法的具体用法?C# MethodDefinition.Instantiate怎么用?C# MethodDefinition.Instantiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodDefinition
的用法示例。
在下文中一共展示了MethodDefinition.Instantiate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadInstructionCov
private void ReadInstructionCov(MethodDefinition method, int[] hits,
MethodDefinitionBodyInstrumentationInfo info)
{
Instruction instruction;
Method instantiate = null;
bool logInstruction = false;
if (method.FullName.StartsWith("System") || method.FullName.StartsWith("Microsoft.Pex.Framework"))
{
return;
}
try
{
instantiate = method.Instantiate(TypeEx.NoTypes, TypeEx.NoTypes);
MethodBodyEx body;
if (instantiate.TryGetBody(out body))
{
foreach (var i in info.BasicBlockStartOffsets)
{
if (!basicBlockOffsets.ContainsKey(method.FullName))
{
basicBlockOffsets[method.FullName] = new HashSet<int>();
}
basicBlockOffsets[method.FullName].Add(i);
}
body.TryGetInstruction(0, out instruction);
Converter<int, int> covConverter = info.GetInstructionCoverage(hits);
int coveredTimes = covConverter.Invoke(0);
int nextOffset = instruction.NextOffset;
if (logInstruction)
{
Log.AppendLine("instruction: " + instruction.Offset.ToString("x") +
" code: " + instruction.OpCode + " covered " +
coveredTimes + " times " +
" next: " + nextOffset.ToString("x"));
}
if (!instructionCov.ContainsKey(method.FullName))
{
instructionCov[method.FullName] = new Dictionary<int, int>();
instructionCov[method.FullName][0] = coveredTimes;
}
else
{
instructionCov[method.FullName][0] = coveredTimes;
}
while (body.TryGetInstruction(nextOffset, out instruction))
{
nextOffset = instruction.NextOffset;
coveredTimes = covConverter.Invoke(nextOffset);
if (logInstruction)
{
Log.AppendLine("instruction: " + instruction.Offset.ToString("x") +
" code: " + instruction.OpCode + " covered " +
coveredTimes + " times " +
" next: " + nextOffset.ToString("x"));
}
instructionCov[method.FullName][instruction.Offset] = coveredTimes;
}
}
}
catch (Exception ex)
{
ErrorLog.AppendLine("error in ReadInstructionCov of method: " + method + "\n" + ex);
return;
}
}
示例2: TryCheckReturnTypeOfMethod
public static bool TryCheckReturnTypeOfMethod(PexMeDynamicDatabase pmd, TypeDefinition tdef,
MethodDefinition mdef, TypeEx targetTypeEx, out Method producingMethod)
{
var retType = mdef.ResultType;
if (retType.ToString() == targetTypeEx.FullName)
{
producingMethod = mdef.Instantiate(MethodOrFieldAnalyzer.GetGenericTypeParameters(pmd, tdef),
MethodOrFieldAnalyzer.GetGenericMethodParameters(pmd, mdef));
return true;
}
//Get the actual type of return type and see whether it is assinable
TypeEx retTypeEx;
if (MethodOrFieldAnalyzer.TryGetTypeExFromName(pmd, pmd.CurrAssembly, retType.ToString(), out retTypeEx))
{
if (targetTypeEx.IsAssignableTo(retTypeEx))
{
producingMethod = mdef.Instantiate(MethodOrFieldAnalyzer.GetGenericTypeParameters(pmd, tdef),
MethodOrFieldAnalyzer.GetGenericMethodParameters(pmd, mdef));
return true;
}
}
producingMethod = null;
return false;
}