Created
March 11, 2023 09:29
-
-
Save vlapenkov/065271f641d323159bb8c88ad6b2c096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template debug="false" hostspecific="false" language="C#" #> | |
<#@ assembly name="System.Core" #> | |
<#@ assembly name="System.Xml" #> | |
<#@ import namespace="System.Linq" #> | |
<#@ import namespace="System.Text" #> | |
<#@ import namespace="System.IO" #> | |
<#@ import namespace="System.Xml" #> | |
<#@ import namespace="System.Collections.Generic" #> | |
<#@ output extension=".cs" #> | |
// Данный файл генерирует класс SampleDto в TextTemplate1.cs файле | |
namespace ConsoleApp1 { | |
class SampleDto { | |
<# | |
var directory = @"C:\Users\vlape\source\repos\My.WinFormsApp1\My.WinFormsApp1"; | |
string xmlFilename = "Constants.xml"; | |
var path=Path.Combine(directory, xmlFilename); | |
XmlDocument xmlDoc = new XmlDocument(); | |
xmlDoc.Load(path); | |
foreach (var xmlNode in xmlDoc.ChildNodes[1].ChildNodes) { | |
string nameAttr = ((System.Xml.XmlElement)xmlNode).Attributes[0].Value; | |
string typeAttr = ((System.Xml.XmlElement)xmlNode).Attributes[1].Value; | |
string defaultValue = ((System.Xml.XmlElement)xmlNode).Attributes[2].Value; | |
#> | |
public <#= typeAttr #> <#= nameAttr #> {set; get;} = <#= defaultValue #>; | |
<# | |
} | |
#> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment