Reputation: 885
I have the following code in VB.NET
<#@ template debug="false" hostspecific="true" language="VB" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ output extension=".vb" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#
Dim inputFile= Path.ChangeExtension(Host.TemplateFile, "resx")
Dim xml As XElement = XElement.Load(Host.ResolvePath(inputFile))
Dim dataElements = xml.Elements().Where(Function(x) x.Name = "data")
Dim resourceTypeName = Path.GetFileNameWithoutExtension(inputFile)
#>
' This file is autogenerated
Public Class <#= resourceTypeName #>Constants
<# For Each d as XElement in dataElements #>
Public Const <#= d.@name #> As String = "<#= d.@name #>"
<# Next #>
End Class
I made a rewrite to C#. But i forgot something i think. Because i get an error ( ErrorGeneratingOutput )
<#@ template language="C#" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ output extension=".cs" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#
dynamic inputFile = Path.ChangeExtension(Host.TemplateFile, "resx");
XElement xml = XElement.Load(Host.ResolvePath(inputFile));
dynamic dataElements = xml.Elements().Where(x => x.Name == "data");
dynamic resourceTypeName = Path.GetFileNameWithoutExtension(inputFile);
#>
'This file is autogenerated
public class <# resourceTypeName #>Contstants
{
foreach (XElement d in dataElements) {
public Const String <#= d.@name #> = "<#= d.@name #>";
}
}
Somebody who can help me?
Update
I get some error on line 21 , this is the line
public class <# resourceTypeName #>Contstants
He give as error Compiling transformation: ; expected
Upvotes: 0
Views: 730
Reputation: 174279
Change 'This file is autogenerated
to //This file is autogenerated
.
Additionally, the foreach in the first version is a TT foreach not a VB one. Try this:
<# foreach (XElement d in dataElements) {#>
public const string <#= d.@name #> = "<#= d.@name #>";
<# } #>
Upvotes: 1