Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of AnyOfCodeGenerator to ease future development #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pacyfist
Copy link

I would like to develop a feature that I think is missing from this library and could be very useful when working in ASP.NET and service->controller communication.

First I thought I'll refactor the code generator so any future changes are easier to implement. I changed the generator from appending the files line by line to using as large as possible interpolated string literals. They are converted into a string builder before compilation so the logic remains exactly the same, but it makes the code cleaner and easier to maintain.

Newly generated classes are almost identical to old ones.

There are two changes.

  • AnyOfTypes.g.cs - I added values to the enum:

(old)

public enum AnyOfType
{
    Undefined = 0, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth
}

(new)

public enum AnyOfType
{
    Undefined = 0, First = 1, Second = 2, Third = 3, Fourth = 4, Fifth = 5, Sixth = 6, Seventh = 7, Eighth = 8, Ninth = 9, Tenth = 10
}
  • AnyOf_??.g.cs - the order of fields in the constructor now is always sequential:

(old)

public AnyOf(TSecond value)
{
    _numberOfTypes = 3;
    _currentType = AnyOfType.Second;
    _currentValue = value;
    _currentValueType = typeof(TSecond);
    _second = value;
    _first = default!;
    _third = default!;
}

(new)

public AnyOf(TSecond value)
{
    _numberOfTypes = 3;
    _currentType = AnyOfType.Second;
    _currentValue = value;
    _currentValueType = typeof(TSecond);
    _first = default!;
    _second = value;
    _third = default!;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant