Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.21k stars 213 forks source link

[Feature] Multi-dimensional Arrays support #483

Open oformaniuk opened 2 years ago

oformaniuk commented 2 years ago

Discussed in https://github.com/Handlebars-Net/Handlebars.Net/discussions/450

Originally posted by **nooelan** May 10, 2021 My model contains data that are multi-dimensional, and my first attempt was to implement this as a regular C# multidimensional array similar to this: `object[,] matrix3x3 = new object[3,3];` When trying to access this type of object from a template, Handlebars.Net threw an exception complaining it could not convert from object[ , ] to object[]. Then I changed my model implementation to jagged arrays (similar to this): ``` object[][] matrix3x3 = new object[3]; for (row = 0; row < 3; ++row) matrix3x3[row] = new object[3]; ``` This works just fine with Handlebars.Net. Question: Is the lack of support for regular multidimensional arrays intentional, or is it a missing feature or bug? As regular, multidimensional arrays are more efficient, at least for 2D arrays according to C# guidelines, I think it is a good idea to add support for it. It will also help avoid having to change the implementation of an already existing model.
mike-warren-dev commented 1 year ago

I'll work on this if you still want it, @zjklee

oformaniuk commented 1 year ago

Thanks @mike-warren-dev, I'd appreciate a PR ;)