XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.AutoImplement

【DLL】自动生成实现类

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.AutoImplement

fix-修复了不能实现泛型类的bug fix-修复了泛型类无法继承泛型约束条件的bug

c40b480
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

6 个文件 +64 -17
Modified XFEExtension.NetCore.AutoImplement.Analyzer/Generator/ImplementAutoGenerator.cs +14 -6
@@ -44,14 +44,13 @@ namespace XFEExtension.NetCore.AutoImplement.Analyzer.Generator
44 44 {
45 45 implementationClass = SyntaxFactory.ClassDeclaration($"{className}Impl")
46 46 .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.SealedKeyword))
47 .AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(className)))
48 47 .AddMembers(classDeclaration.Members.OfType<ConstructorDeclarationSyntax>().Select(constructor =>
49 48 {
50 49 return SyntaxFactory.ConstructorDeclaration($"{className}Impl")
51 .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword))
52 .WithBody(SyntaxFactory.Block())
53 .WithParameterList(constructor.ParameterList)
54 .WithInitializer(SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(constructor.ParameterList.Parameters.Select(parameter => SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameter.Identifier)))))));
50 .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword))
51 .WithBody(SyntaxFactory.Block())
52 .WithParameterList(constructor.ParameterList)
53 .WithInitializer(SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(constructor.ParameterList.Parameters.Select(parameter => SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameter.Identifier)))))));
55 54 }).ToArray())
56 55 .WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
57 56 /// <seealso cref=""{className}Impl""/> 是根据 <seealso cref=""{className}""/> 自动生成的实现类
@@ -63,7 +62,6 @@ namespace XFEExtension.NetCore.AutoImplement.Analyzer.Generator
63 62 {
64 63 implementationClass = SyntaxFactory.ClassDeclaration($"{className}Impl")
65 64 .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword))
66 .AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(className)))
67 65 .AddMembers(SyntaxFactory.ConstructorDeclaration($"{className}Impl")
68 66 .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword))
69 67 .WithBody(SyntaxFactory.Block())
@@ -75,6 +73,16 @@ namespace XFEExtension.NetCore.AutoImplement.Analyzer.Generator
75 73 "))
76 74 .NormalizeWhitespace();
77 75 }
76 if (classDeclaration.TypeParameterList is TypeParameterListSyntax typeParameterListSyntax && typeParameterListSyntax.Parameters.Count > 0)
77 {
78 implementationClass = implementationClass.AddTypeParameterListParameters(typeParameterListSyntax.Parameters.ToArray())
79 .AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName($"{className}{typeParameterListSyntax}")))
80 .AddConstraintClauses(classDeclaration.ConstraintClauses.ToArray());
81 }
82 else
83 {
84 implementationClass = implementationClass.AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(className)));
85 }
78 86 MemberDeclarationSyntax memberDeclaration;
79 87 if (fileScopedNamespaceDeclarationSyntax is null)
80 88 {
Added XFEExtension.NetCore.AutoImplement.Test/MyTestClass.cs +8 -0
@@ -0,0 +1,8 @@
1 namespace XFEExtension.NetCore.AutoImplement.Test;
2
3 [CreateImpl]
4 public abstract class MyTestClass<T, F>(T obj, F obj2) where T : class where F : new()
5 {
6 public T TProperty { get; set; } = obj;
7 public F FProperty { get; set; } = obj2;
8 }
Added XFEExtension.NetCore.AutoImplement.Test/Program.cs +5 -0
@@ -0,0 +1,5 @@
1 // See https://aka.ms/new-console-template for more information
2 using XFEExtension.NetCore.AutoImplement.Test;
3
4 Console.WriteLine("Hello, World!");
5 var myClass = new MyTestClassImpl<string, Program>("123", new());
Added XFEExtension.NetCore.AutoImplement.Test/XFEExtension.NetCore.AutoImplement.Test.csproj +14 -0
@@ -0,0 +1,14 @@
1 <Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <OutputType>Exe</OutputType>
5 <TargetFramework>net8.0</TargetFramework>
6 <ImplicitUsings>enable</ImplicitUsings>
7 <Nullable>enable</Nullable>
8 </PropertyGroup>
9
10 <ItemGroup>
11 <ProjectReference Include="..\XFEExtension.NetCore.AutoImplement\XFEExtension.NetCore.AutoImplement.csproj" />
12 <ProjectReference Include="..\XFEExtension.NetCore.AutoImplement.Analyzer\XFEExtension.NetCore.AutoImplement.Analyzer.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
13 </ItemGroup>
14 </Project>
Modified XFEExtension.NetCore.AutoImplement.sln +20 -10
@@ -9,25 +9,35 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XFEExtension.NetCore.AutoIm
9 9 EndProject
10 10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XFEExtension.NetCore.AutoImplement.Analyzer", "XFEExtension.NetCore.AutoImplement.Analyzer\XFEExtension.NetCore.AutoImplement.Analyzer.csproj", "{BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}"
11 11 EndProject
12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XFEExtension.NetCore.AutoImplement.Test", "XFEExtension.NetCore.AutoImplement.Test\XFEExtension.NetCore.AutoImplement.Test.csproj", "{F13BFA6A-CD15-412E-9881-F53DE89215E3}"
13 ProjectSection(ProjectDependencies) = postProject
14 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2} = {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}
15 {E74B6938-9516-4211-88EB-5C68EB76FD62} = {E74B6938-9516-4211-88EB-5C68EB76FD62}
16 EndProjectSection
17 EndProject
12 18 Global
13 GlobalSection(ExtensibilityGlobals) = postSolution
14 SolutionGuid = {3C237470-3400-4B76-862D-63B1608FE3D8}
19 GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 Debug|Any CPU = Debug|Any CPU
21 Release|Any CPU = Release|Any CPU
15 22 EndGlobalSection
16 23 GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Release|Any CPU.Build.0 = Release|Any CPU
21 24 {E74B6938-9516-4211-88EB-5C68EB76FD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 25 {E74B6938-9516-4211-88EB-5C68EB76FD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 26 {E74B6938-9516-4211-88EB-5C68EB76FD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 27 {E74B6938-9516-4211-88EB-5C68EB76FD62}.Release|Any CPU.Build.0 = Release|Any CPU
25 EndGlobalSection
26 GlobalSection(SolutionConfigurationPlatforms) = preSolution
27 Debug|Any CPU = Debug|Any CPU
28 Release|Any CPU = Release|Any CPU
28 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 {BECB5988-CA6E-471E-AFE8-C8416BC5A9B2}.Release|Any CPU.Build.0 = Release|Any CPU
32 {F13BFA6A-CD15-412E-9881-F53DE89215E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 {F13BFA6A-CD15-412E-9881-F53DE89215E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 {F13BFA6A-CD15-412E-9881-F53DE89215E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 {F13BFA6A-CD15-412E-9881-F53DE89215E3}.Release|Any CPU.Build.0 = Release|Any CPU
29 36 EndGlobalSection
30 37 GlobalSection(SolutionProperties) = preSolution
31 38 HideSolutionNode = FALSE
32 39 EndGlobalSection
40 GlobalSection(ExtensibilityGlobals) = postSolution
41 SolutionGuid = {3C237470-3400-4B76-862D-63B1608FE3D8}
42 EndGlobalSection
33 43 EndGlobal
Modified XFEExtension.NetCore.AutoImplement/XFEExtension.NetCore.AutoImplement.csproj +3 -1
@@ -5,6 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8 <Version>1.0.1</Version>
8 9 <Title>AutoImplement</Title>
9 10 <Authors>XFEstudio</Authors>
10 11 <Company>寰宇朽力网络科技有限公司</Company>
@@ -15,7 +16,8 @@
15 16 <PackageReadmeFile>README.md</PackageReadmeFile>
16 17 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.AutoImplement.git</RepositoryUrl>
17 18 <PackageTags>XFE;impl;implement;auto</PackageTags>
18 <PackageReleaseNotes>First Release</PackageReleaseNotes>
19 <PackageReleaseNotes>修复了不能实现泛型类的bug
20 修复了泛型类无法继承泛型约束条件的bug</PackageReleaseNotes>
19 21 <PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
20 22 <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
21 23 </PropertyGroup>