Skip to content

Commit

Permalink
1.1.0.1 released #4
Browse files Browse the repository at this point in the history
  • Loading branch information
vipwan committed Nov 5, 2023
1 parent b669a6f commit c82ebfa
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Biwen.AutoClassGen.Gen/Biwen.AutoClassGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisLevel>6.0-all</AnalysisLevel>
<Authors>万雅虎</Authors>
<PackageVersion>1.1.0.0</PackageVersion>
<PackageVersion>1.1.0.1</PackageVersion>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -23,7 +23,7 @@
<Copyright>MIT</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>Roslyn,SourceGenerator,QuickApi</PackageTags>
<PackageReleaseNotes>提供对DTO的Gen支持</PackageReleaseNotes>
<PackageReleaseNotes>提供对DTO的Gen支持,提供简单的Mapper</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/vipwan/Biwen.AutoClassGen</PackageProjectUrl>
</PropertyGroup>

Expand Down
11 changes: 10 additions & 1 deletion Biwen.AutoClassGen.Gen/SourceGenAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,17 @@ public override void Initialize(AnalysisContext context)
ctx.ReportDiagnostic(Diagnostic.Create(InvalidDeclareNameError, location));
}

//NamespaceDeclarationSyntax
if (declaration.Parent is NamespaceDeclarationSyntax @namespace &&
@namespace?.Name.ToString() != arg1.GetText().ToString().Replace("\"", ""))
@namespace?.Name.ToString() != arg1?.GetText().ToString().Replace("\"", ""))
{
var location = arg1?.GetLocation();
// issue warning
ctx.ReportDiagnostic(Diagnostic.Create(SuggestDeclareNameWarning, location));
}
//FileScopedNamespaceDeclaration
if (declaration.Parent is FileScopedNamespaceDeclarationSyntax @namespace2 &&
@namespace2?.Name.ToString() != arg1?.GetText().ToString().Replace("\"", ""))
{
var location = arg1?.GetLocation();
// issue warning
Expand Down
29 changes: 20 additions & 9 deletions Biwen.AutoClassGen.Gen/SourceGenCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
//var @namespace = root.Parent?.AncestorsAndSelf().OfType<NamespaceDeclarationSyntax>().First().Name.ToString();

var rootCompUnit = (CompilationUnitSyntax)root;
var @namespace = ((rootCompUnit.Members.Where(m => m.IsKind(SyntaxKind.NamespaceDeclaration)).Single()) as NamespaceDeclarationSyntax)?.Name.ToString();

// Register a code action that will invoke the fix.
CodeAction action = CodeAction.Create(
"GEN:使用推荐的命名空间",
c => ReplaceWithNameOfAsync(context.Document, nodeToReplace, @namespace!, c),
equivalenceKey: nameof(SourceGenCodeFixProvider));
context.RegisterCodeFix(action, diagnostic);
var @namespace = (rootCompUnit.Members.Where(m => m.IsKind(SyntaxKind.NamespaceDeclaration)).FirstOrDefault() as NamespaceDeclarationSyntax)?.Name.ToString();
if (string.IsNullOrEmpty(@namespace))
{
@namespace = (rootCompUnit.Members.Where(m => m.IsKind(SyntaxKind.FileScopedNamespaceDeclaration)).FirstOrDefault() as FileScopedNamespaceDeclarationSyntax)?.Name.ToString();
}
if (!string.IsNullOrEmpty(@namespace))
{
// Register a code action that will invoke the fix.
CodeAction action = CodeAction.Create(
"GEN:使用推荐的命名空间",
c => ReplaceWithNameOfAsync(context.Document, nodeToReplace, @namespace!, c),
equivalenceKey: nameof(SourceGenCodeFixProvider));
context.RegisterCodeFix(action, diagnostic);
}
}
else if (diagnostic.Id == SourceGenAnalyzer.GEN011)
{
Expand Down Expand Up @@ -159,7 +165,12 @@ private static async Task<Document> AddAttributeAsync(Document document, SyntaxN
var rootCompUnit = (CompilationUnitSyntax)root!;
//命名空间
var @namespace = ((rootCompUnit.Members.Where(
m => m.IsKind(SyntaxKind.NamespaceDeclaration)).Single()) as NamespaceDeclarationSyntax)?.Name.ToString();
m => m.IsKind(SyntaxKind.NamespaceDeclaration)).FirstOrDefault()) as NamespaceDeclarationSyntax)?.Name.ToString();
if (string.IsNullOrEmpty(@namespace))
{
@namespace = ((rootCompUnit.Members.Where(
m => m.IsKind(SyntaxKind.FileScopedNamespaceDeclaration)).FirstOrDefault()) as FileScopedNamespaceDeclarationSyntax)?.Name.ToString();
}
//类名
var @class = "YourClassName";

Expand Down
28 changes: 13 additions & 15 deletions Biwen.AutoClassGen.TestConsole/Classes.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using Biwen.AutoClassGen.TestConsole.Interfaces;

namespace Biwen.AutoClassGen.Models
{
namespace Biwen.AutoClassGen.Models;

/// <summary>
/// 分页请求
/// </summary>
[AutoGen("QueryRequest", "Biwen.AutoClassGen.Models")]
[AutoGen("Query2Request", "Biwen.AutoClassGen.Models")]
public interface IQueryRequest : IPager, IQuery
{
}

[AutoGen("TenantRealRequest", "Biwen.AutoClassGen.Models")]
public interface ITenantRealRequest : ITenantRequest
{
/// <summary>
/// 分页请求
/// </summary>
[AutoGen("QueryRequest", "Biwen.AutoClassGen.Models")]
[AutoGen("Query2Request", "Biwen.AutoClassGen.Models")]
public interface IQueryRequest : IPager, IQuery
{
}

}
[AutoGen("TenantRealRequest", "Biwen.AutoClassGen.Models")]
public interface ITenantRealRequest : ITenantRequest
{

}
}
2 changes: 2 additions & 0 deletions Biwen.AutoClassGen.TestConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
KeyWord = "biwen"
};



Biwen.AutoClassGen.TestConsole.Dtos.UserDto userDto2 = new()
{
FirstName = "biwen",
Expand Down

0 comments on commit c82ebfa

Please sign in to comment.