This project is read-only.

How to check the type of variables

Apr 23, 2012 at 9:23 AM

Hi !

I've been struggling quite long with an issue to create a rule that check the type of variable to ensure that the variable is

properly defined like: string strMyString. I would like to avoid a situation where the string is defined

for example by accident like: string chrMyChar. I just like to know how to catch the type of variable.

I appreciate your help.

Thanks in advance


May 16, 2012 at 10:13 AM


As StyleCop works only with parsed source - your task is impossible.
Just imagine you would use "var" instead of "string" for local variables.

In order to determine type, the code should be compiled, which is not the StyleCop's responsibility.

Best regards,
Oleg Shuruev

May 16, 2012 at 10:53 AM

Yep - as Oleg said. This would need to be in the compiled checker - FxCop

May 16, 2012 at 8:19 PM
Thanks for the reply.

Actually I found another solution which base on using tokens and variable name combinations.


Lähettäjä: andyr []
Lähetetty: 16. toukokuuta 2012 12:53
Vastaanottaja: Pertti Saviranta
Aihe: Re: How to check the type of variables [stylecop:353184]

From: andyr

Yep - as Oleg said. This would need to be in the compiled checker - FxCop

Read the full discussion online<>.

To add a post to this discussion, reply to this email ([email removed]<mailto:[email removed]?subject=[stylecop:353184]>)

To start a new discussion for this project, email [email removed]<mailto:[email removed]>

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe<> on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at