2

I am using T4Scaffolding, and tried to create a custom Scaffold template. It's not asp.net project, not MVC.

My user class :

   public class User
   {
     public int Id {get;set;}
     public string Name {get; set;}
   }

in the .cs.t4 file , I need to get the user properties ,I tried to use:

var propertyInfos = typeof(Model.).GetProperties(BindingFlags.Public |
                                              BindingFlags.Static);
foreach (PropertyInfo propertyInfo in propertyInfos)

...

but It did not work, I know in asp.net mvc I can use

foreach (ModelProperty property in GetModelProperties(Model.ViewDataType, false))

What's the correct method in asp.net ???

Thanks for any comment ...

Alfero Chingono
  • 2,663
  • 3
  • 33
  • 54
nicholapei
  • 53
  • 5

1 Answers1

1

Assuming you are passing a model with property ViewDataType you can get the properties of the type using the following code:

var modelType = (EnvDTE.CodeType) Model.ViewDataType;
var modelProperties = modelType.VisibleMembers().OfType<EnvDTE.CodeProperty>();

Hope that helps.

Alfero Chingono
  • 2,663
  • 3
  • 33
  • 54