本文整理汇总了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);
}
}
}