DotNetCampus.Telescope
1.0.0-alpha.3
dotnet add package DotNetCampus.Telescope --version 1.0.0-alpha.3
NuGet\Install-Package DotNetCampus.Telescope -Version 1.0.0-alpha.3
<PackageReference Include="DotNetCampus.Telescope" Version="1.0.0-alpha.3" />
<PackageVersion Include="DotNetCampus.Telescope" Version="1.0.0-alpha.3" />
<PackageReference Include="DotNetCampus.Telescope" />
paket add DotNetCampus.Telescope --version 1.0.0-alpha.3
#r "nuget: DotNetCampus.Telescope, 1.0.0-alpha.3"
#:package DotNetCampus.Telescope@1.0.0-alpha.3
#addin nuget:?package=DotNetCampus.Telescope&version=1.0.0-alpha.3&prerelease
#tool nuget:?package=DotNetCampus.Telescope&version=1.0.0-alpha.3&prerelease
Telescope
Telescope 是一套基于 Roslyn 增量源生成器的预编译框架。
| 中文 | English |
|---|
当项目安装 DotNetCampus.Telescope NuGet 包后,即可在编译期自动扫描并导出程序集中的类型与特性元数据,将耗时的运行时反射迁移到编译期执行,大幅度提升应用程序启动与运行性能。
| Package | NuGet |
|---|---|
| DotNetCampus.Telescope |
支持的目标框架:net6.0、netstandard2.0、net45。
安装
<PackageReference Include="DotNetCampus.Telescope" Version="1.0.0" />
DotNetCampus.Telescope 单个 NuGet 包同时包含运行时类型与 Roslyn 增量源生成器,不再需要分别安装 TelescopeSource 或独立的分析器包。
用法
支持两种导出写法:
1. 分部方法式(推荐)
在分部类里定义分部方法,标记 [TelescopeExport] 特性,并在返回值元组中声明导出条件:
using DotNetCampus.Telescope;
internal partial class Program
{
[TelescopeExport]
private static partial IEnumerable<(Type type, F1Attribute attribute, Func<Base> creator)> ExportFooEnumerable();
}
以上代码会在编译期导出当前项目中标记了 F1Attribute 且继承自 Base 的所有非抽象类型,源生成器会自动补全该分部方法的实现:
internal partial class Program
{
private static partial global::System.Collections.Generic.IEnumerable<(global::System.Type type, global::Demo.F1Attribute attribute, global::System.Func<global::Demo.Base> creator)> ExportFooEnumerable()
{
yield return (typeof(global::Demo.F2), new global::Demo.F1Attribute(), () => new global::Demo.F2());
yield return (typeof(global::Demo.F3), new global::Demo.F1Attribute(), () => new global::Demo.F3());
}
}
如果不限制特性,只需导出继承自 Base 的所有类型,可省略元组中的特性项:
[TelescopeExport]
private static partial IEnumerable<(Type type, Func<Base> creator)> ExportAllSubTypes();
扫描引用程序集
在 TelescopeExportAttribute 上设置 IncludeReferences = true 可一并导出所有引用程序集中满足条件的类型:
internal partial class Program
{
[TelescopeExport(IncludeReferences = true)]
private static partial IEnumerable<(Type type, F1Attribute attribute, Func<Base> creator)> ExportFooEnumerable();
}
仅推荐在入口程序集启用 IncludeReferences = true,因为任何引用程序集的变更都会触发源生成器重新执行。
2. 程序集特性式(MarkExport + AttributedTypes)
在需要导出类型的项目中添加程序集级 [assembly: MarkExport(...)] 特性:
using DotNetCampus.Telescope;
[assembly: MarkExport(typeof(Base), typeof(FooAttribute))]
源生成器会在编译期自动生成 DotNetCampus.Telescope.__AttributedTypesExport__,运行时可通过 AttributedTypes.FromAssembly 跨程序集读取:
using DotNetCampus.Telescope;
var exportedTypes = AttributedTypes.FromAssembly<Base, FooAttribute>(typeof(Program).Assembly);
foreach (var metadata in exportedTypes)
{
Console.WriteLine(metadata.RealType.FullName);
var instance = metadata.CreateInstance();
}
为此项目开发
非常期望你能加入到 Telescope 的开发中来,请阅读 如何为 Telescope 贡献代码 了解开发相关的约定和技术要求。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DotNetCampus.Telescope:
| Package | Downloads |
|---|---|
|
dotnetCampus.TelescopeTask
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.3 | 59 | 11/26/2026 |
| 0.10.7-alpha22 | 456 | 11/20/2025 |
| 0.10.7-alpha21 | 177 | 1/29/2024 |
| 0.10.7-alpha20 | 202 | 12/7/2023 |
| 0.10.7-alpha19 | 174 | 11/14/2023 |
| 0.10.7-alpha17 | 162 | 9/4/2023 |
| 0.10.7-alpha16 | 180 | 8/30/2023 |
| 0.10.7-alpha15 | 177 | 8/29/2023 |