diff Source/Templates/Renamer.ttinclude @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Templates/Renamer.ttinclude	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,38 @@
+<#
+//Rename tables and fields according to the .NET style, i.e. "booking_number" to "BookingNumber"
+	{
+		var fieldsPrevBeforeGenerateModel = BeforeGenerateModel;
+
+		Func<string, string> getNetStyleName = (string name) =>
+		{
+			if(!string.IsNullOrEmpty(name))
+			{
+				var chars = new System.Text.StringBuilder(name);
+				for(int i=1; i<chars.Length; i++)
+					if(chars[i-1]=='_') chars[i]=char.ToUpper(chars[i]);
+				chars.Replace("_", null);
+				chars[0]=char.ToUpper(chars[0]);
+				name = chars.ToString();
+			}
+			return name;
+		};
+
+		BeforeGenerateModel = tt =>
+		{
+			fieldsPrevBeforeGenerateModel(tt);
+			Dictionary<string, string> remapper = new Dictionary<string, string>() { { "Exception", "Exceptions" } };
+
+			foreach (var t in Tables.Values)
+			{
+				t.ClassName = getNetStyleName(t.ClassName);
+				string className;
+				if(remapper.TryGetValue(t.ClassName, out className))
+					t.ClassName = className;
+				foreach (var c in t.Columns.Values)
+					c.MemberName = getNetStyleName(c.MemberName);
+			}
+		};
+	}
+
+
+#>
\ No newline at end of file