huangweiboy / NCaller

使用Natasha构建快速动态操作字段/属性

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

中文 | English

NCaller

Member project of Night Moon Studio NuGet Badge GitHub repo size Codecov Badge GitHub license


持续构建(CI Build Status)

CI Platform Build Server Master Build Master Test
Travis Linux/OSX Build status
AppVeyor Windows/Linux Build status Build status
Azure Windows Build Status Azure DevOps tests
Azure Linux Build Status Azure DevOps tests
Azure Mac Build Status Azure DevOps tests

项目简介:

此项目为Natasha的衍生项目,通过运行时自动构建高性能操作代理类,为普通类,静态类,动态类,动态类中的动态类,动态生成的静态类等提供了良好的、完备的、高性能的操作,如果反射、dynamic都不能满足高端的需求,可使用本类库,它将是一个不错的选择。


发布计划:

  • 2019-08-01 : 发布v1.0.0.0, 高性能动态调用库。



性能展示:

由于benchmark 不能支持最新的roslyn编译测试,因此基准测试放在3.0版本后。

性能对比


使用方法(User Api):


首先编辑您的工程文件:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>   <--- 定要加上这句话
  </PropertyGroup>

动态调用普通类:

public class A
{
   public int Age;
   public DateTime Time;
   public B Outter = new B();
}

public class B
{
   public string Name;
   public B()
   {
      Name = "小明"
   }
}


//调用方式(支持动态类型)

var handler = DynamicCaller.Create(typeof(A));

handler.New();

handler["Age"].Set(100);                                          // Set Operator
handler.Set("Age", 100);                                          // Set Operator

Console.WriteLine(handler["Time"].Get<DateTime>());               // Get Operator
Console.WriteLine(handler.Get<DateTime>("Time"));                 // Get Operator

handler.Get("Outter")["Name"].Set("NewName");                     // Link Operator
handler.Get<B>("Outter").Name = "NewName";                        // Link Operator


动态调用静态类:

public static class A
{
   public static int Age;
   public static DateTime Time;
   public static B Outter = new B();
}

public class B
{
   public string Name;
   public B()
   {
      Name = "小明";
   }
}


//调用方式(支持动态类型)

var handler = StaticDynamicCaller.Create(type(A));

handler["Age"].Set(100);                                          // Set Operator
handler.Set("Age", 100);                                          // Set Operator

Console.WriteLine(handler["Time"].Get<DateTime>());               // Get Operator
Console.WriteLine(handler.Get<DateTime>("Time"));                 // Get Operator

handler.Get("Outter").Set(Name,"NewName");                        // Link Operator
handler.Get<B>("Outter").Name = "NewName";                        // Link Operator


License

FOSSA Status

About

使用Natasha构建快速动态操作字段/属性

License:MIT License


Languages

Language:C# 100.0%