- Notifications
You must be signed in to change notification settings - Fork235
-
hi, is this library supported in a native aot compiled .net application (i am on version .net 8)? thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 4 comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
i tested a simple case with JsonDocument and it seem to work: usingSystem.Text.Json;usingHandlebarsDotNet;usingHandlebarsDotNet.Extension.Json;varmodel=JsonDocument.Parse("{\"Key1\":\"Val1\",\"Key2\":\"Val2\"}");varsource="{{#each this}}{{@key}}={{@value}}\n{{/each}}";varhandlebars=Handlebars.Create();handlebars.Configuration.UseJson();vartemplate=handlebars.Compile(source);varoutput=template(model);Console.WriteLine(output); <ProjectSdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <PropertyGroupCondition="'$(Configuration)'=='Release'"> <PublishAot>true</PublishAot> </PropertyGroup> <ItemGroup> <PackageReferenceInclude="Handlebars.Net"Version="2.1.4" /> <PackageReferenceInclude="Handlebars.Net.Extension.Json"Version="1.0.0" /> </ItemGroup></Project> |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
sadly i cant make it work with a simple dictionary: source=@"<diventry""> <h1>{{title}}</h1> <divbody""> {{body}} </div></div>";template=Handlebars.Compile(source);Dictionary<string,string>data=new(){{"title","my new post"},{"body","this is my post"}};varresult=template(data);Console.WriteLine(result); |
BetaWas this translation helpful?Give feedback.
All reactions
-
also thankfully it works correctly with custom objects with source generator: usingSystem.Text.Json;usingSystem.Text.Json.Serialization;usingHandlebarsDotNet;usingHandlebarsDotNet.Extension.Json;varmodel=JsonSerializer.SerializeToDocument(new[]{newModel("ivan","programmer"),newModel("jane","cook"),newModel("joe","athlete")},MyContext.Default.ModelArray);varsource="{{#each this}}Name: {{name}}\nJob: {{job}}\n\n{{/each}}";varhandlebars=Handlebars.Create();handlebars.Configuration.UseJson();vartemplate=handlebars.Compile(source);varoutput=template(model);Console.WriteLine(output);Console.WriteLine();publicclassModel{[JsonPropertyName("name")]publicstringName{get;set;}[JsonPropertyName("job")]publicstringJob{get;set;}publicModel(stringname,stringjob){Name=name;Job=job;}}[JsonSerializable(typeof(Model[]))]publicpartialclassMyContext:JsonSerializerContext{} |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
the only problematic part is that i have to do this in the csproj otherwise it will have runtime error on Debug (not release): <PropertyGroupCondition="'$(Configuration)'=='Release'"> <PublishAot>true</PublishAot> </PropertyGroup> the error: i am not familiar of how the library work but if it is possible to disable dynamic code gen for JsonDocument then i think i wont have to do the csproj thing. |
BetaWas this translation helpful?Give feedback.