2012-06-25 2 views
6

자동 생성 클래스를 ExcludeFromCodeCoverage로 표시 할 수 있습니까? 나는 다른 영역에서 그 속성을 사용하고 있으며 훌륭하게 작동합니다. 그러나 자동 생성 된 사람의 코드를 열고 클래스를 ExcludeFromCodeCoverage로 표시하면 해당 클래스를 다시 생성하면 완전히 덮어 쓰게됩니다.ExcludeFromCodeCoverage 자동 생성 코드 제외

dbml의 코드 뒤에 부분 클래스를 만들고이 속성을 적용 할 수 있지만 많은 부분 클래스를 만들 수 있습니다.

[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)}; 
    } 
} 

가 그럼 그냥 조립이 측면을 적용하고 제외 할 네임 스페이스를 제공

+0

자동 생성 클래스를 '부분적'으로 만들 수 있습니까 (어떤 방식 으로든 생성기를 변경)? –

답변

4

당신은 지정된 유형 또는 네임 스페이스에 ExcludeFromCodeCoverageAttribute를 적용 할 측면을 만들 PostSharp 또는 다른 AOP 프레임 워크를 사용할 수 있습니다. 컴파일하는 동안 PostSharp는 My.AutogeneratedCode 네임 스페이스의 모든 클래스에 ExcludeFromCodeCoverageAttribute를 추가합니다 :

[assembly: DisableCoverage(AttributeTargetTypes="My.AutogeneratedCode.*")] 

예제 코드와 설명은 당신이 here을 찾을 수 있습니다.

관련 문제