Skip to content

Commit

Permalink
如果不存在任何导出内容,则不创建代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Nov 14, 2023
1 parent cd16583 commit 65990f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class ExportedTypesCodeTextGenerator
{
public string Generate(ImmutableArray<MarkClassParseResult> markClassCollection, CancellationToken token)
{
if (markClassCollection.Length == 0)
{
// 如果没有任何需要导出的类型,那就不要创建任何代码
return string.Empty;
}

// 导出的接口
var exportedInterfaces = new List<string>();
// 导出的方法
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using dotnetCampus.Telescope;
using dotnetCampus.Telescope.SourceGeneratorAnalyzers.Demo;

[assembly: MarkExport(typeof(Base), typeof(FooAttribute))]
//[assembly: MarkExport(typeof(Base), typeof(FooAttribute))]
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ static void Main(string[] args)
{
}

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

[dotnetCampus.Telescope.TelescopeExportAttribute(IncludeReferences = true)]
Expand Down

0 comments on commit 65990f9

Please sign in to comment.