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

Factory methods renderer: create variables for reflection elements #38

Closed
zspitz opened this issue Aug 20, 2020 · 1 comment
Closed

Comments

@zspitz
Copy link
Owner

zspitz commented Aug 20, 2020

For the factory methods renderer, and pending #8, we could also define variables for other reused elements, such as MethodInfo instances. Instead of returning something like this:

Lambda(
    Call(
        typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }),
        Add(s1, s2,
            typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) })
        )
    ),
    var s1 = Parameter(
        typeof(string),
        "s1"
    ),
    var s2 = Parameter(
        typeof(string),
        "s2"
    )
)

we could return something like this:

// Variables
var s1 = Parameter(
    typeof(string),
    "s1"
);
var s2 = Parameter(
    typeof(string),
    "s2"
);

// MethodInfos
var writeLine = typeof(Console).GetMethod("WriteLine", new[] { typeof(string) });
var concat = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) });

Lambda(
    Call(
        writeLine,
        Add(s1, s2, concat)
    ),
    s1,
    s2
)
@zspitz zspitz changed the title Factory methods renderer: create variables for reused elements, such as MethodInfo Factory methods renderer: create variables for reflection elements Aug 26, 2020
@zspitz
Copy link
Owner Author

zspitz commented Aug 26, 2020

This seems to be technically unfeasable. Within a given insertion point (each of which has its own StringBuilder) we allow only forward-only writing. The first time a given reflection element is encountered, we would write it out entirely, within the method calls. Then the next time, we'd have to go back and replace the reflection code with the variable name.

Alternatively, we might use variables for every reflection element, but that would obscure what is being passed into the method.

Closing for now.

@zspitz zspitz closed this as completed Aug 26, 2020
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

No branches or pull requests

1 participant