From 945ec83feb05db833b268e87a47429b4d3e179b8 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 7 May 2016 20:03:44 +0100
Subject: [PATCH] Lets set a few things up.

---
 cscz.sln                        |  17 +++++
 cscz/ClassGenerator.cs          | 128 ++++++++++++++++++++++++++++++++
 cscz/Program.cs                 |  15 ++++
 cscz/Properties/AssemblyInfo.cs |  27 +++++++
 cscz/cscz.csproj                |  41 ++++++++++
 5 files changed, 228 insertions(+)
 create mode 100644 cscz.sln
 create mode 100644 cscz/ClassGenerator.cs
 create mode 100644 cscz/Program.cs
 create mode 100644 cscz/Properties/AssemblyInfo.cs
 create mode 100644 cscz/cscz.csproj

diff --git a/cscz.sln b/cscz.sln
new file mode 100644
index 0000000..3201607
--- /dev/null
+++ b/cscz.sln
@@ -0,0 +1,17 @@
+﻿
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cscz", "cscz\cscz.csproj", "{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}.Debug|x86.ActiveCfg = Debug|x86
+		{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}.Debug|x86.Build.0 = Debug|x86
+		{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}.Release|x86.ActiveCfg = Release|x86
+		{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+EndGlobal
diff --git a/cscz/ClassGenerator.cs b/cscz/ClassGenerator.cs
new file mode 100644
index 0000000..8a187fa
--- /dev/null
+++ b/cscz/ClassGenerator.cs
@@ -0,0 +1,128 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace cscz
+{
+	public class ClassGenerator
+	{
+		/// <summary>
+		/// A mapping of namespaces to using shortcuts.
+		/// </summary>
+		public Dictionary<string, string> UsingShortcuts = new Dictionary<string, string>()
+		{
+			{ "s", "System" },
+			{ "c", "System.Collections.Generic" },
+			{ "cc", "System.Collections.Concurrent" },
+			{ "r", "System.Text.RegularExpressions" }
+		};
+
+		/// <summary>
+		/// The using statements to add to the generated class.
+		/// </summary>
+		public List<string> UsingStatements = new List<string>()
+		{
+			"s"
+		};
+		public List<string> Signatures = new List<string>();
+
+		public string ClassName = "Carrot";
+
+		/// <summary>
+		/// Whether to make data members private and create public properties for them instead of making the
+		/// data members public.
+		/// </summary>
+		public bool CreateProperties = true;
+
+		public ClassGenerator ()
+		{
+		}
+
+		public override string ToString()
+		{
+			StringBuilder result = new StringBuilder();
+			foreach(string usingStatement in UsingStatements)
+				result.AppendLine(string.Format("using {0};", expandUsingShortcut(usingStatement)));
+
+			result.AppendLine();
+			result.AppendLine(string.Format("class {0} ", ClassName));
+			result.AppendLine("{");
+
+			StringBuilder properties = new StringBuilder();
+			StringBuilder constructorSignature = new StringBuilder(string.Format("\tpublic {0}(", ClassName));
+			StringBuilder constructorBody = new StringBuilder();
+
+			foreach (string signature in Signatures)
+			{
+				string[] parts = Regex.Split(signature, @"\s+");
+				string datatypeName = parts[0];
+				string privateDataMemberName = LowercaseFirstLetter(parts[1]);
+				string publicDataMemberName = UppercaseFirstLetter(parts[1]);
+
+				constructorSignature.AppendFormat("{0} in{1}, ", datatypeName, publicDataMemberName);
+
+				if (CreateProperties)
+				{
+					result.AppendLine(string.Format("\tprivate {0} {1};", datatypeName, privateDataMemberName));
+
+					properties.AppendLine(string.Format("\tpublic {0} {1}", datatypeName, publicDataMemberName));
+					properties.AppendLine(string.Format("\t{{"));
+					properties.AppendLine(string.Format("\t\tget {{ return {0}; }}", privateDataMemberName));
+					properties.AppendLine(string.Format("\t\tset {{ {0} = value; }}", privateDataMemberName));
+					properties.AppendLine(string.Format("\t}}"));
+
+					constructorBody.AppendLine(string.Format("\t\t{0} = in{0};", publicDataMemberName));
+				}
+				else
+				{
+					result.AppendLine(string.Format("\tpublic {0} {1};"));
+					constructorBody.AppendLine(string.Format("\t\t{0} = in{1};", privateDataMemberName, publicDataMemberName));
+				}
+			}
+
+			// Add the properties to the output
+			result.AppendLine("\t");
+			result.AppendLine(properties.ToString());
+
+			// Add the constructor to the output
+			constructorSignature.Remove(constructorSignature.Length - 2, 2); // Remove the last ", "
+			constructorSignature.Append(")");
+			result.AppendLine(constructorSignature.ToString());
+			result.AppendLine("\t{");
+			result.Append(constructorBody.ToString());
+			result.AppendLine("\t}");
+
+			// Close the class off and end the file
+			result.AppendLine("}");
+			result.AppendLine();
+
+			return result.ToString();
+		}
+
+		protected string expandUsingShortcut(string shortcut)
+		{
+			if (UsingShortcuts.ContainsKey(shortcut))
+				return UsingShortcuts[shortcut];
+			else
+				return shortcut;
+		}
+
+		private string UppercaseFirstLetter(string str)
+		{
+			if (str == null)
+				return null;
+			if (str.Length > 1)
+				return char.ToUpper(str[0]) + str.Substring(1);
+			return str.ToUpper();
+		}
+		private string LowercaseFirstLetter(string str)
+		{
+			if (str == null)
+				return null;
+			if (str.Length > 1)
+				return char.ToLower(str[0]) + str.Substring(1);
+			return str.ToLower();
+		}
+	}
+}
\ No newline at end of file
diff --git a/cscz/Program.cs b/cscz/Program.cs
new file mode 100644
index 0000000..7184f3b
--- /dev/null
+++ b/cscz/Program.cs
@@ -0,0 +1,15 @@
+﻿using System;
+
+namespace cscz
+{
+	class Program
+	{
+		public static void Main(string[] args)
+		{
+			ClassGenerator cg = new ClassGenerator();
+			cg.Signatures.Add("float radius");
+			cg.Signatures.Add("double weight");
+			Console.WriteLine(cg);
+		}
+	}
+}
diff --git a/cscz/Properties/AssemblyInfo.cs b/cscz/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..c241a7f
--- /dev/null
+++ b/cscz/Properties/AssemblyInfo.cs
@@ -0,0 +1,27 @@
+﻿using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("cscz")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("Starbeamrainbowlabs")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/cscz/cscz.csproj b/cscz/cscz.csproj
new file mode 100644
index 0000000..05f6009
--- /dev/null
+++ b/cscz/cscz.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{3DE7A812-1AB9-483F-A785-4497FC8FDF2C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>cscz</RootNamespace>
+    <AssemblyName>cscz</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Externalconsole>true</Externalconsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>full</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Externalconsole>true</Externalconsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="ClassGenerator.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
