Hi,
I'm creating new rule in fxcop which is variable naming convention (Im using VS 2005). actually i have to access local variable name. but the problem is when my code working its check only first local variable name... then loop not working. i have to access all local variable name continuosly..
public override ProblemCollection Check(Member member)
{
Method method = member as Method;
if (method == null)
{
return base.Problems;
}
LocalList locals = null;
if (method.Instructions == null || method.Instructions.Length == 0)
{
return base.Problems;
}
if (method.Instructions.Length > 0)
{
locals = method.Instructions[0].Value as LocalList;
}
//for (int x = 0; x < method.Instructions.Length ; x++)
//{
// Instruction instruction = method.Instructions[i];
//list = method.Instructions[x].Value as LocalList;
//{
if (locals != null)
{
// return base.Problems;
//}
//for (int i = 1; i < locals.Length; i++)
//{
//base.Problems.Add(new Problem(GetNamedResolution("Local", "[" + list + "]")));
//return Problems;
for (int i = 0; i < locals.Length; i++) //if this loop work properly then Ok
{
Local local = locals[i];
string name = local.Name.Name; //get local variable name
if (name == null)
{
return base.Problems;
//return null value
}
/* // Have to do what want
Boolean lowerFlag = false;
for (int j = 0; j < name.Length; j++)
{
//base.Problems.Add(new Problem(GetNamedResolution("Local", "[" + name.Length + "]")));
//return Problems;
if (j % 3 == 0)
{
lowerFlag = !lowerFlag; //negate the flag, when condition true
}
if (lowerFlag)
{
if (Char.IsUpper(name[j])) //check the letter which is lower or uppercase
{
base.Problems.Add(new Problem(GetNamedResolution("Local", "[" + name + "]"))); //if the variable name is not a correct format add problem
return Problems;
}
}
else
{
if (Char.IsLower(name[j]))
{
base.Problems.Add(new Problem(GetNamedResolution("Local", "[" + name + "]"))); //if the variable name is not a correct format add problem
return Problems;
}
}
}
if (RuleUtilities.IsCompilerGenerated(local))
continue;
// return base.Problems;
}
}
*/
return base.Problems;
}
this is my code.. plz any one help me to check all local variable name.