jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

DynamicJsonObject #37

Closed oscaruribe closed 9 years ago

oscaruribe commented 9 years ago

Hi,

When data is DynamicJsonObject it cannot find a way to get values for it.

In my case I have the following structure (simplified):

var data = new { Issue = this, // this is just a normal class DataSources = new Dictionary<string, dynamic[]> { } }

then:

foreach (var dataSource in dataSources) { var dataSourceData = dataSource.Fetch(); // This returns a dynamic data.DataSources.Add(dataSource.Name, dataSourceData); }

This data can be rendered into the template:

each DataSources.SomeDataSource

{{Title}} /each

This works if the data in each DataSourche is dynamic or Dictionary. But when dataSource.Fetch() returns an array of DynamicJsonObject it can't find a way to get values. I made this to fake data:

var i1 = new Dictionary<string, object>(); i1.Add("Title", "t1"); var i2 = new Dictionary<string, object>(); i2.Add("Title", "t2"); return new dynamic[] {new DynamicJsonObject(i1), new DynamicJsonObject(i2)};

It seems to me that DynamicJsonObject is not identified as a valid property getter whereas dynamic is but both behave the same way,

jehugaleahsa commented 9 years ago

Subclasses of DynamicObject are not supported. However, it's a good idea for a future release.

oscaruribe commented 9 years ago

It's ok. I used JsonConvert.Deserialize() and it worked like a charm!

Are there any known performance issues?

We're looking at volumes of one million runs per template (approx 250kb with a few #each and #if statements) Is memory management good?