當前位置: 首頁>>代碼示例>>C#>>正文


C# Instruction.GetField方法代碼示例

本文整理匯總了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;
		}
開發者ID:boothead,項目名稱:mono-tools,代碼行數:33,代碼來源:ReviewDoubleAssignmentRule.cs

示例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);
				}
			}
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:12,代碼來源:ReviewSelfAssignmentRule.cs


注:本文中的Mono.Cecil.Cil.Instruction.GetField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。