Skip to content

Add support of Single-Dimensional Arrays initialization#245

Merged
metoule merged 1 commit intodynamicexpresso:masterfrom
metoule:fix_194
Aug 16, 2022
Merged

Add support of Single-Dimensional Arrays initialization#245
metoule merged 1 commit intodynamicexpresso:masterfrom
metoule:fix_194

Conversation

@metoule
Copy link
Copy Markdown
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
Copy Markdown
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