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


C# TypeDefinition.GetMethod方法代碼示例

本文整理匯總了C#中Mono.Cecil.TypeDefinition.GetMethod方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeDefinition.GetMethod方法的具體用法?C# TypeDefinition.GetMethod怎麽用?C# TypeDefinition.GetMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.TypeDefinition的用法示例。


在下文中一共展示了TypeDefinition.GetMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// that will cover interfaces, delegates too
			if (!type.HasFields)
				return RuleResult.DoesNotApply;

			// rule doesn't apply to enums, interfaces, structs, delegates or generated code
			if (type.IsEnum || type.IsValueType || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			MethodDefinition explicitDisposeMethod = null;
			MethodDefinition implicitDisposeMethod = null;

			bool abstractWarning = false;

			if (type.Implements ("System", "IDisposable")) {
				implicitDisposeMethod = type.GetMethod (MethodSignatures.Dispose);
				explicitDisposeMethod = type.GetMethod (MethodSignatures.DisposeExplicit);

				if (IsAbstract (implicitDisposeMethod) || IsAbstract (explicitDisposeMethod)) {
					abstractWarning = true;
				} else {
					return RuleResult.Success;
				}
			}

			FieldCandidates.Clear ();

			foreach (FieldDefinition field in type.Fields) {
				// we can't dispose static fields in IDisposable
				if (field.IsStatic)
					continue;
				TypeDefinition fieldType = field.FieldType.GetElementType ().Resolve ();
				if (fieldType == null)
					continue;
				if (FieldTypeIsCandidate (fieldType))
					FieldCandidates.Add (field);
			}

			// if there are fields types that implements IDisposable
			if (type.HasMethods && (FieldCandidates.Count > 0)) {
				// check if we're assigning new object to them
				foreach (MethodDefinition method in type.Methods) {
					CheckMethod (method, abstractWarning);
				}
			}

			// Warn about possible confusion if the Dispose methods are abstract
			if (IsAbstract (implicitDisposeMethod))
				Runner.Report (implicitDisposeMethod, Severity.Medium, Confidence.High, AbstractDisposeMessage);

			return Runner.CurrentRuleResult;
		}
開發者ID:alfredodev,項目名稱:mono-tools,代碼行數:53,代碼來源:TypesShouldBeDisposableBaseRule.cs

示例2: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule only apply to (non generated) delegates
			if (!type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			MethodDefinition invoke = type.GetMethod ("Invoke");
			// this happens for System.MulticastDelegate
			if (invoke == null)
				return RuleResult.DoesNotApply;

			if (!invoke.ReturnType.IsNamed ("System", "Void"))
				return RuleResult.Success;

			if (!invoke.HasParameters)
				return RuleResult.Success;

			IList<ParameterDefinition> pdc = invoke.Parameters;
			if (pdc.Count != 2)
				return RuleResult.Success;
			if (!pdc [0].ParameterType.IsNamed ("System", "Object"))
				return RuleResult.Success;
			if (!pdc [1].ParameterType.Inherits ("System", "EventArgs"))
				return RuleResult.Success;

			Runner.Report (type, Severity.Medium, Confidence.High);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:28,代碼來源:UseGenericEventHandlerRule.cs

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rules applies to types that overrides System.Object.Equals(object)
			MethodDefinition method = type.GetMethod (MethodSignatures.ToString);
			if ((method == null) || !method.HasBody)
				return RuleResult.DoesNotApply;

			// call base class to detect if the method can return null
			return CheckMethod (method);
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:10,代碼來源:ToStringReturnsNullRule.cs

示例4: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsEnum || type.IsInterface || type.IsDelegate ())
				return RuleResult.DoesNotApply;

			MethodDefinition equality = type.GetMethod (MethodSignatures.op_Equality);
			if ((equality == null) || type.HasMethod (MethodSignatures.Equals))
				return RuleResult.Success;
			
			Runner.Report (equality, Severity.High, Confidence.High);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:12,代碼來源:OverrideEqualsMethodRule.cs

示例5: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// handle System.Object (which can't call base class)
			if (type.BaseType == null)
				return RuleResult.DoesNotApply;

			MethodDefinition finalizer = type.GetMethod (MethodSignatures.Finalize);
			if (finalizer == null) // no finalizer found
				return RuleResult.DoesNotApply;

			if (IsBaseFinalizeCalled (finalizer))
				return RuleResult.Success;

			Runner.Report (finalizer, Severity.Critical, Confidence.Total);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:16,代碼來源:FinalizersShouldCallBaseClassFinalizerRule.cs

示例6: CheckCallingBaseMethod

		private void CheckCallingBaseMethod (TypeDefinition type, MethodSignature methodSignature)
		{
			MethodDefinition method = type.GetMethod (methodSignature);
			if (method == null)
				return; // Perhaps should report that doesn't exist the method (only with ctor).

			foreach (Instruction instruction in method.Body.Instructions) {
				if (instruction.OpCode.FlowControl == FlowControl.Call) {
					MethodReference operand = (MethodReference) instruction.Operand;
					if (methodSignature.Matches (operand) && type.Inherits (operand.DeclaringType.ToString ()))
						return;
				}
			}

			Runner.Report (method, Severity.High, Confidence.High, String.Format ("The method {0} isn't calling its base method.", method));
		}
開發者ID:TheRealDuckboy,項目名稱:mono-soc-2008,代碼行數:16,代碼來源:CallBaseMethodsOnISerializableTypesRule.cs

示例7: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rules applies to types that overrides System.Object.Equals(object)
			MethodDefinition method = type.GetMethod (MethodSignatures.Equals);
			if ((method == null) || !method.HasBody || method.IsStatic)
				return RuleResult.DoesNotApply;

			// rule applies

			// scan IL to see if null is checked and false returned
			if (CheckSequence (method.Body.Instructions [0], type))
				return RuleResult.Success;

			Runner.Report (method, Severity.Medium, Confidence.High);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:16,代碼來源:EqualShouldHandleNullArgRule.cs

示例8: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule only apply to (non generated) delegates
			if (!type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			MethodDefinition invoke = type.GetMethod ("Invoke");
			// this happens for System.MulticastDelegate
			if (invoke == null)
				return RuleResult.DoesNotApply;

			int n = 0;
			Severity severity = Severity.Medium;
			bool use_structure = false;
			// check parameters for 'ref', 'out', 'params'
			if (invoke.HasParameters) {
				IList<ParameterDefinition> pdc = invoke.Parameters;
				n = pdc.Count;
				// too many parameters to directly use Action/Func
				// so we lower severity and suggest grouping them
				if (n > ((type.Module.Runtime >= TargetRuntime.Net_4_0) ? 16 : 4)) {
					severity = Severity.Low;
					n = 1;
					use_structure = true;
				}

				// special cases not directly usable with Action/Func
				foreach (ParameterDefinition pd in pdc) {
					if (pd.IsOut || pd.ParameterType.IsByReference || pd.IsParams ())
						return RuleResult.Success;
				}
			}

			string msg = invoke.ReturnType.IsNamed ("System", "Void") ? ActionMessage [n] : FuncMessage [n];
			if (use_structure)
				msg += " and use a structure to hold all your parameters into <T>.";
			Runner.Report (type, severity, Confidence.High, msg);
			return Runner.CurrentRuleResult;
		}
開發者ID:alfredodev,項目名稱:mono-tools,代碼行數:39,代碼來源:AvoidDeclaringCustomDelegatesRule.cs

示例9: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsSerializable || !type.Implements ("System.Runtime.Serialization.ISerializable"))
				return RuleResult.DoesNotApply;
			
			MethodDefinition getObjectData = type.GetMethod (MethodSignatures.GetObjectData);
			if (getObjectData != null) {
				CheckUnusedFieldsIn (type, getObjectData);
				CheckExtensibilityFor (type, getObjectData);
			}
			return Runner.CurrentRuleResult;
		}
開發者ID:TheRealDuckboy,項目名稱:mono-soc-2008,代碼行數:12,代碼來源:ImplementISerializableCorrectlyRule.cs

示例10: CacheTypeGetStoreMethod

 private MethodDefinition CacheTypeGetStoreMethod(TypeDefinition cacheInterface, string cacheTypeStoreMethodName)
 {
     return cacheInterface.GetMethod(cacheTypeStoreMethodName, cacheInterface.Module.ImportType(typeof(void)),
         new[] { cacheInterface.Module.ImportType<string>(), cacheInterface.Module.ImportType<object>() });
 }
開發者ID:mdabbagh88,項目名稱:MethodCache,代碼行數:5,代碼來源:ModuleWeaver.cs

示例11: CacheTypeGetRetrieveMethod

 private MethodDefinition CacheTypeGetRetrieveMethod(TypeDefinition cacheType, string cacheTypeRetrieveMethodName)
 {
     return cacheType.GetMethod(cacheTypeRetrieveMethodName, new GenericParameter("T", cacheType),
         new[] { cacheType.Module.ImportType<string>() });
 }
開發者ID:mdabbagh88,項目名稱:MethodCache,代碼行數:5,代碼來源:ModuleWeaver.cs

示例12: CacheTypeGetRemoveMethod

 private MethodDefinition CacheTypeGetRemoveMethod(TypeDefinition cacheType, string cacheTypeRemoveMethodName)
 {
     return cacheType.GetMethod(cacheTypeRemoveMethodName, ModuleDefinition.TypeSystem.Void,
         new[] { cacheType.Module.ImportType<string>() });
 }
開發者ID:mdabbagh88,項目名稱:MethodCache,代碼行數:5,代碼來源:ModuleWeaver.cs

示例13: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.HasFields || type.IsEnum)
				return RuleResult.DoesNotApply;

			Log.WriteLine (this);
			Log.WriteLine (this, "----------------------------------");
			Log.WriteLine (this, type.FullName);
						
			FieldDefinition field = FindIntPtr (type);
			if (field != null) {
				Confidence confidence = Confidence.Low;
				
				MethodDefinition finalizer = type.GetMethod (MethodSignatures.Finalize);
				if (finalizer != null) 
					confidence = (Confidence) ((int) confidence - 1);	// lower numbers have higher confidence

				if (type.Implements ("System.IDisposable"))
					confidence = (Confidence) ((int) confidence - 1);

				Log.WriteLine (this, "'{0}' is an IntPtr.", field.Name);
				Runner.Report (field, Severity.Medium, confidence);
			}
						
			return Runner.CurrentRuleResult;
		}
開發者ID:nolanlum,項目名稱:mono-tools,代碼行數:26,代碼來源:PreferSafeHandleRule.cs

示例14: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsSerializable || !type.Implements ("System.Runtime.Serialization", "ISerializable"))
				return RuleResult.DoesNotApply;

			MethodDefinition getObjectData = type.GetMethod (MethodSignatures.GetObjectData);
			if (getObjectData == null) {
				// no GetObjectData means that the type's ancestor does the job but 
				// are we introducing new instance fields that need to be serialized ?
				if (!type.HasFields)
					return RuleResult.Success;
				// there are some, but they could be static
				foreach (FieldDefinition field in type.Fields) {
					if (!field.IsStatic)
						Runner.Report (field, Severity.Medium, Confidence.High);
				}
			} else {
				if (type.HasFields)
					CheckUnusedFieldsIn (type, getObjectData);

				if (!type.IsSealed && getObjectData.IsFinal) {
					string msg = "Either seal this type or change GetObjectData method to be virtual";
					Runner.Report (getObjectData, Severity.High, Confidence.Total, msg);
				}
			}
			return Runner.CurrentRuleResult;
		}
開發者ID:col42dev,項目名稱:mono-tools,代碼行數:27,代碼來源:ImplementISerializableCorrectlyRule.cs

示例15: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule does not apply to enums, delegates and to generated code
			if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// rule applies only if the type overrides Equals(object)
			if (!type.HasMethod (MethodSignatures.Equals))
				return RuleResult.DoesNotApply;

			// if so then the type should also implement Equals(type) since this avoid a cast 
			// operation (for reference types) and also boxing (for value types).

			// we suggest to implement IEquatable<T> if
			// * the assembly targets the 2.0 (or later) runtime
			// * and it does not already implement it
			if (type.Module.Runtime >= TargetRuntime.Net_2_0) {
				if (!type.Implements ("System", "IEquatable`1")) {
					Runner.Report (type, Severity.Medium, Confidence.Total, "Implement System.IEquatable<T>");
				}
				return Runner.CurrentRuleResult;
			}

			parameters [0] = type.GetFullName ();
			if (type.GetMethod (MethodAttributes.Public, "Equals", "System.Boolean", parameters) != null)
				return RuleResult.Success;

			// we consider this a step more severe for value types since it will need 
			// boxing/unboxing with Equals(object)
			Severity severity = type.IsValueType ? Severity.Medium : Severity.Low;
			string msg = String.Format (CultureInfo.InvariantCulture, "Implement 'bool Equals({0})'", type.Name);
			Runner.Report (type, severity, Confidence.High, msg);
			return RuleResult.Failure;
		}
開發者ID:col42dev,項目名稱:mono-tools,代碼行數:34,代碼來源:ImplementEqualsTypeRule.cs


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