m-m-m / code

Library to parse, analyze, transform and generate code
Apache License 2.0
2 stars 3 forks source link

ability for generation of getters and setters #3

Closed hohwille closed 5 years ago

hohwille commented 5 years ago

A common thing is to generate getters and setters (esp. in Java). For convenience it would be nice to have support for this directly in the API e.g. in CodeType:

void createGetters();
void createSetters();
void createGettersAndSetters();

We should be aware that C# and TypeScript have a different concept for Properties and there I would suggest that CodeField implementation (e.g. CsField) would also implement CodeProperty and should therefore host a getter and setter (including the default one). These getters and setters have the according names get and set and are not listed as (declared) methods of the code type. Hence here getFields and getProperties would more or less return the same thing.

For C# (TypeScript is very similar):

public string MyProperty { get; set; }

or

string _myProperty;

public string MyProperty
{
    get { return _myProperty; }
    set { _myProperty = value; }
}
hohwille commented 5 years ago

In C# with assignment:

public int X { get; set; } = x;
hohwille commented 5 years ago

Done.