我目前正在从事一个项目,我需要您的帮助。
以下代码应检查变量名(如果前缀为“ l”)。
我还创建了一个.XML文件,其中包含规则。它叫做MCRULES.xml。
实施我的自定义书面规则的下一步是什么?我在互联网上找不到任何文章或博客文章,这对我有帮助。 谢谢您的帮助
public abstract class CheckLocalVariablePrefix : BaseIntrospectionRule
{
protected CheckLocalVariablePrefix(string Rules)
: base("CheckLocalVariablePrefix", "MCRULESET.MCRULESET",
typeof(CheckLocalVariablePrefix).Assembly)
{ }
internal sealed class EnforceHungarianNotation : CheckLocalVariablePrefix
{
public EnforceHungarianNotation() : base ("EnforceHungarianNotation")
{ }
}
public override TargetVisibilities TargetVisibility
{
get
{
return TargetVisibilities.NotExternallyVisible;
}
}
public override ProblemCollection Check(Member member)
{
if (!(member.DeclaringType is ClassNode))
return this.Problems;
Field field = member as Field;
if (field == null)
return null;
if (field.IsStatic)
{
CheckFieldName(field, l_staticFieldPrefix);
}
return Problems;
}
public const string l_staticFieldPrefix = "l";
public void CheckFieldName(Field field, string expectedPrefix)
{
if(!field.Name.Name.StartsWith(expectedPrefix, StringComparison.Ordinal))
{
Resolution resolution = GetResolution(field, expectedPrefix);
Problem problem = new Problem(resolution);
Problems.Add(problem);
}
}
}
}