-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
14 additions
and
3,503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,18 @@ | ||
# SourceFusion | ||
# Telescope | ||
|
||
SourceFusion 是一套预编译框架。 | ||
Telescope 是一套预编译框架。 | ||
|
||
当项目安装 SourceFusion 了之后,项目中即可开始书写预编译代码。通过执行这些预编译代码,项目可以在编译期间执行一些平时需要在运行时执行的代码。这种方式能够将耗时的运行时代码迁移到编译期执行,大幅度提升运行时性能。 | ||
当项目安装 Telescope 了之后,项目中即可开始书写预编译代码。通过执行这些预编译代码,项目可以在编译期间执行一些平时需要在运行时执行的代码。这种方式能够将耗时的运行时代码迁移到编译期执行,大幅度提升运行时性能。 | ||
|
||
|Build|NuGet| | ||
|--|--| | ||
|![](https://github.com/dotnet-campus/SourceFusion/workflows/.NET%20Core/badge.svg)|[![](https://img.shields.io/nuget/v/dotnetCampus.SourceFusion.svg)](https://www.nuget.org/packages/dotnetCampus.SourceFusion)| | ||
|
||
## 入门 | ||
|
||
### 安装 NuGet 包 | ||
|
||
在 NuGet 源上搜索 `SourceFusion` 寻找已发布的 NuGet 包。由于目前尚未发布正式版,所以你需要指定搜索“预编译版本”才能搜索到此包。 | ||
|
||
在需要编写预编译代码的项目中安装此 NuGet 包即可。 | ||
|
||
### 编写预编译代码 | ||
|
||
你有两种编写预编译代码的方法: | ||
![](https://github.com/dotnet-campus/Telescope/workflows/.NET%20Core/badge.svg) | ||
|
||
1. 纯文本代码转换; | ||
1. 模板转换。 | ||
|
||
以下代码为纯文本预编译代码的 Hello World 实现。HelloWorldTransformer.cs 中的 `Transform` 方法将在编译期间执行,用于将 HelloWorld.cs 文件中的输出改为 `Hello World!`。 | ||
|
||
```csharp | ||
[CompileTimeCode("HelloWorld.cs")] | ||
public class HelloWorldTransformer : IPlainCodeTransformer | ||
{ | ||
public string Transform(string originalText, TransformingContext context) | ||
{ | ||
return originalText.Replace("Hello", "Hello World!"); | ||
} | ||
} | ||
``` | ||
|
||
```csharp | ||
using System; | ||
|
||
public class HelloWorld | ||
{ | ||
public void SayHello() | ||
{ | ||
Console.WriteLine("Hello"); | ||
} | ||
} | ||
``` | ||
|
||
以下代码为模板转换的 Hello World 实现: | ||
|Package|NuGet| | ||
|--|--| | ||
|Telescope|[![](https://img.shields.io/nuget/v/dotnetCampus.Telescope.svg)](https://www.nuget.org/packages/dotnetCampus.Telescope)| | ||
|Telescope.SourceGeneratorAnalyzers|[![](https://img.shields.io/nuget/v/dotnetCampus.Telescope.SourceGeneratorAnalyzers.svg)](https://www.nuget.org/packages/dotnetCampus.Telescope.SourceGeneratorAnalyzers)| | ||
|
||
```csharp | ||
using System; | ||
|
||
namespace SourceFusion.Tests | ||
{ | ||
[CompileTimeTemplate] | ||
public class HelloWorld | ||
{ | ||
public void SayHello() | ||
{ | ||
var outputs = Placeholder.Array<string>(context => | ||
{ | ||
// 这里使用两个引号来转义一个引号,最终我们得到了一个包含三个单词部分的数组。 | ||
return @"""Hello "", ""World"", ""!"""; | ||
}); | ||
foreach (var output in outputs) | ||
{ | ||
Console.Write(output); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 为此项目开发 | ||
|
||
非常期望你能加入到 SourceFusion 的开发中来,请阅读 [如何为 SourceFusion 贡献代码](/docs/how-to-contribute.md) 了解开发相关的约定和技术要求。 | ||
非常期望你能加入到 Telescope 的开发中来,请阅读 [如何为 Telescope 贡献代码](/docs/how-to-contribute.md) 了解开发相关的约定和技术要求。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# SourceFusion | ||
# Telescope | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,2 @@ | ||
# 如何为 SourceFusion 贡献代码 | ||
# 如何为 Telescope 贡献代码 | ||
|
||
SourceFusion 基于 Roslyn 对代码进行编译期分析和执行。 | ||
|
||
## 核心程序集 | ||
|
||
核心程序集有两个: | ||
|
||
- SourceFusion.Core | ||
- SourceFusion.Tool | ||
|
||
SourceFusion.Core 是抽象部分,当作为 NuGet 包安装后,会被目标程序集引用,这样目标程序集可以编写出编译期间运行的的代码。SourceFusion.Tool 是对以上抽象的具体实现部分,当作为 NuGet 包安装后,如果目标程序集执行编译操作,那么此程序集将被执行。也就是说,SourceFusion.Core 的存在是为了让目标程序集能够编写出编译期间执行的代码,而 SourceFusion.Tool 则是执行目标程序集中指定为编译期执行的代码。 | ||
|
||
这两个程序集有一些开发上的约定。 | ||
|
||
- SourceFusion.Core 由于会被目标项目通过 PackageReference 的方式引用,所以不要额外引入第三方依赖。 | ||
- SourceFusion.Tool 由于其控制台输出被用于特殊用途,所以请不要使用 `Console.WriteLine` 等进行调试。 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.