-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
源代码生成类型的方法导出功能 #39
Merged
Merged
源代码生成类型的方法导出功能 #39
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
011ab8a
测试读取程序集里面所有其他的内容
lindexi 70e7c50
Revert "测试读取程序集里面所有其他的内容"
lindexi bf051cb
加上对方法导出的定义
lindexi b64eaf0
Merge branch 'master' of github.com:dotnet-campus/SourceFusion into t…
lindexi 65fbd69
收集定义的方法
lindexi 32e9c59
完成收集项目的所有类型
lindexi 605cdd9
判断项目里面的类型是否符合预期
lindexi 3563746
修复判断逻辑
lindexi 9f15fe3
Merge branch 'master' of github.com:dotnet-campus/SourceFusion into t…
lindexi 342abc7
尝试实现导出方法
lindexi 951d48e
合并代码
lindexi e9eec05
尝试修复构建
lindexi 5ad0a3a
完成读取配置的属性
lindexi 10977ce
定义 ValueTuple 的转换代码
lindexi 85bba4c
尝试添加转换代码
lindexi cd661f9
整理文件
lindexi 12c0a0a
拆分代码
lindexi 956cfc0
封装辅助方法
lindexi bc4d8f1
支持读取整个程序集
lindexi fa12b86
修复取错期望继承类型
lindexi fd882bf
添加更多测试代码
lindexi 423ce81
减少创建大量对象
lindexi a35a4d0
完成生成代码
lindexi e601998
修复判断
lindexi 8ac604d
整理辅助代码
lindexi 00f469d
修改代码格式化
lindexi 66825b1
修复空格
lindexi e0e3c28
修复循环引用
lindexi f464e1d
修复特性丢失字符串
lindexi 31d8a81
防止加上不可见的类型
lindexi fb32ef0
修复判定逻辑
lindexi 5539984
修复布尔值
lindexi 4499016
优化代码格式
lindexi 4517a81
删除不使用代码
lindexi 4013936
修改注释
lindexi bd81630
提供辅助方法
lindexi 12ff430
更新打包方法
lindexi b015756
优化打包方法
lindexi 9e402aa
提升 VisualStudio 性能
lindexi 659c3f6
删除调试代码
lindexi 3a88719
拆分代码
lindexi fb91d7a
拆分返回值实现方法
lindexi 16800d8
定义源代码生成静态类
lindexi 592aafd
支持创建单独的类型
lindexi 30dca58
拆分代码创建
lindexi 2db8be6
删除不使用代码
lindexi 6aa457b
加上智能提示功能
lindexi 61aba68
支持静态
lindexi b9804d1
准备发布
lindexi a347ab7
提升性能
lindexi dde5876
修改命名
lindexi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/TelescopeSourceGenerator/Analyzers/Core/AccessibilityHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.CodeAnalysis; | ||
using System; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Core; | ||
|
||
static class AccessibilityHelper | ||
{ | ||
public static string ToCSharpCode(this Accessibility accessibility) | ||
=> accessibility switch | ||
{ | ||
Accessibility.Public => "public", | ||
Accessibility.Private => "private", | ||
Accessibility.Internal => "internal", | ||
Accessibility.Protected => "protected", | ||
Accessibility.ProtectedAndInternal => "private protected", | ||
_ => string.Empty | ||
}; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/TelescopeSourceGenerator/Analyzers/Core/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Core; | ||
|
||
internal static class AssemblyInfo | ||
{ | ||
public static string ToolName => | ||
Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product; | ||
|
||
public static string ToolVersion => | ||
Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>() | ||
.InformationalVersion; | ||
|
||
/// <summary> | ||
/// 如果需要为类加上 <see cref="System.CodeDom.Compiler.GeneratedCodeAttribute"/>,则使用此字符串。 | ||
/// </summary> | ||
public static string GeneratedCodeAttribute => | ||
$@"[global::System.CodeDom.Compiler.GeneratedCode(""{ToolName}"", ""{ToolVersion}"")]"; | ||
|
||
/// <summary> | ||
/// 获取可以为每一个生成的文件都增加的文件头。 | ||
/// </summary> | ||
public const string GeneratedCodeComment = | ||
$@"//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// 此代码由工具生成。 | ||
// | ||
// 对此文件的更改可能会导致不正确的行为,并且如果 | ||
// 重新生成代码,这些更改将会丢失。 | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#define GENERATED_CODE | ||
|
||
"; | ||
} | ||
87 changes: 87 additions & 0 deletions
87
src/TelescopeSourceGenerator/Analyzers/Core/AssemblySymbolHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Core; | ||
|
||
static class AssemblySymbolHelper | ||
{ | ||
public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbol(IAssemblySymbol assemblySymbol) => GetAllTypeSymbol(assemblySymbol.GlobalNamespace); | ||
lindexi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static IEnumerable<INamedTypeSymbol> GetAllTypeSymbol(INamespaceSymbol namespaceSymbol) | ||
lindexi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var typeMemberList = namespaceSymbol.GetTypeMembers(); | ||
|
||
foreach (var typeSymbol in typeMemberList) | ||
{ | ||
yield return typeSymbol; | ||
} | ||
|
||
foreach (var namespaceMember in namespaceSymbol.GetNamespaceMembers()) | ||
{ | ||
foreach (var typeSymbol in GetAllTypeSymbol(namespaceMember)) | ||
{ | ||
yield return typeSymbol; | ||
} | ||
} | ||
} | ||
|
||
public static bool IsReference(IAssemblySymbol currentAssemblySymbol, IAssemblySymbol requiredAssemblySymbol) | ||
{ | ||
var visited = new Dictionary<IAssemblySymbol, bool /*是否引用*/>(SymbolEqualityComparer.Default); | ||
return IsReference(currentAssemblySymbol, requiredAssemblySymbol, visited); | ||
} | ||
|
||
public static bool IsReference(IAssemblySymbol currentAssemblySymbol, IAssemblySymbol requiredAssemblySymbol, | ||
Dictionary<IAssemblySymbol, bool /*是否引用*/> visited) | ||
{ | ||
if (SymbolEqualityComparer.Default.Equals(currentAssemblySymbol, requiredAssemblySymbol)) | ||
{ | ||
// 这个就看业务了,如果两个程序集是相同的,是否判断为引用关系 | ||
return true; | ||
} | ||
|
||
foreach (var moduleSymbol in currentAssemblySymbol.Modules) | ||
{ | ||
foreach (var referencedAssemblySymbol in moduleSymbol.ReferencedAssemblySymbols) | ||
{ | ||
if (SymbolEqualityComparer.Default.Equals(referencedAssemblySymbol, requiredAssemblySymbol)) | ||
{ | ||
// 记录当前程序集存在引用关系 | ||
visited[currentAssemblySymbol] = true; | ||
return true; | ||
} | ||
else if (SymbolEqualityComparer.Default.Equals(referencedAssemblySymbol, currentAssemblySymbol)) | ||
{ | ||
// 循环引用,跳过 | ||
continue; | ||
} | ||
else | ||
{ | ||
if (visited.TryGetValue(referencedAssemblySymbol, out var isReference)) | ||
{ | ||
// 这个是访问过的,那就从字典获取缓存,不需要再访问一次 | ||
// 同时也能解决程序集循环引用问题 | ||
} | ||
else | ||
{ | ||
// 进入递归之前,先将自身设置到字典,先设置为没有引用。防止循环引用炸掉 | ||
visited[referencedAssemblySymbol] = false; | ||
|
||
// 没有访问过的,获取引用的程序集是否存在引用关系 | ||
isReference = IsReference(referencedAssemblySymbol, requiredAssemblySymbol, visited); | ||
visited[referencedAssemblySymbol] = isReference; | ||
} | ||
|
||
if (isReference) | ||
{ | ||
// 如果这个程序集有引用,那也算上 | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/TelescopeSourceGenerator/Analyzers/Core/IncrementalValuesProviderHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Core; | ||
|
||
static class IncrementalValuesProviderHelper | ||
{ | ||
/// <summary> | ||
/// 过滤掉空的值 | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="provider"></param> | ||
/// <returns></returns> | ||
public static IncrementalValuesProvider<T> FilterNull<T>(this IncrementalValuesProvider<T?> provider) | ||
lindexi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return provider.Where(static t => t != null).Select(static (t, _) => t!); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从今天开始,你可以使用 """ 来编写这种代码,对得齐多好