내 edmx에서 클래스를 빌드하고 파생 클래스를 제외하고 원활하게 작동하는 수정 된 T4 템플릿이 있습니다.조건부로 선언에서 기본 클래스를 설정하는 방법
Product : BaseItem // works fine as do all top level classes
TranslatedProduct : Product : BaseItem // dang
은 내가 조건부 무시하도록 T4 템플릿을 설정할 수있는 방법과에 대한 혼란 스러워요 : - :
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#> : BaseItem
BASEITEM를 파생 클래스의 경우 즉, 예를 들어
TranslatedProduct : Product
내 머리 속에 나는 그것을 상상했다. -
if(code.Escape(entity.BaseType).Equals(string.empty)
{
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#> : BaseItem
}
else
{
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
}
하지만 구문 오류가있어서 다른 사람이 시도했는지 확인하고 싶습니다. 올바른 경로에 있다면
감사 답장 - 그건 괜찮아요,하지만 기본 동작은 이후입니다. 즉. 모든 클래스가 파생 클래스가 아닌 경우 BaseItem을 상속합니다. 이 코드 줄은 T4의 기본 동작입니다. – MikeW
더 자세히 설명하겠습니다.이 기본 BaseClass는 T4 생성 클래스와 매우 다르기 때문에 모델의 일부가 아닙니다. 따라서 최선의 해결책은 아니지만 쉬운 해결 방법 – MikeW
@MikeW : 따라서 '<#= #>'태그 사이에있는 T4 템플릿 부분은 간단한 C# 표현식입니다.'entity.BaseType'이 최상위 유형에 대해 평가하는 것을 알고 있습니까? 예 : 'null'입니까? –