Skip to content

Commit

Permalink
修改命名空间
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Feb 2, 2024
1 parent f317148 commit a72e231
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,3 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
/src/SourceFusion.Tool/Properties/launchSettings.json
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,85 @@ Telescope 是一套预编译框架。
|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)|

## Telescope.SourceGeneratorAnalyzers

使用 SourceGenerator 源代码生成器的 Telescope 版本

可以用来导出指定类型

### 用法

支持多个不同的导出写法

#### 分部方法式

这是推荐的方法

在分部类里定义分部方法,分部方法标记 `dotnetCampus.Telescope.TelescopeExportAttribute` 特性,且返回值包括导出条件,如以下写法

```csharp
internal partial class Program
{
[dotnetCampus.Telescope.TelescopeExportAttribute()]
private static partial IEnumerable<(Type type, F1Attribute attribute, Func<Base> creator)> ExportFooEnumerable();
}
```

以上代码将导出当前项目标记了 `F1Attribute` 且继承 `Base` 的所有类型。经过 Telescope 源代码生成器即可生成大概如下的代码

```csharp
[global::System.CodeDom.Compiler.GeneratedCode("dotnetCampus.Telescope.SourceGeneratorAnalyzers", "1.0.0")]
internal partial class Program
{
private static partial IEnumerable<(Type type, F1Attribute attribute, Func<Base> creator)> ExportFooEnumerable()
{
yield return (typeof(F2), new F1Attribute()
{

}, () => new F2());
yield return (typeof(F3), new F1Attribute()
{

}, () => new F3());
}
}
```

高级用法:

可以在 TelescopeExportAttribute 加上 IncludeReference 属性用来导出所有引用程序集的满足条件的类型,如以下代码

```csharp
internal partial class Program
{
[dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReference = true)]
private static partial IEnumerable<(Type type, F1Attribute attribute, Func<Base> creator)> ExportFooEnumerable();
}
```

仅推荐在入口程序集加上 `IncludeReference = true` 属性,因为一旦加入此属性,任何引用程序集的变更都可能导致源代码生成器重复执行,降低 VisualStudio 性能

#### 程序集标记

这是传统的 Telescope 实现方法,在需要导出类型的项目里标记 `dotnetCampus.Telescope.MarkExportAttribute` 特性,如以下代码

```csharp
[assembly: dotnetCampus.Telescope.MarkExportAttribute(typeof(Base), typeof(FooAttribute))]
```

标记之后将会自动生成 `dotnetCampus.Telescope.__AttributedTypesExport__` 类型,即可在代码里面直接使用,如以下代码

```csharp
var attributedTypesExport = new __AttributedTypesExport__();
ICompileTimeAttributedTypesExporter<Base, FooAttribute> exporter = attributedTypesExport;
foreach (var exportedTypeMetadata in exporter.ExportAttributeTypes())
{
// 输出导出的类型
Console.WriteLine(exportedTypeMetadata.RealType.FullName);
}
```

也可以使用 `dotnetCampus.Telescope.AttributedTypes` 辅助类获取所有导出类型

## 为此项目开发

Expand Down
10 changes: 4 additions & 6 deletions src/Tradition/dotnetCampus.TelescopeTask/Cli/Options.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System.IO;
using dotnetCampus.Cli;

using dotnetCampus.Cli;

namespace dotnetCampus.SourceFusion.Cli
namespace dotnetCampus.TelescopeTask.Cli
{
internal class Options
{
[Value(0, Description = "转换源码的工作路径。")]
public string WorkingDirectory { get; set; }

[Option('t', "ToolFolder", Description = "SourceFusion 可以使用的临时文件夹路径。")]
[Option('t', "ToolFolder", Description = "Telescope 可以使用的临时文件夹路径。")]
public string ToolFolder { get; set; }

[Option('c', "GeneratedCodeFolder", Description = "SourceFusion 生成的新源码文件所在的文件夹。")]
[Option('c', "GeneratedCodeFolder", Description = "Telescope 生成的新源码文件所在的文件夹。")]
public string GeneratedCodeFolder { get; set; }

[Option('p', "ProjectPropertyFile", Description = "一个文件,包含项目的各种所需属性和集合。")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using dotnetCampus.SourceFusion.CompileTime;
using dotnetCampus.TelescopeTask.CompileTime;

namespace dotnetCampus.TelescopeTask.CodeGenerating
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using dotnetCampus.SourceFusion.Core;
using dotnetCampus.TelescopeTask.Core;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 编译时找到的程序集
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// The <see cref="Attribute"/> that is in the compile time context.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
internal class CompileField : CompileMember, ICompileField
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dotnetCampus.SourceFusion.Core;
using dotnetCampus.SourceFusion.Syntax;
using dotnetCampus.TelescopeTask.Core;
using dotnetCampus.TelescopeTask.Syntax;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 包含 Compile 类型文件的编译期信息。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 编译找到的对象,可以是类型、属性
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
internal class CompileMethod : CompileMember, ICompileMethod
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
internal class CompileProperty : CompileMember, ICompileProperty
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 编译时找到的类型
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileAssembly
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileAttributeProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileField : ICompileMember
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileInterface : ICompileMember
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileMember : ICompileAttributeProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileMethod : ICompileMember
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
public interface ICompileProperty : ICompileMember
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace dotnetCampus.SourceFusion.CompileTime
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 编译时的类型
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using dotnetCampus.SourceFusion.CompileTime;

namespace dotnetCampus.SourceFusion
namespace dotnetCampus.TelescopeTask.CompileTime
{
/// <summary>
/// 包含编译期代码执行的上下文。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using dotnetCampus.SourceFusion.CompileTime;
using dotnetCampus.TelescopeTask.CompileTime;

namespace dotnetCampus.SourceFusion.Core
namespace dotnetCampus.TelescopeTask.Core
{
/// <summary>
/// <see cref="T:SourceFusion.ICompilingContext" /> 的基础实现,包含编译期代码执行的上下文。
/// <see cref="T:dotnetCampus.TelescopeTask.CompileTime.ICompilingContext" /> 的基础实现,包含编译期代码执行的上下文。
/// </summary>
internal class CompilingContext : ICompilingContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;

namespace dotnetCampus.SourceFusion.Core
namespace dotnetCampus.TelescopeTask.Core
{
public class CompilingException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dotnetCampus.SourceFusion.Cli;
using dotnetCampus.SourceFusion.CompileTime;
using dotnetCampus.TelescopeTask.Cli;
using dotnetCampus.TelescopeTask.CompileTime;

namespace dotnetCampus.SourceFusion.Core
namespace dotnetCampus.TelescopeTask.Core
{
internal class ProjectCompilingContext
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tradition/dotnetCampus.TelescopeTask/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using dotnetCampus.Cli;
using dotnetCampus.Cli.Standard;
using dotnetCampus.MSBuildUtils;
using dotnetCampus.SourceFusion.Cli;
using dotnetCampus.TelescopeTask.Cli;
using dotnetCampus.TelescopeTask.Tasks;

namespace dotnetCampus.TelescopeTask
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using dotnetCampus.SourceFusion.CompileTime;
using dotnetCampus.TelescopeTask.CompileTime;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace dotnetCampus.SourceFusion.Syntax
namespace dotnetCampus.TelescopeTask.Syntax
{
/// <summary>
/// 访问编译的所有类和属性
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.IO;
using System.Linq;
using System.Reflection;
using dotnetCampus.SourceFusion.Core;
using dotnetCampus.TelescopeTask.Core;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace dotnetCampus.SourceFusion.Syntax
namespace dotnetCampus.TelescopeTask.Syntax
{
/// <summary>
/// 包含语法树编译相关的扩展方法。
Expand Down
6 changes: 3 additions & 3 deletions src/Tradition/dotnetCampus.TelescopeTask/Tasks/CompileTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using dotnetCampus.Cli;
using dotnetCampus.Cli.Standard;
using dotnetCampus.MSBuildUtils;
using dotnetCampus.SourceFusion.Cli;
using dotnetCampus.SourceFusion.CompileTime;
using dotnetCampus.SourceFusion.Core;
using dotnetCampus.Telescope;
using dotnetCampus.TelescopeTask.Cli;
using dotnetCampus.TelescopeTask.CompileTime;
using dotnetCampus.TelescopeTask.Core;
using dotnetCampus.TelescopeTask.Utils;

using Walterlv.IO.PackageManagement;
Expand Down

0 comments on commit a72e231

Please sign in to comment.