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


C# MethodDefinition.IsOverride方法代碼示例

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


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

示例1: CheckMethod

		public RuleResult CheckMethod (MethodDefinition method)
		{
			//does not apply if method has no parameter, is a property, or a p/invoke
			if (!method.HasParameters || method.IsProperty () || method.IsPInvokeImpl)
				return RuleResult.DoesNotApply;

			//if this is a constructor or override, the method name is dependent
			if (method.IsConstructor || method.IsOverride ())
				return RuleResult.DoesNotApply;

			ParameterDefinition p0 = method.Parameters [0];
			string name = p0.ParameterType.Name;

			//param is out/ref, it is already not obvious (there is a rule for that)
			if (p0.IsOut || p0.IsRef ())
				return RuleResult.DoesNotApply;

			string method_name = method.Name;
			if (name.Length == 1 || method_name.Length <= name.Length)
				return RuleResult.DoesNotApply;
			if ((method_name.Length - name.Length) < 4 && IsVaguePrefix (method_name)) //suggestion would be too vague anyway (Get/Set/Is)
				return RuleResult.DoesNotApply;
			if (!char.IsUpper (name [0])) //non-compliant naming, cannot go further (PascalWords needed)
				return RuleResult.DoesNotApply;

			//if the method return the parameter type it is most likely clearer to have it in the name
			if (method.ReturnType == p0.ParameterType)
				return RuleResult.Success;

			//if starting with name it is most likely on purpose
			if (method_name.StartsWith (name, StringComparison.Ordinal))
				return RuleResult.Success;

			int pos = method_name.LastIndexOf (name);
			if (-1 == pos)
				return RuleResult.Success;

			Confidence confidence = Confidence.Normal;
			if (pos >= method_name.Length - name.Length) //suffix, most common and most verbose case
				confidence = Confidence.High;
			else if (!char.IsUpper (method_name [pos + name.Length])) //not the end of a 'PascalWord'
				return RuleResult.Success;

			//if IgnoreAlienNamespaces is True, then check if parameter type is from one of the analyzed namespaces
			if (IgnoreAlienNamespaces && IsTypeFromAlienNamespace (p0.ParameterType))
				return RuleResult.Success; //ignored/out-of-reach, so this is a success

			//main goal is to keep the API as simple as possible so this is more severe for visible methods
			Severity severity = method.IsVisible () ? Severity.Medium : Severity.Low;

			string suggestion = GetSuggestionMethodName (method, name, pos);
			string msg;
			if (method.IsStatic) { //we already have a rule that checks if the method should be static
				string memberKind = GetSuggestionMemberKind (method);
				msg = String.Format ("Consider renaming method to '{2}', or extracting method to type '{0}' as {1} '{2}', or making an extension method of that type.", 
					p0.ParameterType, memberKind, suggestion);
			} else {
				msg = String.Format ("Consider renaming method to '{0}'.", suggestion);
			}

			Runner.Report (method, severity, confidence, msg);
			return RuleResult.Failure;
		}
開發者ID:nolanlum,項目名稱:mono-tools,代碼行數:63,代碼來源:AvoidRedundancyInMethodNameRule.cs


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