中文 | English
基于roslyn的动态编译库,为您提供高效率、高性能、可追踪的动态构建方案,兼容stanadard2.0, 只需原生C#语法不用Emit。 让您的动态方法更加容易编写、跟踪、维护。 欢迎参与讨论:点击加入Gitter讨论组
Scan Name | Status |
---|---|
Document | |
Lang | |
Rumtime | |
OS |
CI Platform | Build Server | Master Build | Master Test |
---|---|---|---|
Travis | Linux/OSX | ||
AppVeyor | Windows/Linux | ||
Azure | Windows | ||
Azure | Linux | ||
Azure | Mac |
- 2019-06-25 : 发布v0.7.1.2, 修复跨平台调用,将object类型纳入一次性赋值类型,增加类扩展方法。
- 2019-06-26 : 发布v0.7.2.0, 升级到Standard的程序集操作,并指定release模式进行编译。
- 2019-08-01 : 发布v1.0.0.0, 发布稳如老狗版,抛弃Emit农耕铲,端起Roslyn金饭碗。
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext> <--- 一定要加上这句话
</PropertyGroup>
var action = FastMethodOperator.New
.Param<string>("str1")
.Param(typeof(string),"str2")
.MethodBody("return str1+str2;")
.Return<string>()
.Complie<Func<string,string,string>>();
string result = action("Hello ","World!"); //result: "Hello World!"
//定义一个委托
public delegate string GetterDelegate(int value);
//方法一
var action = DelegateOperator<GetterDelegate>.Create("value += 101; return value.ToString();");
string result = action(1); //result: "102"
//方法二
var action = "value += 101; return value.ToString();".Create<GetterDelegate>();
string result = action(1); //result: "102"
public class Test
{
public string Handler(string str)
{
retrurn null;
}
}
var action = FakeMethodOperator.New
.UseMethod(typeof(Test).GetMethod("Handler"))
.StaticMethodContent(" str += "" is xxx;"",return str; ")
.Complie<Func<string,string>>();
string result = action("xiao"); //result: "xiao is xxx;"
Example:
typeof(Dictionary<string,List<int>>[]).GetDevelopName();
//result: "Dictionary<String,List<Int32>>[]"
typeof(Dictionary<string,List<int>>[]).GetAvailableName();
//result: "Dictionary_String_List_Int32____"
typeof(Dictionary<string,List<int>>).GetAllGenericTypes();
//result: [string,list<>,int]
typeof(Dictionary<string,List<int>>).IsImplementFrom<IDictionary>();
//result: true
typeof(Dictionary<string,List<int>>).IsOnceType();
//result: false
typeof(List<>).With(typeof(int));
//result: List<int>
Example:
Using : Natasha.Method;
public delegate int AddOne(int value);
var action = "return value + 1;".Create<AddOne>();
var result = action(9);
//result : 10
var action = typeof(AddOne).Create("return value + 1;");
var result = action(9);
//result : 10
Example:
Using : Natasha.Clone;
var instance = new ClassA();
var result = instance.Clone();
Example:
Using : Natasha.Snapshot;
var instance = new ClassA();
instance.MakeSnapshot();
// ********
// do sth
// ********
var result = instance.Compare();
Natasha的动态调用模块: 已移至【NCaller】
-
测试计划(等待下一版本bechmark):
- 动态函数性能测试(对照组: emit, origin)
- 动态调用性能测试(对照组: 动态直接调用,动态代理调用,emit, origin)
- 动态克隆性能测试(对照组: origin)
- 远程动态封装函数性能测试(对照组: 动态函数,emit, origin)