T4 default template parameters -
i want pass in default template parameters of context controller t4 template codegenerator function new extension such:
<#@ parameter type="system.string" name="controllername" #> <#@ parameter type="system.string" name="controllerrootname" #> <#@ parameter type="system.string" name="namespace" #> <#@ parameter type="system.string" name="areaname" #> <#@ parameter type="system.string" name="contexttypename" #> <#@ parameter type="system.string" name="modeltypename" #> <#@ parameter type="system.string" name="modelvariable" #> <#@ parameter type="microsoft.aspnet.scaffolding.core.metadata.modelmetadata" name="modelmetadata" #> <#@ parameter type="system.string" name="entitysetvariable" #> <#@ parameter type="system.boolean" name="useasync" #> <#@ parameter type="system.boolean" name="isoverpostingprotectionrequired" #> <#@ parameter type="system.string" name="bindattributeincludetext" #> <#@ parameter type="system.string" name ="overpostingwarningmessage" #> <#@ parameter type="system.collections.generic.hashset<system.string>" name="requirednamespaces" #>
these passed in through scaffolding process microsoft's mvc dll automatically since overriding scaffolding process own want pass them in myself in here:
public override void generatecode() { // selected code type var codetype = _viewmodel.selectedmodeltype.codetype; // add custom scaffolding item t4 template. this.addfilefromtemplate(context.activeproject, "mvcbootstrapservertable", "customtexttemplate", getparameters(), //to provide parameters here! skipifexists: false); }
is there easy way this?
you can process template using text templating service. sample code, please refer to:
https://msdn.microsoft.com/en-us/library/gg586944.aspx#anchor_1
if want parameters t4 template, need use itexttemplatingenginehost.resolveparametervalue method. before use method, need add hostspecific="true" attribute template element.
sample code, code refer to:
Comments
Post a Comment