|
using System;
using System.Diagnostics;
using System.Reflection;
using Microsoft.FxCop.Sdk;
using Microsoft.FxCop.Sdk.Introspection;
using Microsoft.Cci;
using System.Text.RegularExpressions;
public class stringwithStr:BaseIntrospectionRule
{
public stringwithStr():
base(@"stringwithStr", "DummyProj.DLADesignRules",
typeof(stringwithStr).Assembly)
{
//
// TODO: Add constructor logic here
//
}
public override ProblemCollection Check(Member member)
{
// Member Variables
// Look for str in local variable names
Method method = member as Method;
if (method == null)
{
return null;
}
LocalList list = null;
if (method.Instructions.Length > 0)
{
list = method.Instructions[0].Value as LocalList;
}
if (list != null)
{
for (int i = 0; i < list.Length; i++)
{
Local local = list[i];
if (local.Type == SystemTypes.String)
{
if (ContainsStr(local.Name.Name))
{
// Found a local containing a numeric in the name
base.Problems.Add(new Problem(base.GetResolution(local.Name.Name), local.Name.Name));
}
}
}
}
return base.Problems;
}
private bool ContainsStr(string variableName)
{
//NOTE:
//Use regexp instaed of substring, which will be more faster.
if (!(variableName.Substring(0, 3).ToString().Trim() == "str"))
{
return true;
}
else
{
return false;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.