0

I want a template which somehow accepts a class_name property and creates a class, name of which is the value of class_name

Ideally, I should be able to execute my template inside MyClass.cs containing definition for public partial class MyClass, and that would set class_name to MyClass

This template

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>

public partial class <#=class_name #>
{

}

produces an error:

Error   1   Compiling transformation: The name 'class_name' does not exist in the current context

How do I put a definition of a class_name into it?

user2136963
  • 2,526
  • 3
  • 22
  • 41

1 Answers1

0

You can define class_name as like this:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<# var class_name = "MyClass"; #>

public partial class <#=class_name #>
{

}
temUser
  • 142
  • 8
  • this is not really passing a parameter, it's just setting a local variable in the context of this template – Frank Sep 09 '15 at 17:38