XmlCodeGeneartor
Introduce
C#/VB.NET code can be generated by XML + XSLT.
What's New
v1.0: Initial checked-in.
v1.1: Add support for Visual Studio 2015
v1.2: Add support for Visual Studio 2017
v1.3: Add support for Visual Studio 2019
v1.4: Add support for Visual Studio 2022 (Preview)
v1.6: Only support for Visual Studio 2022
How to use
- Create your own XML file in your project. For example,
<IFs>
<DOIT condition="1" />
<DOIT condition="2" />
<DOIT condition="3" />
<DOIT condition="4" />
<DOIT condition="5" />
</IFs>
- Create your own XSLT file in the same directory of XML. You can write XSLT to produce source codes on XML. For example,
<?xml version="1.0" encoding="UTF-8" ?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<output method="text" encoding="utf-8" indent="yes"></output>
<template match="IFs">
using System;
using System.Collections.Generic;
using System.Text;
namespace macroTest
{
public partial class Test
{
private void DoIt(int condition)
{
<apply-templates select="//DOIT"></apply-templates>
}
}
}
</template>
<template match="//DOIT">
if (condition == <value-of select="@condition"/>)
{
funcName_<value-of select="@condition"/>();
}
</template>
</stylesheet>
- Finally, select Xml file and type 'XmlCodeGenerator' on 'Custom Tool' in properties.
- Now, whenever you save xml file, [xml-filename].cs file will be generated by combining with XSLT. For example,
using System;
using System.Collections.Generic;
using System.Text;
namespace macroTest
{
public partial class Test
{
private void DoIt(int condition)
{
if (condition == 1)
{
funcName_1();
}
// .........[repeat]..........
}
}
}
Source Code
Project site: https://github.com/stjeong/XmlCodeGenerator