Skip to content

Commit

Permalink
Reflection
Browse files Browse the repository at this point in the history
 - allow GenerateIgnoreGenericAttribute on methods
  • Loading branch information
ky-one committed Sep 24, 2020
1 parent 491e4f0 commit 10609d6
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Angular/KY.Generator.Angular.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>KY-Programming</Authors>
<Company>KY-Programming</Company>
<Product>KY.Generator</Product>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Copyright>2020 - KY-Programming</Copyright>
<Description>Angular Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
2 changes: 1 addition & 1 deletion AspDotNet/KY.Generator.AspDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>ASP.net Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
8 changes: 4 additions & 4 deletions AspDotNet/Readers/AspDotNetControllerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public virtual void Read(AspDotNetReadConfiguration configuration, List<ITransfe
.IgnoreGeneric("Microsoft.AspNetCore.Mvc", "IActionResult")
.IgnoreGeneric("Microsoft.AspNetCore.Mvc", "ActionResult");

foreach (GenerateIgnoreGenericAttribute attribute in method.GetCustomAttributes<GenerateIgnoreGenericAttribute>())
{
returnType = returnType.IgnoreGeneric(attribute.Type);
}
IEnumerable<Type> typesToIgnore = method.GetCustomAttributes<GenerateIgnoreGenericAttribute>()
.Concat(type.GetCustomAttributes<GenerateIgnoreGenericAttribute>())
.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)
Expand Down
4 changes: 2 additions & 2 deletions CLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion CLI/nuget.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>KY.Generator.CLI</id>
<!-- Ensure nuget.targets version is also updated -->
<version>5.1.2</version>
<version>5.2.0</version>
<title>KY.Generator.CLI</title>
<authors>KY-Programming</authors>
<owners>KY-Programming</owners>
Expand Down
21 changes: 19 additions & 2 deletions Core/Extensions/TypeExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KY.Core;

Expand All @@ -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<Type> typesToIgnore)
{
return type.IgnoreGeneric(typesToIgnore.ToArray());
}
}
}
2 changes: 1 addition & 1 deletion Core/KY.Generator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Product>KY.Generator</Product>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Description>Core elements for KY-Generator
Download KY.Generator to use this module</Description>
<Copyright>2020 - KY-Programming</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion Csharp/KY.Generator.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>KY-Programming</Authors>
<Company>KY-Programming</Company>
<Product>KY.Generator</Product>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Description>C# Module for KY-Generator
Download KY.Generator to use this module</Description>
<Copyright>2020 - KY-Programming</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion EntityFramework/KY.Generator.EntityFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>KY-Programming</Authors>
<Company>KY-Programming</Company>
<Product>KY.Generator</Product>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Copyright>2020 - KY-Programming</Copyright>
<Description>EntityFramework Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
2 changes: 1 addition & 1 deletion Json/KY.Generator.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>JSON Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
4 changes: 2 additions & 2 deletions Main.Legacy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion Main/KY.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFrameworks>netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Authors>KY-Programming</Authors>
<Product>KY.Generator</Product>
<Copyright>2020 - KY-Programming</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion Main/nuget.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>KY.Generator</id>
<!-- Ensure nuget.targets version is also updated -->
<version>5.1.2</version>
<version>5.2.0</version>
<title>KY.Generator</title>
<authors>KY-Programming</authors>
<owners>KY-Programming</owners>
Expand Down
16 changes: 8 additions & 8 deletions Main/nuget.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="%22%25USERPROFILE%25\.nuget\packages\ky.generator\5.1.2\tools\$(Framework)\KY.Generator.exe%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
<Exec Command="%22%25USERPROFILE%25\.nuget\packages\ky.generator\5.2.0\tools\$(Framework)\KY.Generator.exe%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
Condition="$(Framework) != 'netcoreapp2.0'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
</Exec>
<Exec Command="dotnet %22%25USERPROFILE%25\.nuget\packages\ky.generator\5.1.2\tools\$(Framework)\KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -plattform=%22$(Plattform)%22 msbuild beforeBuild"
<Exec Command="dotnet %22%25USERPROFILE%25\.nuget\packages\ky.generator\5.2.0\tools\$(Framework)\KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -plattform=%22$(Plattform)%22 msbuild beforeBuild"
Condition="$(Framework) == 'netcoreapp2.0'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand All @@ -38,12 +38,12 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="%22%25USERPROFILE%25\.nuget\packages\ky.generator\5.1.2\tools\$(Framework)\KY.Generator.exe%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
<Exec Command="%22%25USERPROFILE%25\.nuget\packages\ky.generator\5.2.0\tools\$(Framework)\KY.Generator.exe%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
Condition="$(Framework) != 'netcoreapp2.0'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
</Exec>
<Exec Command="dotnet %22%25USERPROFILE%25\.nuget\packages\ky.generator\5.1.2\tools\$(Framework)\KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -plattform=%22$(Plattform)%22 msbuild"
<Exec Command="dotnet %22%25USERPROFILE%25\.nuget\packages\ky.generator\5.2.0\tools\$(Framework)\KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)\%22 -assembly=%22$(TargetPath)%22 -plattform=%22$(Plattform)%22 msbuild"
Condition="$(Framework) == 'netcoreapp2.0'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand All @@ -59,7 +59,7 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.1.2/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.2.0/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
Condition="$(Framework) != 'none'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand All @@ -76,7 +76,7 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.1.2/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.2.0/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
Condition="$(Framework) != 'none'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand All @@ -95,7 +95,7 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.1.2/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.2.0/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild beforeBuild"
Condition="$(Framework) != 'none'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand All @@ -112,7 +112,7 @@
<Framework Condition="$(FrameworkRaw.StartsWith('2.'))">netcoreapp2.0</Framework>
<Framework Condition="$(FrameworkRaw.StartsWith('3.'))">netcoreapp3.0</Framework>
</PropertyGroup>
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.1.2/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
<Exec Command="dotnet %22~/.nuget/packages/ky.generator/5.2.0/tools/$(Framework)/KY.Generator.dll%22 %22$(ProjectDir)generator.json%22 -output=%22$(ProjectDir)%22 -assembly=%22$(TargetPath)%22 -platform=%22$(GeneratorPlatform)%22 msbuild"
Condition="$(Framework) != 'none'"
CustomErrorRegularExpression="^Error:"
CustomWarningRegularExpression="^Warning:">
Expand Down
2 changes: 1 addition & 1 deletion OData/KY.Generator.OData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>oData Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
2 changes: 1 addition & 1 deletion OpenApi/KY.Generator.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>OpenApi Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>Annotations for Reflection Module for KY-Generator</Description>
<Copyright>2020 - KY-Programming</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Reflection/KY.Generator.Reflection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>KY-Programming</Company>
<Authors>KY-Programming</Authors>
<Version>5.1.2</Version>
<Version>5.2.0</Version>
<Product>KY.Generator</Product>
<Description>Reflection Module for KY-Generator
Download KY.Generator to use this module</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,60 @@ export class WeatherForecastService {
return subject;
}

public test8(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(this.serviceUrl + "/weatherforecast/test8", httpOptions).subscribe((result) => {
subject.next(result);
subject.complete();
}, (error) => subject.error(error));
return subject;
}

public test9(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(this.serviceUrl + "/weatherforecast/test9", httpOptions).subscribe((result) => {
subject.next(result);
subject.complete();
}, (error) => subject.error(error));
return subject;
}

public test10(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(this.serviceUrl + "/weatherforecast/test10", httpOptions).subscribe((result) => {
subject.next(result);
subject.complete();
}, (error) => subject.error(error));
return subject;
}

public test11(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(this.serviceUrl + "/weatherforecast/test11", httpOptions).subscribe((result) => {
subject.next(result);
subject.complete();
}, (error) => subject.error(error));
return subject;
}

public test12(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(this.serviceUrl + "/weatherforecast/test12", httpOptions).subscribe((result) => {
subject.next(result);
subject.complete();
}, (error) => subject.error(error));
return subject;
}

public test13(httpOptions: {} = undefined): Observable<string[]> {
let subject = new Subject<string[]>();
this.http.get<string[]>(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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -100,5 +101,50 @@ public IgnoreMe<string[]> Test7(int test)
{
return new IgnoreMe<string[]>(Enumerable.Empty<string>().ToArray());
}

[HttpGet, Route("[action]")]
public IgnoreMe2<string[]> Test8()
{
return new IgnoreMe2<string[]>(Enumerable.Empty<string>().ToArray());
}

[HttpGet, Route("[action]")]
[GenerateIgnoreGeneric(typeof(IgnoreMe<>))]
[GenerateIgnoreGeneric(typeof(IgnoreMe3<>))]
public IgnoreMe3<IgnoreMe<string[]>> Test9()
{
return new IgnoreMe3<IgnoreMe<string[]>>(new IgnoreMe<string[]>(Enumerable.Empty<string>().ToArray()));
}

[HttpGet, Route("[action]")]
[GenerateIgnoreGeneric(typeof(IgnoreMe<>))]
[GenerateIgnoreGeneric(typeof(IgnoreMe3<>))]
public IgnoreMe<IgnoreMe3<string[]>> Test10()
{
return new IgnoreMe<IgnoreMe3<string[]>>(new IgnoreMe3<string[]>(Enumerable.Empty<string>().ToArray()));
}

[HttpGet, Route("[action]")]
[GenerateIgnoreGeneric(typeof(IgnoreMe3<>))]
[GenerateIgnoreGeneric(typeof(IgnoreMe<>))]
public IgnoreMe3<IgnoreMe<string[]>> Test11()
{
return new IgnoreMe3<IgnoreMe<string[]>>(new IgnoreMe<string[]>(Enumerable.Empty<string>().ToArray()));
}

[HttpGet, Route("[action]")]
[GenerateIgnoreGeneric(typeof(IgnoreMe3<>))]
[GenerateIgnoreGeneric(typeof(IgnoreMe<>))]
public IgnoreMe<IgnoreMe3<string[]>> Test12()
{
return new IgnoreMe<IgnoreMe3<string[]>>(new IgnoreMe3<string[]>(Enumerable.Empty<string>().ToArray()));
}

[HttpGet, Route("[action]")]
[GenerateIgnoreGeneric(typeof(IgnoreMe<>))]
public IgnoreMe<List<string>> Test13()
{
return new IgnoreMe<List<string>>(new List<string>());
}
}
}
Loading

0 comments on commit 10609d6

Please sign in to comment.