{"id":28579050,"url":"https://github.com/dotnet-campus/telescope","last_synced_at":"2025-06-28T19:35:04.769Z","repository":{"id":220443714,"uuid":"751647541","full_name":"dotnet-campus/Telescope","owner":"dotnet-campus","description":"Telescope 是一套预编译框架，可以帮助你将耗时的运行时代码迁移到编译期执行，大幅度提升运行时性能","archived":false,"fork":false,"pushed_at":"2024-02-07T08:16:57.000Z","size":489,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-04-28T06:00:37.867Z","etag":null,"topics":["dotnet","roslyn","sourcegenerator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotnet-campus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-02T02:45:22.000Z","updated_at":"2024-03-07T05:03:21.000Z","dependencies_parsed_at":"2024-02-02T04:29:55.691Z","dependency_job_id":"39aeffbe-692e-4614-84ef-21d8b6df5c00","html_url":"https://github.com/dotnet-campus/Telescope","commit_stats":null,"previous_names":["dotnet-campus/telescope"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-campus%2FTelescope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-campus%2FTelescope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-campus%2FTelescope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-campus%2FTelescope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotnet-campus","download_url":"https://codeload.github.com/dotnet-campus/Telescope/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-campus%2FTelescope/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259182549,"owners_count":22818116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","roslyn","sourcegenerator"],"created_at":"2025-06-11T01:37:55.792Z","updated_at":"2025-06-11T01:38:07.792Z","avatar_url":"https://github.com/dotnet-campus.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telescope\n\nTelescope 是一套预编译框架。\n\n|[中文](README.md)|[English](docs/en-us/README.md)|\n|-|-|\n\n当项目安装 Telescope 了之后，项目中即可开始书写预编译代码。通过执行这些预编译代码，项目可以在编译期间执行一些平时需要在运行时执行的代码。这种方式能够将耗时的运行时代码迁移到编译期执行，大幅度提升运行时性能。\n\n![](https://github.com/dotnet-campus/Telescope/workflows/.NET%20Core/badge.svg)\n\n|Package|NuGet|\n|--|--|\n|Telescope|[![](https://img.shields.io/nuget/v/dotnetCampus.Telescope.svg)](https://www.nuget.org/packages/dotnetCampus.Telescope)|\n|Telescope.SourceGeneratorAnalyzers|[![](https://img.shields.io/nuget/v/dotnetCampus.Telescope.SourceGeneratorAnalyzers.svg)](https://www.nuget.org/packages/dotnetCampus.Telescope.SourceGeneratorAnalyzers)|\n\n## Telescope.SourceGeneratorAnalyzers\n\n使用 SourceGenerator 源代码生成器的 Telescope 版本\n\n可以用来导出指定类型\n\n### 用法\n\n支持多个不同的导出写法\n\n#### 分部方法式\n\n这是推荐的方法\n\n在分部类里定义分部方法，分部方法标记 `dotnetCampus.Telescope.TelescopeExportAttribute` 特性，且返回值包括导出条件，如以下写法\n\n```csharp\ninternal partial class Program\n{\n    [dotnetCampus.Telescope.TelescopeExportAttribute()]\n    private static partial IEnumerable\u003c(Type type, F1Attribute attribute, Func\u003cBase\u003e creator)\u003e ExportFooEnumerable();\n}\n```\n\n以上代码将导出当前项目标记了 `F1Attribute` 且继承 `Base` 的所有类型。经过 Telescope 源代码生成器即可生成大概如下的代码\n\n```csharp\n    [global::System.CodeDom.Compiler.GeneratedCode(\"dotnetCampus.Telescope.SourceGeneratorAnalyzers\", \"1.0.0\")]\n    internal partial class Program\n    {\n        private static partial IEnumerable\u003c(Type type, F1Attribute attribute, Func\u003cBase\u003e creator)\u003e ExportFooEnumerable()\n        {\n            yield return (typeof(F2), new F1Attribute()\n            {\n                       \n            }, () =\u003e new F2());\n            yield return (typeof(F3), new F1Attribute()\n            {\n                       \n            }, () =\u003e new F3());\n        }\n    }\n```\n\n高级用法：\n\n可以在 TelescopeExportAttribute 加上 IncludeReference 属性用来导出所有引用程序集的满足条件的类型，如以下代码\n\n```csharp\ninternal partial class Program\n{\n    [dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReference = true)]\n    private static partial IEnumerable\u003c(Type type, F1Attribute attribute, Func\u003cBase\u003e creator)\u003e ExportFooEnumerable();\n}\n```\n\n仅推荐在入口程序集加上 `IncludeReference = true` 属性，因为一旦加入此属性，任何引用程序集的变更都可能导致源代码生成器重复执行，降低 VisualStudio 性能\n\n#### 程序集标记\n\n这是传统的 Telescope 实现方法，在需要导出类型的项目里标记 `dotnetCampus.Telescope.MarkExportAttribute` 特性，如以下代码\n\n```csharp\n[assembly: dotnetCampus.Telescope.MarkExportAttribute(typeof(Base), typeof(FooAttribute))]\n```\n\n标记之后将会自动生成 `dotnetCampus.Telescope.__AttributedTypesExport__` 类型，即可在代码里面直接使用，如以下代码\n\n```csharp\n        var attributedTypesExport = new __AttributedTypesExport__();\n        ICompileTimeAttributedTypesExporter\u003cBase, FooAttribute\u003e exporter = attributedTypesExport;\n        foreach (var exportedTypeMetadata in exporter.ExportAttributeTypes())\n        {\n            // 输出导出的类型\n            Console.WriteLine(exportedTypeMetadata.RealType.FullName);\n        }\n```\n\n也可以使用 `dotnetCampus.Telescope.AttributedTypes` 辅助类获取所有导出类型\n\n## 为此项目开发\n\n非常期望你能加入到 Telescope 的开发中来，请阅读 [如何为 Telescope 贡献代码](/docs/zh-hans/how-to-contribute.md) 了解开发相关的约定和技术要求。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet-campus%2Ftelescope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotnet-campus%2Ftelescope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet-campus%2Ftelescope/lists"}