# Natasha
**Repository Path**: mayuzx/Natasha
## Basic Information
- **Project Name**: Natasha
- **Description**: 使用roslyn方案打造高性能动态代码。
- **Primary Language**: C#
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2020-05-29
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
中文 |
English
# Natasha
[](https://github.com/dotnetcore)
[](https://www.nuget.org/packages/DotNetCore.Natasha)
[](https://gitter.im/dotnetcore/Natasha?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[](https://996.icu/#/zh_CN)
[](https://github.com/dotnetcore/Natasha/blob/master/LICENSE)
基于roslyn的动态编译库,为您提供高效率、高性能、可追踪的动态构建方案,兼容stanadard2.0, 只需原生C#语法不用Emit。
让您的动态方法更加容易编写、跟踪、维护。 欢迎参与讨论:[点击加入Gitter讨论组](https://gitter.im/dotnetcore/Natasha)
### 类库信息(Library Info)
[](https://github.com/dotnetcore/Natasha/releases)  [](https://github.com/dotnetcore/Natasha/commits/master) [](https://codecov.io/gh/dotnetcore/Natasha)
| Scan Name | Status |
|--------- |------------- |
| Document | [](https://github.com/dotnetcore/Natasha/wiki) |
| Lang | |
| Rumtime |  |
| OS |   |
### 持续构建(CI Build Status)
| CI Platform | Build Server | Master Build | Master Test |
|--------- |------------- |---------| --------|
| Travis | Linux/OSX | [](https://travis-ci.org/dotnetcore/Natasha) | |
| AppVeyor | Windows/Linux |[](https://ci.appveyor.com/project/NMSAzulX/natasha)|[](https://ci.appveyor.com/project/NMSAzulX/natasha)|
| Azure | Windows |[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master)|[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master) |
| Azure | Linux |[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master)|[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master) |
| Azure | Mac |[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master)|[](https://dev.azure.com/NightMoonStudio/Natasha/_build/latest?definitionId=3&branchName=master) |
### Wiki审核
Teng(359768998@qq.com)
### 代码审核
WeihanLi
### 发布日志
- 2019-08-11 : 发布v1.3.4.0,增加NFunc/NAction方法, 可快速动态构建方法。
- 2019-08-16 : 发布v1.3.6.0,添加枚举构建及编译方法, 日志添加一级 “时分” 目录。
- 2019-09-01 : 发布v2.0.0.0,支持共享域协作,支持创建、卸载、锁域操作,支持多程序集合并编译、覆盖编译,支持外部文件热加载,封装字符串解构操作。
### 升级日志
- [[2019]](https://github.com/dotnetcore/Natasha/wiki/Update2019)
### 微信群
---------------------
### 使用方法(User Api):
> 更多更新的参考文档:https://github.com/dotnetcore/Natasha/tree/master/article/ch
#### 首先编辑您的工程文件:
```C#
Exe
netcoreapp2.2
true <--- 一定要加上这句话
false <---- WEB发布一定要加
```
#### 异常捕获方法:
```C#
var fastBuilder = FastMethodOperator.New;
fastBuilder.Complier.Exception; //编译后异常会进入这里
var fakeBuilder = FakeMethodOpeartor.New;
fakeBuilder.Complier.Exception;
var oopBuilder = new OopBuilder();
oopBuilder.Complier.Exception;
if(builder.Complier.Exception.ErrorFlag == ComplieError.None)
{
//编译成功!
}
```
#### 脚本与DLL混合编译
```C#
//dll 中的内容:
using System;
namespace ClassLibrary1
{
public class Class1
{
public void Show1()
{
Console.WriteLine("RunShow1");
}
public static void Show2()
{
Console.WriteLine("RunShow2");
}
}
}
```
```C#
string text = @"
using System;
using System.Collections;
using System.Linq;
using System.Text;
using ClassLibrary1;
namespace HelloWorld
{
public class Test
{
public override string ToString()
{
Class1 a = new Class1();
a.Show1();
Class1.Show2();
return ""11"";
}
}
}";
//Class1 来自于 ClassLibrary1.dll
//添加/编译
OopComplier oop = new OopComplier();
oop.LoadFile(@"D:\Project\IlTest\ClassLibrary1\bin\Debug\netstandard2.0\ClassLibrary1.dll");
Type type = oop.GetClassType(text);
//调用
var a = Activator.CreateInstance(type);
Console.WriteLine(a.ToString());
```
#### Natasha的动态调用模块: 已移至[【NCaller】](https://github.com/night-moon-studio/NCaller)
---------------------
- **测试计划(等待下一版本bechmark)**:
- [ ] **动态函数性能测试(对照组: emit, origin)**
- [ ] **动态调用性能测试(对照组: 动态直接调用,动态代理调用,emit, origin)**
- [ ] **动态克隆性能测试(对照组: origin)**
- [ ] **远程动态封装函数性能测试(对照组: 动态函数,emit, origin)**
---------------------
## License
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fdotnetcore%2FNatasha?ref=badge_large)