From 10609d6ab46823b2b0f8d9f40156487ad8845fd9 Mon Sep 17 00:00:00 2001 From: KY Date: Thu, 24 Sep 2020 04:54:56 +0200 Subject: [PATCH] Reflection - allow GenerateIgnoreGenericAttribute on methods --- Angular/KY.Generator.Angular.csproj | 2 +- AspDotNet/KY.Generator.AspDotNet.csproj | 2 +- .../Readers/AspDotNetControllerReader.cs | 8 +-- CLI/Properties/AssemblyInfo.cs | 4 +- CLI/nuget.nuspec | 2 +- Core/Extensions/TypeExtension.cs | 21 +++++++- Core/KY.Generator.Core.csproj | 2 +- Csharp/KY.Generator.CSharp.csproj | 2 +- .../KY.Generator.EntityFramework.csproj | 2 +- Json/KY.Generator.Json.csproj | 2 +- Main.Legacy/Properties/AssemblyInfo.cs | 4 +- Main/KY.Generator.csproj | 2 +- Main/nuget.nuspec | 2 +- Main/nuget.targets | 16 +++--- OData/KY.Generator.OData.csproj | 2 +- OpenApi/KY.Generator.OpenApi.csproj | 2 +- ...KY.Generator.Reflection.Annotations.csproj | 2 +- .../GenerateIgnoreGenericAttribute.cs | 2 +- Reflection/KY.Generator.Reflection.csproj | 2 +- .../app/services/weather-forecast.service.ts | 54 +++++++++++++++++++ .../Controllers/WeatherForecastController.cs | 46 ++++++++++++++++ .../Models/IgnoreMe.cs | 20 +++++++ Tsql/KY.Generator.Tsql.csproj | 2 +- TypeScript/KY.Generator.TypeScript.csproj | 2 +- Watchdog/KY.Generator.Watchdog.csproj | 2 +- 25 files changed, 172 insertions(+), 35 deletions(-) diff --git a/Angular/KY.Generator.Angular.csproj b/Angular/KY.Generator.Angular.csproj index 03d888af..917fe44a 100644 --- a/Angular/KY.Generator.Angular.csproj +++ b/Angular/KY.Generator.Angular.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 5.1.2 + 5.2.0 2020 - KY-Programming Angular Module for KY-Generator Download KY.Generator to use this module diff --git a/AspDotNet/KY.Generator.AspDotNet.csproj b/AspDotNet/KY.Generator.AspDotNet.csproj index 7732f768..94be67c9 100644 --- a/AspDotNet/KY.Generator.AspDotNet.csproj +++ b/AspDotNet/KY.Generator.AspDotNet.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator ASP.net Module for KY-Generator Download KY.Generator to use this module diff --git a/AspDotNet/Readers/AspDotNetControllerReader.cs b/AspDotNet/Readers/AspDotNetControllerReader.cs index cefe2069..3accd092 100644 --- a/AspDotNet/Readers/AspDotNetControllerReader.cs +++ b/AspDotNet/Readers/AspDotNetControllerReader.cs @@ -48,10 +48,10 @@ public virtual void Read(AspDotNetReadConfiguration configuration, List()) - { - returnType = returnType.IgnoreGeneric(attribute.Type); - } + IEnumerable typesToIgnore = method.GetCustomAttributes() + .Concat(type.GetCustomAttributes()) + .Select(x => x.Type); + returnType = returnType.IgnoreGeneric(typesToIgnore); this.modelReader.Read(returnType, transferObjects); Attribute methodRouteAttribute = method.GetCustomAttributes().FirstOrDefault(x => x.GetType().Name == "RouteAttribute"); if (methodRouteAttribute != null) diff --git a/CLI/Properties/AssemblyInfo.cs b/CLI/Properties/AssemblyInfo.cs index 3aefde67..cf537e8c 100644 --- a/CLI/Properties/AssemblyInfo.cs +++ b/CLI/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("5.1.2")] -[assembly: AssemblyFileVersion("5.1.2")] +[assembly: AssemblyVersion("5.2.0")] +[assembly: AssemblyFileVersion("5.2.0")] diff --git a/CLI/nuget.nuspec b/CLI/nuget.nuspec index 7b264c44..bc8ca824 100644 --- a/CLI/nuget.nuspec +++ b/CLI/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI - 5.1.2 + 5.2.0 KY.Generator.CLI KY-Programming KY-Programming diff --git a/Core/Extensions/TypeExtension.cs b/Core/Extensions/TypeExtension.cs index c573966c..8b67b34b 100644 --- a/Core/Extensions/TypeExtension.cs +++ b/Core/Extensions/TypeExtension.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using KY.Core; @@ -11,9 +12,25 @@ public static Type IgnoreGeneric(this Type type, string nameSpace, string typeNa return type.Namespace == nameSpace && type.Name.TrimEnd("`1") == typeName.TrimEnd("`1") ? type.GetGenericArguments().SingleOrDefault() ?? typeof(void) : type; } - public static Type IgnoreGeneric(this Type type, Type typeToIgnore) + public static Type IgnoreGeneric(this Type type, params Type[] typesToIgnore) { - return type.IgnoreGeneric(typeToIgnore.Namespace, typeToIgnore.Name); + bool isChanged = false; + foreach (Type typeToIgnore in typesToIgnore) + { + Type oldType = type; + type = type.IgnoreGeneric(typeToIgnore.Namespace, typeToIgnore.Name); + isChanged |= oldType != type; + } + if (isChanged) + { + return type.IgnoreGeneric(typesToIgnore); + } + return type; + } + + public static Type IgnoreGeneric(this Type type, IEnumerable typesToIgnore) + { + return type.IgnoreGeneric(typesToIgnore.ToArray()); } } } \ No newline at end of file diff --git a/Core/KY.Generator.Core.csproj b/Core/KY.Generator.Core.csproj index 6182c440..42f8fe54 100644 --- a/Core/KY.Generator.Core.csproj +++ b/Core/KY.Generator.Core.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 5.1.2 + 5.2.0 Core elements for KY-Generator Download KY.Generator to use this module 2020 - KY-Programming diff --git a/Csharp/KY.Generator.CSharp.csproj b/Csharp/KY.Generator.CSharp.csproj index 68def87d..babfcde6 100644 --- a/Csharp/KY.Generator.CSharp.csproj +++ b/Csharp/KY.Generator.CSharp.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 5.1.2 + 5.2.0 C# Module for KY-Generator Download KY.Generator to use this module 2020 - KY-Programming diff --git a/EntityFramework/KY.Generator.EntityFramework.csproj b/EntityFramework/KY.Generator.EntityFramework.csproj index a934ac14..5a09ab81 100644 --- a/EntityFramework/KY.Generator.EntityFramework.csproj +++ b/EntityFramework/KY.Generator.EntityFramework.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 5.1.2 + 5.2.0 2020 - KY-Programming EntityFramework Module for KY-Generator Download KY.Generator to use this module diff --git a/Json/KY.Generator.Json.csproj b/Json/KY.Generator.Json.csproj index 3450e787..6a25b562 100644 --- a/Json/KY.Generator.Json.csproj +++ b/Json/KY.Generator.Json.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator JSON Module for KY-Generator Download KY.Generator to use this module diff --git a/Main.Legacy/Properties/AssemblyInfo.cs b/Main.Legacy/Properties/AssemblyInfo.cs index a75a6507..322d90bf 100644 --- a/Main.Legacy/Properties/AssemblyInfo.cs +++ b/Main.Legacy/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("5.1.2")] -[assembly: AssemblyFileVersion("5.1.2")] +[assembly: AssemblyVersion("5.2.0")] +[assembly: AssemblyFileVersion("5.2.0")] diff --git a/Main/KY.Generator.csproj b/Main/KY.Generator.csproj index 40822828..c364c969 100644 --- a/Main/KY.Generator.csproj +++ b/Main/KY.Generator.csproj @@ -4,7 +4,7 @@ Exe netcoreapp3.0 netcoreapp2.0;netcoreapp3.0 - 5.1.2 + 5.2.0 KY-Programming KY.Generator 2020 - KY-Programming diff --git a/Main/nuget.nuspec b/Main/nuget.nuspec index 14149dab..815d3c3b 100644 --- a/Main/nuget.nuspec +++ b/Main/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator - 5.1.2 + 5.2.0 KY.Generator KY-Programming KY-Programming diff --git a/Main/nuget.targets b/Main/nuget.targets index b74d4f1a..76bf6fa6 100644 --- a/Main/nuget.targets +++ b/Main/nuget.targets @@ -19,12 +19,12 @@ netcoreapp2.0 netcoreapp3.0 - - @@ -38,12 +38,12 @@ netcoreapp2.0 netcoreapp3.0 - - @@ -59,7 +59,7 @@ netcoreapp2.0 netcoreapp3.0 - @@ -76,7 +76,7 @@ netcoreapp2.0 netcoreapp3.0 - @@ -95,7 +95,7 @@ netcoreapp2.0 netcoreapp3.0 - @@ -112,7 +112,7 @@ netcoreapp2.0 netcoreapp3.0 - diff --git a/OData/KY.Generator.OData.csproj b/OData/KY.Generator.OData.csproj index 987ed578..4f70f60b 100644 --- a/OData/KY.Generator.OData.csproj +++ b/OData/KY.Generator.OData.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator oData Module for KY-Generator Download KY.Generator to use this module diff --git a/OpenApi/KY.Generator.OpenApi.csproj b/OpenApi/KY.Generator.OpenApi.csproj index 6651dbe2..1ca8b75f 100644 --- a/OpenApi/KY.Generator.OpenApi.csproj +++ b/OpenApi/KY.Generator.OpenApi.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator OpenApi Module for KY-Generator Download KY.Generator to use this module diff --git a/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj b/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj index 4f6b3eb0..6f03e8dc 100644 --- a/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj +++ b/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator Annotations for Reflection Module for KY-Generator 2020 - KY-Programming diff --git a/Reflection.Annotations/Reflection/GenerateIgnoreGenericAttribute.cs b/Reflection.Annotations/Reflection/GenerateIgnoreGenericAttribute.cs index c9c2bfd9..fd330e57 100644 --- a/Reflection.Annotations/Reflection/GenerateIgnoreGenericAttribute.cs +++ b/Reflection.Annotations/Reflection/GenerateIgnoreGenericAttribute.cs @@ -2,7 +2,7 @@ namespace KY.Generator { - [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false, AllowMultiple = true)] public class GenerateIgnoreGenericAttribute : Attribute { public Type Type { get; } diff --git a/Reflection/KY.Generator.Reflection.csproj b/Reflection/KY.Generator.Reflection.csproj index c3bb5ca2..cb454b0f 100644 --- a/Reflection/KY.Generator.Reflection.csproj +++ b/Reflection/KY.Generator.Reflection.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator Reflection Module for KY-Generator Download KY.Generator to use this module diff --git a/Tests/WebApiControllerWithRoute/ClientApp/src/app/services/weather-forecast.service.ts b/Tests/WebApiControllerWithRoute/ClientApp/src/app/services/weather-forecast.service.ts index d9303784..539226f4 100644 --- a/Tests/WebApiControllerWithRoute/ClientApp/src/app/services/weather-forecast.service.ts +++ b/Tests/WebApiControllerWithRoute/ClientApp/src/app/services/weather-forecast.service.ts @@ -125,6 +125,60 @@ export class WeatherForecastService { return subject; } + public test8(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test8", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + + public test9(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test9", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + + public test10(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test10", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + + public test11(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test11", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + + public test12(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test12", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + + public test13(httpOptions: {} = undefined): Observable { + let subject = new Subject(); + this.http.get(this.serviceUrl + "/weatherforecast/test13", httpOptions).subscribe((result) => { + subject.next(result); + subject.complete(); + }, (error) => subject.error(error)); + return subject; + } + public convertAny(value: any): string { return value === null || value === undefined ? "" : value.toString(); } diff --git a/Tests/WebApiControllerWithRoute/Controllers/WeatherForecastController.cs b/Tests/WebApiControllerWithRoute/Controllers/WeatherForecastController.cs index 20d40517..a31ff4ca 100644 --- a/Tests/WebApiControllerWithRoute/Controllers/WeatherForecastController.cs +++ b/Tests/WebApiControllerWithRoute/Controllers/WeatherForecastController.cs @@ -12,6 +12,7 @@ namespace WebApiControllerWithRoute.Controllers [Route("[controller]")] [GenerateAngularService("\\ClientApp\\src\\app\\services", "\\ClientApp\\src\\app\\models")] [GenerateOption(GenerateOption.SkipHeader)] + [GenerateIgnoreGeneric(typeof(IgnoreMe2<>))] public class WeatherForecastController : ControllerBase { private static readonly string[] Summaries = new[] @@ -100,5 +101,50 @@ public IgnoreMe Test7(int test) { return new IgnoreMe(Enumerable.Empty().ToArray()); } + + [HttpGet, Route("[action]")] + public IgnoreMe2 Test8() + { + return new IgnoreMe2(Enumerable.Empty().ToArray()); + } + + [HttpGet, Route("[action]")] + [GenerateIgnoreGeneric(typeof(IgnoreMe<>))] + [GenerateIgnoreGeneric(typeof(IgnoreMe3<>))] + public IgnoreMe3> Test9() + { + return new IgnoreMe3>(new IgnoreMe(Enumerable.Empty().ToArray())); + } + + [HttpGet, Route("[action]")] + [GenerateIgnoreGeneric(typeof(IgnoreMe<>))] + [GenerateIgnoreGeneric(typeof(IgnoreMe3<>))] + public IgnoreMe> Test10() + { + return new IgnoreMe>(new IgnoreMe3(Enumerable.Empty().ToArray())); + } + + [HttpGet, Route("[action]")] + [GenerateIgnoreGeneric(typeof(IgnoreMe3<>))] + [GenerateIgnoreGeneric(typeof(IgnoreMe<>))] + public IgnoreMe3> Test11() + { + return new IgnoreMe3>(new IgnoreMe(Enumerable.Empty().ToArray())); + } + + [HttpGet, Route("[action]")] + [GenerateIgnoreGeneric(typeof(IgnoreMe3<>))] + [GenerateIgnoreGeneric(typeof(IgnoreMe<>))] + public IgnoreMe> Test12() + { + return new IgnoreMe>(new IgnoreMe3(Enumerable.Empty().ToArray())); + } + + [HttpGet, Route("[action]")] + [GenerateIgnoreGeneric(typeof(IgnoreMe<>))] + public IgnoreMe> Test13() + { + return new IgnoreMe>(new List()); + } } } \ No newline at end of file diff --git a/Tests/WebApiControllerWithRoute/Models/IgnoreMe.cs b/Tests/WebApiControllerWithRoute/Models/IgnoreMe.cs index 16589fed..0c693f8e 100644 --- a/Tests/WebApiControllerWithRoute/Models/IgnoreMe.cs +++ b/Tests/WebApiControllerWithRoute/Models/IgnoreMe.cs @@ -9,4 +9,24 @@ public IgnoreMe(T value) this.Value = value; } } + + public class IgnoreMe2 + { + public T Value { get; } + + public IgnoreMe2(T value) + { + this.Value = value; + } + } + + public class IgnoreMe3 + { + public T Value { get; } + + public IgnoreMe3(T value) + { + this.Value = value; + } + } } \ No newline at end of file diff --git a/Tsql/KY.Generator.Tsql.csproj b/Tsql/KY.Generator.Tsql.csproj index 8e833b46..2639bc9b 100644 --- a/Tsql/KY.Generator.Tsql.csproj +++ b/Tsql/KY.Generator.Tsql.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 5.1.2 + 5.2.0 TSQL Module for KY-Generator Download KY.Generator to use this module 2020 - KY-Programming diff --git a/TypeScript/KY.Generator.TypeScript.csproj b/TypeScript/KY.Generator.TypeScript.csproj index 2c5aaa5a..c5475c48 100644 --- a/TypeScript/KY.Generator.TypeScript.csproj +++ b/TypeScript/KY.Generator.TypeScript.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 5.1.2 + 5.2.0 KY.Generator TypeScript Module for KY-Generator Download KY.Generator to use this module diff --git a/Watchdog/KY.Generator.Watchdog.csproj b/Watchdog/KY.Generator.Watchdog.csproj index 3591fa6f..8dd19e35 100644 --- a/Watchdog/KY.Generator.Watchdog.csproj +++ b/Watchdog/KY.Generator.Watchdog.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 5.1.2 + 5.2.0 KY-Programming KY-Programming KY.Generator