本文整理匯總了C#中Mono.Cecil.Cil.Instruction.GetField方法的典型用法代碼示例。如果您正苦於以下問題:C# Instruction.GetField方法的具體用法?C# Instruction.GetField怎麽用?C# Instruction.GetField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mono.Cecil.Cil.Instruction
的用法示例。
在下文中一共展示了Instruction.GetField方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CheckDoubleAssignement
static string CheckDoubleAssignement (MethodDefinition method, Instruction ins, Instruction next)
{
// for a static field the pattern is
// DUP, STSFLD, STSFLD
if (ins.OpCode.Code == Code.Stsfld) {
if (next.OpCode.Code != Code.Stsfld)
return String.Empty;
// check that we're assigning the same field twice
FieldDefinition fd1 = ins.GetField ();
FieldDefinition fd2 = next.GetField ();
if (fd1.MetadataToken.RID != fd2.MetadataToken.RID)
return String.Empty;
return String.Format ("Static field '{0}'.", fd1.Name);
} else if (ins.IsStoreLocal ()) {
// for a local variable the pattern is
// DUP, STLOC, STLOC
VariableDefinition vd2 = next.GetVariable (method);
// check that we're assigning the same variable twice
if (vd2 != null) {
VariableDefinition vd1 = ins.GetVariable (method);
if (vd1.Index != vd2.Index)
return String.Empty;
return String.Format ("Local variable '{0}'.", vd1.Name);
} else if (next.OpCode.Code == Code.Stfld) {
// instance fields are a bit more complex...
return CheckDoubleAssignementOnInstanceFields (method, ins, next);
}
}
return String.Empty;
}
示例2: CheckFields
void CheckFields (Instruction ins, Instruction next, MethodDefinition method, bool isStatic)
{
FieldDefinition field = ins.GetField ();
if ((field != null) && (field == next.GetField ())) {
// instance fields need extra comparison using method
if (isStatic || Compare (next, ins, method)) {
string msg = String.Format (CultureInfo.InvariantCulture, "{0} field '{1}' of type '{2}'.",
isStatic ? "Static" : "Instance", field.Name, field.FieldType.GetFullName ());
Runner.Report (method, ins, Severity.Medium, Confidence.Normal, msg);
}
}
}