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

Add support of Single-Dimensional Arrays initialization #245

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

metoule
Copy link
Contributor

@metoule metoule commented Aug 14, 2022

First step towards fixing #194 : single-dimension array initialization.

You can now write:

var target = new Interpreter();
var arr = target.Eval<int[]>("new int[] { 1, 2 }");
Assert.AreEqual(2, arr.Length);
Assert.AreEqual(1, arr[0]);
Assert.AreEqual(2, arr[1]);

Jagged arrays are also supported:

var target = new Interpreter();
var arr = target.Eval<int[][]>("new int[][] { new int[] { 1, 2, }, new int[] { 3, 4, }, }");

Multidimensional arrays are not supported, because I couldn't find the Linq expression needed to create them: NewArrayInit can initialize a single dimension array with values, while NewArrayBounds can initialize a multidimension array, but without values. Considering how rare multidimensional arrays are, I think the limitation is not really an issue.

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.

Very good! Thank you! 👏

@metoule metoule merged commit f0cbd31 into dynamicexpresso:master Aug 16, 2022
@metoule metoule deleted the fix_194 branch August 16, 2022 17:39
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.

2 participants