T4 templates: any way to make ToStringWithCulture() convert null to string.Empty instead of throwing exception?

When I provide an object to a T4 template with nullable properties, unless I explicitly write <#= obj.Property ?? string.Empty #> the ToStringWithCulture(object objectToConvert) method that is generated for the template throws an ArgumentNullException. Is there any neat or elegant way to override this behavior so that I don’t have to pepper null coalescing all over my templates?

Source: .net

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.