Alex Rivera | Logout

C# Code Analysis CA1822 Warning - Why?

Asked 2010-02-09T14:31:19.497
46

I have the method shown below which is generating a CA1822 Code Analysis warning. CA1822 says this:

"The 'this parameter (or 'Me' in Visual Basic) of 'ImportForm.ProcessFile(StreamReader)' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this/Me' in the method body or at least one property accessor, if appropriate."

Can anyone tell me why I am getting this warning, since the 'reader' parameter is in fact being used?

private void ProcessFile(StreamReader reader)
{
   string[] lines;

   lines = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

   ParseFile.IVAFile(lines);
}
Edit
Report

2 Answers

5

The warning occurs because you don't use any member variables of that class in that method. E.g.

this.m_anyVariable = anyValue;

Therefore you can/should mark that method as static.

answered 2010-02-09T14:35:04.360
2

I think it is trying to tell you that this method can be made static.

The only thing this method needs to access is "reader", but nothing from the class instance to which it belongs ("this"). In which case, you can safely make it static.

answered 2010-02-09T14:34:03.827

Your Answer