I have seen the [DebuggerNonUserCode]
and [ExcludeFromCodeCoverage]
attributes in resources and other SO questions about exlcuding code from coverage statistics, and wanted to know if it was possible to automatically add this attribute to the classes in the code generated by the Entity Framework using .NET 4.0.
Also would it need to be class level or could it be on the diagram.Designer.cs
level, needing one attribute for all code generated by that diagram?
Since partial classes (which Entity Framework creates) merge attributes, extended functionality in other partial classes are also excluded if the attribute is class level in the template, it will have to be applied at the method level.
The best way that I've found to do this is using T4 (as recommended in @Craig Stuntz's answer) to:
using System.Diagnostics.CodeAnalysis;
at the top of the fileThen apply [ExcludeFromCodeCoverage]
to getters, setters and Factory methods by searching for:
#>get
#>set
Template_FactoryMethodComment
and placing them in the appropriate place.
This was made a lot easier using Tangible's T4 editor Extension for VS.
This is my first attempt and it seems to work, "your milage may vary", so complete a test run to make sure everything's working as necessary.
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