using VS2015, I am modifying the default t4 template for controller&views scaffolding. In this template I have direct access to the properties of the related model, but I need to also get the properties of a class that resides in the same project as the templates. I have added this at the top of the t4 template:
<#@ Assembly Name="C:\_code\MyProject\obj\Debug\MyProject.dll" #>
<#@ import namespace="MyProject.Models.Filtros" #>
and then I can get the properties of the class with
var listPropsFiltro = typeof(FiltroClientes).GetProperties().Select(f => f.Name).ToList();
This is working ok.
now my problem is, instead of writing the name of the class in code (like here, FiltroClientes), I have to construct it for example with something like
var classname = "Filtro" + ControllerRootName;
and of course this is not working:
var listPropsFiltro = typeof(classname).GetProperties().Select(f => f.Name).ToList();
I have found some posts about similar situations both here in stackexchange and other places, but none of the solution are working for me... so what should be the proper way of doing this?
You could use:
Type classType = Assembly.GetType(classname)and than call
var listPropsFiltro = classType.GetProperties().Select(f => f.Name).ToList();You can try to get your current assembly with:
Assembly.GetExecutingAssembly()If your executing Assembly does not equals the project Assembly containing your classes you could do something like this.
Assembly project Assembly = Assembly.LoadFrom(pathToProject)See msdn.