view Source/Templates/Renamer.ttinclude @ 9:1e85f66cf767 default tip

update bltoolkit
author nickolay
date Thu, 05 Apr 2018 20:53:26 +0300
parents f990fcb411a9
children
line wrap: on
line source

<#
//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);
			}
		};
	}


#>