.net - T4 templates: any way to make ToStringWithCulture() convert null to string.Empty instead of throwing exception? -
when provide object t4 template nullable properties, unless explicitly write <#= obj.property ?? string.empty #> tostringwithculture(object objecttoconvert) method generated template throws argumentnullexception if property null. there neat or elegant way override behavior don't have pepper null coalescing on templates?
mnaoumov's solution. change base template class
public string tostringwithculture(object objecttoconvert) { if (objecttoconvert == null) return ""; ... }
Comments
Post a Comment