Quantcast
Channel: Off-Topic Posts (Do Not Post Here) forum
Viewing all articles
Browse latest Browse all 14169

as.net mvc 5 t4 scaffolding

$
0
0

I am using vs2013 and T4 Templates to generate the Views (Create, Edit , List) what I need is to retrieve the Maxlength attribute .

Create.cs.t4 the file I have the following code ( snippet )

<#
foreach (PropertyMetadata property in ModelMetadata.Properties) {
  string inputlength = MaxLength(property);    
#><#= property.PropertyName #> Maxlength is <#= inputlength  #><# } #>



string MaxLength(PropertyInfo property) {
    var stringLength = property.GetCustomAttributes(typeof(StringLengthAttribute), false);
    if (stringLength != null && stringLength.Length > 0) {
        return ((StringLengthAttribute)stringLength[0]).MaximumLength.ToString();
    } else {
        return "0";
    }
}

I know I'm going PropertyMetadata instead of PropertyInfo , but this was the closest I could get , but it does not return me anything ..

Do not know if converting PropertyMetadata > PropertyInfo work , but do not know it .

My goal is to look at the properties that has MaxLength = 1

Note: the structure of templates is different from VS2013 VS2012 , so I can not understand .


Isco Sistemas José Luiz Borges


Viewing all articles
Browse latest Browse all 14169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>