tags:

views:

40

answers:

2

Similar to my previous question about determining if all classes in a given namespace are serializable, is there a way I can make assertions about all public properties on all classes in a given namespace? I'd like to determine that they are cased properly (eg. start with a capital char) and are all marked as virtual/overridable; is there a way I can do this using reflection?

+3  A: 

Have you tried using FxCop - this is a tool that integrates with Visual Studio and enforces coding styles.

Marco
Good answer, but would also add that Resharper has quite a few more static analysis tools for this sort of thing as well to add to your reportoire.
Kirk Woll
Thanks Marco, I will have a look at FxCop
DanP
+1  A: 

Coding standards like that are a useless way of enforcing better quality code - they're a pathetic alternative to documentation and example. I mean, why not prefix all properties with 'prp' to make it really clear.

Still, if you must have such rules, you want StyleCop. Its a style checking tool that integrates with Visual Studio or can be run stand-alone (with MSBuild) against your code.

Or you can use ReSharper that comes with its own style rules (conflicting with the StyleCop defaults, of course).

gbjbaanb
Well, I can't comment on the casing issue (I guess it's more of a pet peeve) - but ensuring everything is marked as virtual is pretty important when using nhibernate proxies..so I wouldn't really call this 'useless'
DanP