Implement public auto properties & update Help.md.

This commit is contained in:
Starbeamrainbowlabs 2016-10-18 21:30:47 +01:00
parent 4593ebfcac
commit 4c68613913
2 changed files with 28 additions and 36 deletions

View file

@ -48,21 +48,6 @@ namespace cscz
public GenerationMode GenerationMode = GenerationMode.PublicVariables;
/// <summary>
/// Whether to make data members private and create public properties for them instead of making the
/// data members public.
/// This is read only. Please refer to GenerationMode in order to change this field.
/// </summary>
public bool CreateProperties
{
get
{
if (GenerationMode == GenerationMode.PrivateVariablesWithProperties)
return true;
return false;
}
}
public ClassGenerator ()
{
}
@ -134,8 +119,9 @@ namespace cscz
constructorSignature.AppendFormat("{0} in{1}, ", datatypeName, publicDataMemberName);
if (CreateProperties)
switch(GenerationMode)
{
case GenerationMode.PrivateVariablesWithProperties:
// Private data member
classCode.WriteLine("\tprivate {0} {1};", datatypeName, privateDataMemberName);
@ -148,12 +134,17 @@ namespace cscz
// Constructor body
constructorBody.WriteLine("\t\t{0} = in{0};", publicDataMemberName);
}
else
{
break;
case GenerationMode.PublicAutoProperties:
properties.WriteLine("\tpublic {0} {1} {{ get; set; }}", datatypeName, publicDataMemberName);
constructorBody.WriteLine("\t\t{0} = in{0};", publicDataMemberName);
break;
case GenerationMode.PublicVariables:
// Constuctor body
classCode.WriteLine("\tpublic {0} {1};", datatypeName, publicDataMemberName);
constructorBody.WriteLine("\t\t{0} = in{0};", publicDataMemberName);
break;
}
}

View file

@ -9,8 +9,9 @@ Options:
Argument Meaning
-------------------------------------------------------------------------------
--public Causes the parameters of the class to be defined as public data members. This is the default.
--private Causes the parameters of the class to be defined as private data members with public accessors.
--public Generates public data members for the class fields. This is the default.
--private Generates private data members with public accessors for the class fields.
--public-auto Generates public auto properties for the class fields.
Note that arguments specified later always override arguments specified earlier.