sebastienros / fluid

Fluid is an open-source .NET template engine based on the Liquid template language.
MIT License
1.41k stars 176 forks source link

Is support aot? #617

Open Cricle opened 9 months ago

Cricle commented 9 months ago

I try

class A
{
    public int D1 { get; set; }
    public int D2 { get; set; }

    public B B { get; set; }

    public IList<B> Bs { get; set; }
}
class B
{
    public string W1 { get; set; }
}

            var f = new FluidParser(new FluidParserOptions { AllowFunctions = true });
            var temp=f.Parse("""
                These shoes are awesome! {{ D1 }} {{ B.W1 }}
""");
            var a = new A { D1 = 123, B = new B { W1 = "456" } };
            Console.WriteLine(temp.Render(new TemplateContext(a)));
dotnet run

Result is These shoes are awesome! 123, but when I try dotnet publish -c Release -r win-x64 -p:PublishAot=true, result is These shoes are awesome!

hishamco commented 9 months ago

Which version?

lahma commented 9 months ago

Fluid currently isn't AOT compatible so as types are dynamically accessed the results will be wrong, like you've noticed.

hishamco commented 9 months ago

-p:PublishAot=true

Oops I didn't notice the flag, thanks @lahma, that's why I was asking myself why the title contains AOT :)

Cricle commented 9 months ago

Has any plan to support aot compile in the feature? Or has any method to make it work?

sebastienros commented 9 months ago

Has any plan to support aot compile in the feature?

I started some work around it, but haven't made progress in a year. Could you describe your scenario where you need AOT?

Cricle commented 9 months ago

I am currently trying to create a program that interacts with GitLab and other websites through webhook. I want to use Microsoft's' cloud native 'approach. Currently, all components used except for Fluid can be AOT enabled, so I am wondering if Fluid also supports AOT.

Thanks

lahma commented 9 months ago

Would probably require use of source generators and non-trivial amount of work.

Cricle commented 9 months ago

I would try to write object to FluidValue source generation use roslyn, but it will be defined like json serialization such as ignore, deep...

I think it will drop the reflection in model use.

lahma commented 9 months ago

Please draft a PR to demonstrate your ideas 👍🏻

Cricle commented 9 months ago

I will try to do it