Avoiding Properties.Settings and Properties.Resources in Whidbey
Heya, I'm creating a custom rule for private class members variables. So far I'm using this code:
public
overrideProblemCollection Check(TypeNode type)
...
foreach (Member memberin type.Members)
...
if (member.IsPrivate && member.NodeType ==NodeType.Field)
// Do checkNow, the problem here is that I get a lot of attributes which are in the Properties.Settings and Properties.Resources classes/files. Is there a way to check if the TypeNode is one of these classes? Now I use:
if
(!type.FullName.EndsWith(".Properties.Settings"))But I'm not too happy about it...
Cheers
/Chris
Hi Chris,
Both these classes are decorated with the GeneratedCodeAttribute. This attribute has a tool name and a version number.
You could write a helper that checks for the existence of this attribute and check the toolname to be "System.Resources.Tools.StronglyTypedResourceBuilder" or "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator"
You don't want to ignore code marked this attribute all together, as ASP.NET and several other tools mark their generated code with this attribute as well, this generated code can contain chunks of user code inside it on which you probably do want to fire your rules.
Regards,
Jeffrey