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

Improve generic type parsing and referencing #178

Merged
merged 4 commits into from
Oct 30, 2021

Conversation

metoule
Copy link
Contributor

@metoule metoule commented Oct 27, 2021

The arity of the generic type is now considered when trying to get the reference type (e.g. Tuple<,,> is now looked up as Tuple`3 during parsing).

That means it's possible to write:

var target = new Interpreter();
target.Reference(typeof(Tuple<>));
target.Reference(typeof(Tuple<,>));
target.Reference(typeof(Tuple<,,>));
Assert.AreEqual(1, target.Eval("new Tuple<int>(1).Item1"));
Assert.AreEqual("My str item", target.Eval("new Tuple<int, string>(5, \"My str item\").Item2"));
Assert.AreEqual(3, target.Eval("new Tuple<int, int, int>(1, 2, 3).Item3"));

The old way is still working, but in that case you need to add the arity yourself:

var target = new Interpreter();
target.Reference(typeof(Tuple<>), "Toto`1");
target.Reference(typeof(Tuple<,>), "Toto`2");
target.Reference(typeof(Tuple<,,>), "Toto`3");
Assert.AreEqual(1, target.Eval("new Toto<int>(1).Item1"));
Assert.AreEqual("My str item", target.Eval("new Toto<int, string>(5, \"My str item\").Item2"));
Assert.AreEqual(3, target.Eval("new Toto<int, int, int>(1, 2, 3).Item3"));

I took this opportunity to also centralize the way types are parsed, so that it's consistent everywhere.

Fixes #174

Copy link
Member

@davideicardi davideicardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just one question on the resx ...

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

Successfully merging this pull request may close these issues.

Allow support for generic types with multiple arity
2 participants