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

savirpe

Developer
May 16, 2012 at 10:13 AM

Hi,

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

Coordinator
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.

-savirpe

________________________________
Lähettäjä: andyr [notifications@codeplex.com]
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<http://stylecop.codeplex.com/discussions/353184#post837106>.

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<https://stylecop.codeplex.com/discussions/353184/unsubscribe/> on CodePlex.com.

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