From 65990f92ffda1ca7a204414907f3c8811f9dcc0a Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 14 Nov 2023 17:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E4=BB=BB=E4=BD=95=E5=AF=BC=E5=87=BA=E5=86=85=E5=AE=B9=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E4=B8=8D=E5=88=9B=E5=BB=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/dotnet-campus/SourceFusion/issues/41 --- .../Core/ExportedTypesCodeTextGenerator.cs | 6 ++++++ .../TelescopeSourceGeneratorDemo/AssemblyInfo.cs | 2 +- .../Demo/TelescopeSourceGeneratorDemo/Program.cs | 14 +++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/TelescopeSourceGenerator/Analyzers/Core/ExportedTypesCodeTextGenerator.cs b/src/TelescopeSourceGenerator/Analyzers/Core/ExportedTypesCodeTextGenerator.cs index 6bd4979..5a7ffc4 100644 --- a/src/TelescopeSourceGenerator/Analyzers/Core/ExportedTypesCodeTextGenerator.cs +++ b/src/TelescopeSourceGenerator/Analyzers/Core/ExportedTypesCodeTextGenerator.cs @@ -11,6 +11,12 @@ class ExportedTypesCodeTextGenerator { public string Generate(ImmutableArray markClassCollection, CancellationToken token) { + if (markClassCollection.Length == 0) + { + // 如果没有任何需要导出的类型,那就不要创建任何代码 + return string.Empty; + } + // 导出的接口 var exportedInterfaces = new List(); // 导出的方法 diff --git a/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/AssemblyInfo.cs b/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/AssemblyInfo.cs index 419ea61..4b47e23 100644 --- a/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/AssemblyInfo.cs +++ b/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/AssemblyInfo.cs @@ -1,4 +1,4 @@ using dotnetCampus.Telescope; using dotnetCampus.Telescope.SourceGeneratorAnalyzers.Demo; -[assembly: MarkExport(typeof(Base), typeof(FooAttribute))] +//[assembly: MarkExport(typeof(Base), typeof(FooAttribute))] diff --git a/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/Program.cs b/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/Program.cs index 3e1a141..993d7ee 100644 --- a/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/Program.cs +++ b/src/TelescopeSourceGenerator/Demo/TelescopeSourceGeneratorDemo/Program.cs @@ -10,13 +10,13 @@ static void Main(string[] args) { } - var attributedTypesExport = new __AttributedTypesExport__(); - ICompileTimeAttributedTypesExporter exporter = attributedTypesExport; - foreach (var exportedTypeMetadata in exporter.ExportAttributeTypes()) - { - // 输出导出的类型 - Console.WriteLine(exportedTypeMetadata.RealType.FullName); - } + //var attributedTypesExport = new __AttributedTypesExport__(); + //ICompileTimeAttributedTypesExporter exporter = attributedTypesExport; + //foreach (var exportedTypeMetadata in exporter.ExportAttributeTypes()) + //{ + // // 输出导出的类型 + // Console.WriteLine(exportedTypeMetadata.RealType.FullName); + //} } [dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReferences = true)]