I'm in the process of porting my previous MVC4.5 T4 Scaffolding templates to be used in VS2013. All is going well, luckily the logic behind it has not changed much, but lots of namespaces, objects and properties were renamed just like I expected.
However, the tricky bit is PropertyInfo
. It seems that it's no longer possible to use PropertyInfo
, since the new ModelMetadata
object only contains PropertyMetadata
. Since PropertyMetadata
has no GetCustomAttributes()
method or similar, I'm stuck on upgrading the following snippet:
<#+
string SearchableBy(PropertyInfo property) {
foreach (object attribute in property.GetCustomAttributes(true))
{
var searchable = attribute as SearchableAttribute;
if (searchable != null)
{
return searchable.By == "" ? GetValueExpressionSuffix(property) :
searchable.By;
}
}
return null;
}
#>
- Is it possible to get a
PropertyInfo
object in a T4 Controller / View Scaffolder somehow? - If not, what is the new / correct way of accessing Custom Annotations?
ModelMetadata
seems to be useless regarding this
PS:
This question can be considered as a sub-question of my previous one
If you are interested in how Custom Annotations can be accessed in VS2012, see this one