You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a few places that mention that Handlebars.Net is supposed to be case insensitive as of v1.6.6 but I can't seem to get it to act that way.
Am I doing something wrong in the code? Below is a basic example of what I'm doing
var templateString = "Dear {{displayName}}";
var template = Handlebars.Compile(templateString);
var data = new ExpandoObject();
data.TryAdd("DisplayName", "John");
var output = template(data);
Console.WriteLine(output);
This just results in Dear .
If I change templateString to be "Dear {{DisplayName}}" it would print Dear John
This is using the NuGet package v1.10.1 on a .NET Core 3.1 console application.
Hello @brandon-vs . Unfortunately not everything can be handled in case-insensitive way. For example consider data object implementing IDictionary<string, object> (applies to your example with ExpandoObject) - in order to get value from the object members of IDictionary<string, object> will be used. If data source provide case-insensitive access to properties (e.g. new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)) you'd get case-insensitive behavior. The same is true for POCOs as the library performs case-insensitive property search.
Unfortunately the library is not able to handle cases when IDictionary<string, object> data source does not provide case-insensitive behavior as it would require wrapping such object with some kind of proxy that would handle case-insensitive search. Including such functionality as a default behavior can impact performance.
However starting from 2.0 you would be able to handle such problems on you own by registering custom IObjectDescriptorProvider:
Activity
oformaniuk commentedon Sep 24, 2020
Hello @brandon-vs . Unfortunately not everything can be handled in case-insensitive way. For example consider data object implementing
IDictionary<string, object>(applies to your example withExpandoObject) - in order to get value from the object members ofIDictionary<string, object>will be used. If data source provide case-insensitive access to properties (e.g.new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)) you'd get case-insensitive behavior. The same is true for POCOs as the library performs case-insensitive property search.Unfortunately the library is not able to handle cases when
IDictionary<string, object>data source does not provide case-insensitive behavior as it would require wrapping such object with some kind of proxy that would handle case-insensitive search. Including such functionality as a default behavior can impact performance.However starting from 2.0 you would be able to handle such problems on you own by registering custom
IObjectDescriptorProvider:Be aware that proposed API is not final and may change prior to v2 release.