-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/context aware injection generator #147
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78af119
feat(generator): 添加上下文感知注入源码生成器
GeWuYou ee2936e
refactor(generator): 重构上下文获取生成器的代码结构
GeWuYou 7964085
refactor(generators): 优化ContextGetGenerator代码结构并改进异常处理
GeWuYou b5ac8b2
refactor(core): 重构上下文感知服务扩展以改进组件获取逻辑
GeWuYou 6e3954e
docs(GFramework.Core): 更新 ContextAwareServiceExtensions 文档注释
GeWuYou 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetAllAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记类需要自动推断并注入上下文相关字段。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetAllAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetModelAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入单个模型实例。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetModelAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetModelsAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入模型集合。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetModelsAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetServiceAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入单个服务实例。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetServiceAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetServicesAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入服务集合。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetServicesAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetSystemAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入单个系统实例。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetSystemAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetSystemsAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入系统集合。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetSystemsAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetUtilitiesAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入工具集合。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetUtilitiesAttribute : Attribute | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
GFramework.SourceGenerators.Abstractions/Rule/GetUtilityAttribute.cs
This file contains hidden or 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,9 @@ | ||
| namespace GFramework.SourceGenerators.Abstractions.Rule; | ||
|
|
||
| /// <summary> | ||
| /// 标记字段需要自动注入单个工具实例。 | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | ||
| public sealed class GetUtilityAttribute : Attribute | ||
| { | ||
| } |
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
GFramework.SourceGenerators.Common/Extensions/ITypeSymbolExtensions.cs
This file contains hidden or 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,39 @@ | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace GFramework.SourceGenerators.Common.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// 提供 <see cref="ITypeSymbol" /> 的通用符号判断扩展。 | ||
| /// </summary> | ||
| public static class ITypeSymbolExtensions | ||
| { | ||
| /// <summary> | ||
| /// 判断当前类型是否等于或实现/继承目标类型。 | ||
| /// </summary> | ||
| /// <param name="typeSymbol">当前类型符号。</param> | ||
| /// <param name="targetType">目标类型符号。</param> | ||
| /// <returns>若等于、实现或继承则返回 <c>true</c>。</returns> | ||
| public static bool IsAssignableTo( | ||
| this ITypeSymbol typeSymbol, | ||
| INamedTypeSymbol? targetType) | ||
| { | ||
| if (targetType is null) | ||
| return false; | ||
|
|
||
| if (SymbolEqualityComparer.Default.Equals(typeSymbol, targetType)) | ||
| return true; | ||
|
|
||
| if (typeSymbol is INamedTypeSymbol namedType) | ||
| { | ||
| if (namedType.AllInterfaces.Any(i => | ||
| SymbolEqualityComparer.Default.Equals(i, targetType))) | ||
| return true; | ||
|
|
||
| for (var current = namedType.BaseType; current is not null; current = current.BaseType) | ||
| if (SymbolEqualityComparer.Default.Equals(current, targetType)) | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
GFramework.SourceGenerators.Common/Info/FieldCandidateInfo.cs
This file contains hidden or 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,14 @@ | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
|
||
| namespace GFramework.SourceGenerators.Common.Info; | ||
|
|
||
| /// <summary> | ||
| /// 表示字段级生成器候选成员。 | ||
| /// </summary> | ||
| /// <param name="Variable">字段变量语法节点。</param> | ||
| /// <param name="FieldSymbol">字段符号。</param> | ||
| public sealed record FieldCandidateInfo( | ||
| VariableDeclaratorSyntax Variable, | ||
| IFieldSymbol FieldSymbol | ||
| ); |
14 changes: 14 additions & 0 deletions
14
GFramework.SourceGenerators.Common/Info/TypeCandidateInfo.cs
This file contains hidden or 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,14 @@ | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
|
||
| namespace GFramework.SourceGenerators.Common.Info; | ||
|
|
||
| /// <summary> | ||
| /// 表示类型级生成器候选成员。 | ||
| /// </summary> | ||
| /// <param name="Declaration">类型声明语法节点。</param> | ||
| /// <param name="TypeSymbol">类型符号。</param> | ||
| public sealed record TypeCandidateInfo( | ||
| ClassDeclarationSyntax Declaration, | ||
| INamedTypeSymbol TypeSymbol | ||
| ); |
20 changes: 20 additions & 0 deletions
20
GFramework.SourceGenerators.Common/Internals/IsExternalInit.cs
This file contains hidden or 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,20 @@ | ||
| // IsExternalInit.cs | ||
| // This type is required to support init-only setters and record types | ||
| // when targeting netstandard2.0 or older frameworks. | ||
|
|
||
| #if !NET5_0_OR_GREATER | ||
| using System.ComponentModel; | ||
|
|
||
| // ReSharper disable CheckNamespace | ||
|
|
||
| namespace System.Runtime.CompilerServices; | ||
|
|
||
| /// <summary> | ||
| /// 提供一个占位符类型,用于支持 C# 9.0 的 init 访问器功能。 | ||
| /// 该类型在 .NET 5.0 及更高版本中已内置,因此仅在较低版本的 .NET 中定义。 | ||
| /// </summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| internal static class IsExternalInit | ||
| { | ||
| } | ||
| #endif |
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.
Uh oh!
There was an error while loading. Please reload this page.