Is there a product/project that would allow you to define conventions for say an MVC Project to statically check for naming conventions like Controller being appended on the end of classes that inherit from controller and/or enforce a certain method signature when decorating a method with an attribute.
I am basically looking for a way to kind of set up some guard rails for new developers coming onto our team where we have a clear set of conventions some of which are used to wire things up dynamically through reflection. Seeing that this reflection wire-up would fail because of an incompatible signature would be a huge boon to our ramp up process.
Key Features Needed:
Any input suggestions are appreciated although I ask that you only respond if you know that these features are supported.
Personal experience here, but I always write tests for things like this. I parse through my assemblies and make sure things are following conventions. For a couple of specific examples, I check WCF request/response objects to make sure they aren't sending "DTO" over the wire and they were all in a consistent XML namespace.
Here's a quick example that makes sure that all service methods return something that inherits a BaseResponse object:
[Test]
public void All_IMyService_methods_should_return_a_BaseResponse()
{
var methods = typeof (IMyService).GetMethods();
foreach (var methodInfo in methods)
Assert.That(typeof (BaseResponse).IsAssignableFrom(methodInfo.ReturnType), "Service Method " + methodInfo.Name + " does not return a BaseResponse");
}
I'm sure someone will have something better/more automated, but this worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With