Added moar comments and fixed #4.

This commit is contained in:
Starbeamrainbowlabs 2016-07-25 19:22:22 +01:00
parent 6418f52bf8
commit 1fe1b54174

View file

@ -96,47 +96,56 @@ namespace cscz
public override string ToString() public override string ToString()
{ {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
// Using statements
foreach(string usingStatement in UsingStatements) foreach(string usingStatement in UsingStatements)
result.AppendLine(string.Format("using {0};", expandUsingShortcut(usingStatement))); result.AppendLine(string.Format("using {0};", expandUsingShortcut(usingStatement)));
result.AppendLine(); result.AppendLine();
// Class name
result.AppendLine(string.Format("class {0} ", ClassName)); result.AppendLine(string.Format("class {0} ", ClassName));
result.AppendLine("{"); result.AppendLine("{");
// Class body parts declaration
StringBuilder properties = new StringBuilder(); StringBuilder properties = new StringBuilder();
StringBuilder constructorSignature = new StringBuilder(string.Format("\tpublic {0}(", ClassName)); StringBuilder constructorSignature = new StringBuilder(string.Format("\tpublic {0}(", ClassName));
StringBuilder constructorBody = new StringBuilder(); StringBuilder constructorBody = new StringBuilder();
// Data member signature handling
foreach (string signature in Signatures) foreach (string signature in Signatures)
{ {
string[] parts = Regex.Split(signature, @"\s+"); string[] signatureParts = Regex.Split(signature, @"\s+");
string datatypeName = parts[0]; string datatypeName = signatureParts[0];
string privateDataMemberName = LowercaseFirstLetter(parts[1]); string privateDataMemberName = LowercaseFirstLetter(signatureParts[1]);
string publicDataMemberName = UppercaseFirstLetter(parts[1]); string publicDataMemberName = UppercaseFirstLetter(signatureParts[1]);
constructorSignature.AppendFormat("{0} in{1}, ", datatypeName, publicDataMemberName); constructorSignature.AppendFormat("{0} in{1}, ", datatypeName, publicDataMemberName);
if (CreateProperties) if (CreateProperties)
{ {
// Private data member
result.AppendLine(string.Format("\tprivate {0} {1};", datatypeName, privateDataMemberName)); result.AppendLine(string.Format("\tprivate {0} {1};", datatypeName, privateDataMemberName));
// Public property associated with above private data member
properties.AppendLine(string.Format("\tpublic {0} {1}", datatypeName, publicDataMemberName)); properties.AppendLine(string.Format("\tpublic {0} {1}", datatypeName, publicDataMemberName));
properties.AppendLine(string.Format("\t{{")); properties.AppendLine(string.Format("\t{{"));
properties.AppendLine(string.Format("\t\tget {{ return {0}; }}", privateDataMemberName)); properties.AppendLine(string.Format("\t\tget {{ return {0}; }}", privateDataMemberName));
properties.AppendLine(string.Format("\t\tset {{ {0} = value; }}", privateDataMemberName)); properties.AppendLine(string.Format("\t\tset {{ {0} = value; }}", privateDataMemberName));
properties.AppendLine(string.Format("\t}}")); properties.AppendLine(string.Format("\t}}"));
// Constructor body
constructorBody.AppendLine(string.Format("\t\t{0} = in{0};", publicDataMemberName)); constructorBody.AppendLine(string.Format("\t\t{0} = in{0};", publicDataMemberName));
} }
else else
{ {
// Constuctor body
result.AppendLine(string.Format("\tpublic {0} {1};", datatypeName, publicDataMemberName)); result.AppendLine(string.Format("\tpublic {0} {1};", datatypeName, publicDataMemberName));
constructorBody.AppendLine(string.Format("\t\t{0} = in{1};", privateDataMemberName, publicDataMemberName)); constructorBody.AppendLine(string.Format("\t\t{0} = in{0};", publicDataMemberName));
} }
} }
// Add the properties to the output // Add the properties to the output
result.AppendLine("\t");
result.AppendLine(properties.ToString()); result.AppendLine(properties.ToString());
// Add the constructor to the output // Add the constructor to the output