I am trying to create a replacement T4 template for the MVC5 Controller. I have everything working except for one issue.
I need to generate code for each property in the Model, and looping through ModelMetadata.Properties
is actually really easy. However it is not an array of PropertyInfo
s. Rather it is an array of PropertyMetadata
which doesn't seem to have any information about whether a property is required or not or if its type is nullable or not. So properties in your model of type int
and int?
both show up as type System.Int32
.
Furthermore there is no way to get a list of PropertyInfo
s being that you can't really get a Type
Object for the model which you are scaffolding, being that only the short type name is passed to the template.
In summation: Is there any way to know in a T4 template if a property is nullable?