T4 template processing task added

This commit is contained in:
Mike
2019-02-11 22:42:31 -08:00
parent 3952da3a60
commit 4e5f94d27a
7 changed files with 215 additions and 3 deletions

View File

@@ -0,0 +1,40 @@
<#@ template language="C#" hostSpecific="true" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<# var enumTypes = new string[] { "System.StringSplitOptions" }; #>
using System.Collections.Generic;
namespace Nez
{
<#
// loop through all of our enumTypes and generate a comparer
foreach( var enumType in enumTypes )
{
var classPrefix = char.ToUpper( enumType[0] ) + enumType.Substring( 1 ).Replace( ".", string.Empty );
if( enumType.IndexOf( "." ) > 0 )
{
var enumTypeSansNS = enumType.Substring( enumType.IndexOf( "." ) + 1 );
classPrefix = char.ToUpper( enumTypeSansNS[0] ) + enumTypeSansNS.Substring( 1 ).Replace( ".", string.Empty );
}
WriteLine( "\tpublic class {0}Comparer : IEqualityComparer<{1}>", classPrefix, enumType );
WriteLine( "\t{" );
WriteLine( "\t\tstatic public readonly {0}Comparer default{0}Comparer = new {0}Comparer();\n", classPrefix );
WriteLine( "\t\tpublic bool Equals( {0} x, {0} y )", enumType );
WriteLine( "\t\t{" );
WriteLine( "\t\t\treturn x == y;" );
WriteLine( "\t\t}\n\n" );
WriteLine( "\t\tpublic int GetHashCode( {0} b )", enumType );
WriteLine( "\t\t{" );
WriteLine( "\t\t\treturn (int)b;" );
WriteLine( "\t\t}" );
WriteLine( "\t}\n\n" );
}
#>
}