当前位置: 首页>>代码示例>>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;未经允许,请勿转载。