Skip to content

Commit c7acec5

Browse files
New Crowdin translations by GitHub Action (#200)
Co-authored-by: Crowdin Bot <[email protected]>
1 parent 0766d8e commit c7acec5

23 files changed

+726
-28
lines changed

src/i18n/en-US/docusaurus-plugin-content-docs/current/compile/002-SmartMode-Full.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ Implementing assemblies include the specific implementation and private fields o
1414

1515
## Preheating Examples
1616

17+
## 链式预热
18+
19+
从 V9 版本起,Natasha 支持链式预热:
20+
21+
```cs
22+
NatashaManagement
23+
//获取链式构造器
24+
.GetInitializer()
25+
//使用引用程序集中的命名空间
26+
.WithRefUsing()
27+
//使用引用程序集中的元数据
28+
.WithRefReference()
29+
//使用内存中的命名空间
30+
.WithMemoryUsing()
31+
//使用内存中的元数据
32+
.WithMemoryReference()
33+
//使用文件来持久化缓存 命名空间
34+
.WithFileUsingCache()
35+
//过滤哪些元数据是不能用的,被排除的
36+
.WithExcludeReferences((asm, asmStr) => { return false; })
37+
//注册域构造器
38+
.Preheating<NatashaDomainCreator>();
39+
```
40+
41+
如果不指定相关 API ,预热将跳过此行为,例如只写 WithXXXReference 不写 using 相关的 API, 那么 Natasha 预热时将只对元数据进行操作,不会缓存 using code. 这样做的好处是实现了高度定制化,按需预热。
42+
1743
### Ordinary Preheating
1844

1945
1. The generic preheating method will automatically create a singleton for the compilation domain creator.
@@ -22,17 +48,39 @@ Implementing assemblies include the specific implementation and private fields o
2248
4. The second parameter indicates whether to extract 'Metadata' from memory assemblies. Set it to true to extract 'Metadata' from implementing assemblies.
2349

2450
```cs
25-
//Register the compilation domain and preheat method
51+
//注册编译域并预热方法
2652
NatashaManagement.Preheating<NatashaDomainCreator>(true, true);
53+
//或者 V9 版本
54+
NatashaManagement
55+
//获取链式构造器
56+
.GetInitializer()
57+
//使用引用程序集中的命名空间
58+
.WithMemoryUsing()
59+
//使用内存中的元数据
60+
.WithMemoryReference()
61+
//注册域构造器
62+
.Preheating<NatashaDomainCreator>();
2763
```
2864

2965
### Using Cache Preheating
3066

31-
The first generation will write the 'Using Code' into the cache file 'Natasha.Namespace.cache', and subsequent restarts will automatically load it from the file.
67+
指定第三个参数,第一次生成将 Using Code 写入缓存文件 Natasha.Namespace.cache 中,后续重启会自动从文件中加载。
3268

3369
```cs
34-
//Register the compilation domain and preheat method
35-
NatashaManagement.Preheating<NatashaDomainCreator>(true, true, true);
70+
//注册编译域并预热方法
71+
NatashaManagement.Preheating<NatashaDomainCreator>(true, truetrue);
72+
//或者 V9 版本
73+
NatashaManagement
74+
//获取链式构造器
75+
.GetInitializer()
76+
//使用引用程序集中的命名空间
77+
.WithMemoryUsing()
78+
//使用内存中的元数据
79+
.WithMemoryReference()
80+
//使用文件来持久化缓存 命名空间
81+
.WithFileUsingCache()
82+
//注册域构造器
83+
.Preheating<NatashaDomainCreator>();
3684
```
3785

3886
### Separate Preheating

src/i18n/en-US/docusaurus-plugin-content-docs/current/compile/002-SmartMode-Ref.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ Reference Assembly does not include the implementation and will not cause unexpe
1515

1616
## Preheating Examples
1717

18+
### 链式预热
19+
20+
从 V9 版本起,Natasha 支持链式预热:
21+
22+
```cs
23+
NatashaManagement
24+
//获取链式构造器
25+
.GetInitializer()
26+
//使用引用程序集中的命名空间
27+
.WithRefUsing()
28+
//使用引用程序集中的元数据
29+
.WithRefReference()
30+
//使用内存中的命名空间
31+
.WithMemoryUsing()
32+
//使用内存中的元数据
33+
.WithMemoryReference()
34+
//使用文件来持久化缓存 命名空间
35+
.WithFileUsingCache()
36+
//过滤哪些元数据是不能用的,被排除的
37+
.WithExcludeReferences((asm, asmStr) => { return false; })
38+
//注册域构造器
39+
.Preheating<NatashaDomainCreator>();
40+
```
41+
42+
如果不指定相关 API ,预热将跳过此行为,例如只写 WithXXXReference 不写 using 相关的 API, 那么 Natasha 预热时将只对元数据进行操作,不会缓存 using code. 这样做的好处是实现了高度定制化,按需预热。
43+
1844
### Ordinary Preheating
1945

2046
1. The generic preheating method will automatically create a singleton for the compilation domain creator.
@@ -23,17 +49,39 @@ Reference Assembly does not include the implementation and will not cause unexpe
2349
4. The second parameter specifies whether to extract the metadata from the memory assembly. Setting it to false will extract the metadata from the reference assembly.
2450

2551
```cs
26-
//Register the compilation domain and preheating method
52+
//注册编译域并预热方法
2753
NatashaManagement.Preheating<NatashaDomainCreator>(false, false);
54+
//或 V9 版本
55+
NatashaManagement
56+
//获取链式构造器
57+
.GetInitializer()
58+
//使用引用程序集中的命名空间
59+
.WithRefUsing()
60+
//使用引用程序集中的元数据
61+
.WithRefReference()
62+
//注册域构造器
63+
.Preheating<NatashaDomainCreator>();
2864
```
2965

3066
### Using Cache Preheating
3167

3268
The first generation will write the 'Using Code' into the cache file 'Natasha.Namespace.cache', and subsequent restarts will automatically load it from the file.
3369

3470
```cs
35-
//Register the compilation domain and preheating method
36-
NatashaManagement.Preheating<NatashaDomainCreator>(false, false, true);
71+
//注册编译域并预热方法
72+
NatashaManagement.Preheating<NatashaDomainCreator>(false, falsetrue);
73+
//或 V9 版本
74+
NatashaManagement
75+
//获取链式构造器
76+
.GetInitializer()
77+
//使用引用程序集中的命名空间
78+
.WithRefUsing()
79+
//使用引用程序集中的元数据
80+
.WithRefReference()
81+
//使用文件来持久化缓存 命名空间
82+
.WithFileUsingCache()
83+
//注册域构造器
84+
.Preheating<NatashaDomainCreator>();
3785
```
3886

3987
### Separate Preheating

src/i18n/en-US/docusaurus-plugin-content-docs/current/compile/004-Metadata.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ loadContext.AddReferenceAndUsingCode(refAssemblyFilePath);
3333
Add [metadata references] separately
3434

3535
```cs
36+
loadContext.AddReferences()
37+
//
3638
loadContext.ReferenceRecorder.AddReference(
3739
AssemblyName assemblyName,
3840
MetadataReference reference,
@@ -44,6 +46,8 @@ The purpose of the third parameter is: when the assemblyName already exists in t
4446
### Add [Using Code] separately
4547

4648
```cs
49+
loadContext.AddUsing()
50+
//
4751
loadContext.UsingRecorder.Using(string? @using);
4852
loadContext.UsingRecorder.Using(IEnumerable<string> @using);
4953
loadContext.UsingRecorder.Using(Assembly assembly);

src/i18n/en-US/docusaurus-plugin-content-docs/current/compile/006-Advanced.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ builder.SetDllFilePath/SetPdbFilePath/SetCommentFilePath();
111111
Natasha has assembly-related configurations
112112

113113
```cs
114-
//Output the full assembly
114+
//输出完整程序集
115115
builder.OutputAsFullAssembly();
116-
//Output the referenced assembly, which by default does not include private members
116+
//输出引用程序集,此时将默认不包含私有成员
117117
builder.OutputAsRefAssembly();
118-
//Include private members when outputting
118+
//输出时包含私有成员
119119
builder.WithPrivateMembers();
120-
//Do not include private members when outputting
120+
//输出时不包含私有成员
121121
builder.WithoutPrivateMembers();
122122

123-
//The compilation result is a referenced assembly, written to a file, and not loaded into the domain.
123+
//编译结果为引用程序集,且写入文件,且不会加载到域。
124124
builder
125125
.OutputAsRefAssembly();
126126
.WithFileOutput()
127-
.WithoutInjectToDomain();
127+
.CompileWithoutAssembly();
128128
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: 7. Natasha 的异常
3+
---
4+
5+
## 使用方法
6+
7+
Natasha 在编译时出错会抛出异常,异常 Model 如下:
8+
9+
```cs
10+
public sealed class NatashaException : Exception
11+
{
12+
13+
//格式化后的脚本字符串
14+
public string Formatter;
15+
16+
//错误类型
17+
public NatashaExceptionKind ErrorKind;
18+
19+
//roslyn诊断集合
20+
public List<Diagnostic> Diagnostics;
21+
22+
/// <summary>
23+
/// 详细的编译信息
24+
/// </summary>
25+
public string CompileMessage;
26+
27+
}
28+
```
29+
30+
### 如何监控和获取异常
31+
32+
Natasha 的事件执行流程如下:
33+
34+
1. 添加语法树时:
35+
36+
- 使用 FastAddScriptWithoutCheck,则不会抛出异常。
37+
- 使用 Add 则会进行语法检查,并抛出异常。
38+
39+
2. 编译时:
40+
41+
- 编译后先触发 LogCompilationEvent 事件,用来获取编译后的信息。
42+
- 如果编译成功会继续引发 CompileSucceedEvent 事件。
43+
- 如果编译失败会继续引发 CompileFailedEvent 事件。
44+
45+
3. 编译周期之外:
46+
47+
- 编译过后,可以通过 GetException() 获取异常(可能为空)。
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: 8. 使用 Natasha 的类型扩展
3+
---
4+
5+
```cs
6+
7+
Example:
8+
9+
10+
typeof(Dictionary<string,List<int>>[]).GetRuntimeName();
11+
//result: "Dictionary<String,List<Int32>>[]"
12+
13+
14+
typeof(Dictionary<string,List<int>>[]).GetDevelopName();
15+
//result: "System.Collections.Generic.Dictionary<System.String,System.Collections.Generic.List<System.Int32>>[]"
16+
17+
typeof(Dictionary<,>).GetDevelopNameWithoutFlag();
18+
//result: "System.Collections.Generic.Dictionary<,>"
19+
20+
21+
typeof(Dictionary<string,List<int>>[]).GetAvailableName();
22+
//result: "Dictionary_String_List_Int32____"
23+
24+
25+
typeof(Dictionary<string,List<int>>).GetAllGenericTypes();
26+
//result: [string,list<>,int]
27+
28+
29+
typeof(Dictionary<string,List<int>>).IsImplementFrom<IDictionary>();
30+
//result: true
31+
32+
33+
typeof(Dictionary<string,List<int>>).IsSimpleType();
34+
//result: false
35+
36+
37+
typeof(List<>).With(typeof(int));
38+
//result: List<int>
39+
40+
```
41+
42+
<br/>
43+
<br/>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: 9. 使用 Codecov 的扩展
3+
---
4+
5+
## 使用方法
6+
7+
1. 引入 `DotNetCore.Natasha.CSharp.Extension.Codecov` 扩展包。
8+
2. 编码。
9+
10+
```cs
11+
builder.WithCodecov();
12+
Assembly asm = builder.GetAssembly();
13+
List<(string MethodName, bool[] Usage)>? list = asm.GetCodecovCollection();
14+
Show(list);
15+
16+
17+
public static void Show(List<(string MethodName, bool[] Usage)> list)
18+
{
19+
for (int i = 0; i < list!.Count; i++)
20+
{
21+
if (list[i].Usage != null)
22+
{
23+
if (list[i].Usage.Length == 0)
24+
{
25+
Console.WriteLine($"{list[i].MethodName} 执行:100%");
26+
}
27+
else
28+
{
29+
var executeCount = list[i].Usage.Count(item => item);
30+
Console.WriteLine($"{list[i].MethodName} 执行:{((double)executeCount / list[i].Usage.Length).ToString("P")}");
31+
}
32+
}
33+
else
34+
{
35+
Console.WriteLine($"{list[i].MethodName} 未执行!");
36+
}
37+
}
38+
}
39+
```
40+
41+
## Description
42+
43+
CodeCov 将作为 Natasha 扩展库出现
44+
45+
使用方法:
46+
47+
```cs
48+
List<(string MethodName, bool[] Usage)>? result = Assembly.GetCodecovCollection();
49+
```
50+
51+
其中 result 将存放方法以及方法所执行行数的集合。
52+
比如 A 类中有方法 Method , Method 方法体共 6 行代码逻辑,在执行过程中仅执行了前4行。
53+
result 集合中将有:
54+
55+
```cs
56+
"MyNamespace.A.Method":
57+
[0] = true,
58+
[1] = true,
59+
[2] = true,
60+
[3] = true,
61+
[4] = false,
62+
[5] = false,
63+
```
64+
65+
<br/>
66+
<br/>

0 commit comments

Comments
 (0)