night-moon-studio / Leo

A library based on NCC Natasha to quickly and easily read/write instance's fields or properties.
https://natasha.dotnetcore.xyz
MIT License
81 stars 18 forks source link

减少 new 构建,使用代理字段和算法优化 LeoMapper 查询性能。 #10

Closed NMSAzulX closed 3 years ago

NMSAzulX commented 3 years ago

@alexinea 该段代码实现应该得到优化,ToLeoMemberMetadataScript

DictBase<> 的代理类中提供查询方法,由 BTFTree 算法来实现:

private readonly static LeoMember _leoMember_Foo;
private readonly static LeoMember _leoMember_Name;

public LeoMember GetMember(string memberName)
{
       //leoScriptDict :

                     //leoDict -> leoScriptDict<"Name","return _leoMember_Name;">
                     //leoDict -> leoScriptDict<"Foo","return _leoMember_Foo;">

        //BTFTree Script :

                     //logical from : script  = BTFTemplate.GetGroupPrecisionPointBTFScript(leoScriptDict, "memberName");
}

//静态填充方法
public static void FillLeoMapper(Dict<string,LeoMember> dict)
{
      _leoMember_Foo = dict["Foo"];
       .......
}

在构建完成后使用动态代码调用 FillLeoMapper方法

NDelegate.Random().Action<Dict<string,LeoMember>>("type.FillLeoMapper(arg);")();