You can use PostSharp or other AOP framework to create aspect which will apply ExcludeFromCodeCoverageAttribute
to specified types or namespaces:
[Serializable]
[AttributeUsage(AttributeTargets.Assembly)]
[MulticastAttributeUsage(MulticastTargets.Class | MulticastTargets.Struct)]
[ProvideAspectRole(StandardRoles.PerformanceInstrumentation)]
public sealed class DisableCoverageAttribute : TypeLevelAspect, IAspectProvider
{
public IEnumerable<AspectInstance> ProvideAspects(object targetElement)
{
Type disabledType = (Type)targetElement;
var introducedExclusion = new CustomAttributeIntroductionAspect(
new ObjectConstruction(typeof (ExcludeFromCodeCoverageAttribute)));
return new[] {new AspectInstance(disabledType, introducedExclusion)};
}
}
Then just apply this aspect to assembly and provide namespace which you want to exclude. During compilation PostSharp will add ExcludeFromCodeCoverageAttribute
to all classes in My.AutogeneratedCode
namespace:
[assembly: DisableCoverage(AttributeTargetTypes="My.AutogeneratedCode.*")]
Sample code and explanations you can find here.
partial
(like, altering generator in some way)? – Indifferentism