Skip to content

Commit b411539

Browse files
committed
asp: support relative path to assembly
core: resolve modules from local packages folder reflection: resolve assemblies from local packages folder
1 parent 17191b9 commit b411539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+270
-267
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ __pycache__/
293293
/InternalOverride
294294
/InternalConsole
295295
/InternalConsole.Core
296+
/InternalConsole.Minimal
296297
/Nuget
297298
/Xml
298299
/Svn

Angular/KY.Generator.Angular.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<Authors>KY-Programming</Authors>
66
<Company>KY-Programming</Company>
77
<Product>KY.Generator</Product>
8-
<Version>2.3.0</Version>
8+
<Version>2.4.0</Version>
99
<Copyright>2019 - KY-Programming</Copyright>
10-
<Description>Angular Module for KY-Generator</Description>
10+
<Description>Angular Module for KY-Generator
11+
Download KY.Generator.CLI to use this module</Description>
1112
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
1213
<PackageProjectUrl>https://github.com/KY-Programming/generator</PackageProjectUrl>
1314
<PackageIconUrl>https://ky-programming.de/images/logos/128.png</PackageIconUrl>
@@ -16,7 +17,7 @@
1617
</PropertyGroup>
1718

1819
<ItemGroup>
19-
<PackageReference Include="KY.Core.Common" Version="4.6.2" />
20+
<PackageReference Include="KY.Core.Common" Version="4.7.0" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

AspDotNet/KY.Generator.AspDotNet.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<Company>KY-Programming</Company>
66
<Authors>KY-Programming</Authors>
7-
<Version>2.3.0</Version>
7+
<Version>2.4.0</Version>
88
<Product>KY.Generator</Product>
9-
<Description>ASP.net Module for KY-Generator</Description>
9+
<Description>ASP.net Module for KY-Generator
10+
Download KY.Generator.CLI to use this module</Description>
1011
<Copyright>2019 - KY-Programming</Copyright>
1112
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
1213
<PackageProjectUrl>https://github.com/KY-Programming/generator</PackageProjectUrl>
@@ -16,7 +17,7 @@
1617
</PropertyGroup>
1718

1819
<ItemGroup>
19-
<PackageReference Include="KY.Core.Common" Version="4.6.2" />
20+
<PackageReference Include="KY.Core.Common" Version="4.7.0" />
2021
</ItemGroup>
2122

2223
<ItemGroup>
+74-92
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
54
using System.Reflection;
6-
using System.Text.RegularExpressions;
75
using KY.Core;
8-
using KY.Core.DataAccess;
96
using KY.Generator.AspDotNet.Configurations;
107
using KY.Generator.Reflection.Language;
118
using KY.Generator.Reflection.Readers;
@@ -26,116 +23,101 @@ public AspDotNetControllerReader(ReflectionModelReader modelReader)
2623
public virtual IEnumerable<ITransferObject> Read(AspDotNetReadConfiguration configuration)
2724
{
2825
Logger.Trace("Read ASP.net controller...");
29-
List<Assembly> assemblies = new List<Assembly>();
30-
if (!string.IsNullOrEmpty(configuration.Controller.Assembly))
26+
Type type = GeneratorTypeLoader.Get(configuration, configuration.Controller.Assembly, configuration.Controller.Namespace, configuration.Controller.Name);
27+
if (type == null)
3128
{
32-
//TODO: Support only assembly name too
33-
Assembly assembly = Assembly.LoadFile(configuration.Controller.Assembly);
34-
assemblies.Add(assembly);
35-
}
36-
else
37-
{
38-
AppDomain.CurrentDomain.GetAssemblies().ForEach(assemblies.Add);
29+
yield break;
3930
}
4031

41-
foreach (Assembly assembly in assemblies)
32+
HttpServiceTransferObject controller = new HttpServiceTransferObject();
33+
controller.Name = type.Name;
34+
controller.Language = ReflectionLanguage.Instance;
35+
36+
Attribute routeAttribute = type.GetCustomAttributes().FirstOrDefault();
37+
controller.Route = routeAttribute?.GetType().GetProperty("Template")?.GetValue(routeAttribute)?.ToString();
38+
39+
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
40+
foreach (MethodInfo method in methods)
4241
{
43-
Type type = assembly.GetType(string.Join(".", configuration.Controller.Namespace, configuration.Controller.Name));
44-
if (type == null)
42+
foreach (ModelTransferObject model in this.modelReader.Read(method.ReturnType))
4543
{
46-
continue;
44+
yield return model;
4745
}
48-
49-
HttpServiceTransferObject controller = new HttpServiceTransferObject();
50-
controller.Name = type.Name;
51-
controller.Language = ReflectionLanguage.Instance;
52-
53-
Attribute routeAttribute = type.GetCustomAttributes().FirstOrDefault();
54-
controller.Route = routeAttribute?.GetType().GetProperty("Template")?.GetValue(routeAttribute)?.ToString();
55-
56-
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
57-
foreach (MethodInfo method in methods)
46+
foreach (Attribute attribute in method.GetCustomAttributes())
5847
{
59-
foreach (ModelTransferObject model in this.modelReader.Read(method.ReturnType))
48+
Type attributeType = attribute.GetType();
49+
HttpServiceActionTransferObject action = new HttpServiceActionTransferObject();
50+
action.ReturnType = method.ReturnType.ToTransferObject();
51+
action.Route = attributeType.GetProperty("Template")?.GetValue(attribute)?.ToString();
52+
int methodNameIndex = 1;
53+
while (true)
6054
{
61-
yield return model;
62-
}
63-
foreach (Attribute attribute in method.GetCustomAttributes())
64-
{
65-
Type attributeType = attribute.GetType();
66-
HttpServiceActionTransferObject action = new HttpServiceActionTransferObject();
67-
action.ReturnType = method.ReturnType.ToTransferObject();
68-
action.Route = attributeType.GetProperty("Template")?.GetValue(attribute)?.ToString();
69-
int methodNameIndex = 1;
70-
while (true)
55+
string actionName = $"{method.Name}{(methodNameIndex > 1 ? methodNameIndex.ToString() : "")}";
56+
if (controller.Actions.All(x => !x.Name.Equals(actionName)))
7157
{
72-
string actionName = $"{method.Name}{(methodNameIndex > 1 ? methodNameIndex.ToString() : "")}";
73-
if (controller.Actions.All(x => !x.Name.Equals(actionName)))
74-
{
75-
action.Name = actionName;
76-
break;
77-
}
78-
methodNameIndex++;
58+
action.Name = actionName;
59+
break;
7960
}
80-
ParameterInfo[] parameters = method.GetParameters();
81-
foreach (ParameterInfo parameter in parameters)
61+
methodNameIndex++;
62+
}
63+
ParameterInfo[] parameters = method.GetParameters();
64+
foreach (ParameterInfo parameter in parameters)
65+
{
66+
foreach (ModelTransferObject model in this.modelReader.Read(parameter.ParameterType))
8267
{
83-
foreach (ModelTransferObject model in this.modelReader.Read(parameter.ParameterType))
84-
{
85-
yield return model;
86-
}
68+
yield return model;
8769
}
88-
switch (attributeType.Name)
70+
}
71+
switch (attributeType.Name)
72+
{
73+
case "HttpGetAttribute":
74+
action.Type = HttpServiceActionTypeTransferObject.Get;
75+
break;
76+
case "HttpPostAttribute":
77+
action.Type = HttpServiceActionTypeTransferObject.Post;
78+
break;
79+
case "HttpPatchAttribute":
80+
action.Type = HttpServiceActionTypeTransferObject.Patch;
81+
break;
82+
case "HttpPutAttribute":
83+
action.Type = HttpServiceActionTypeTransferObject.Put;
84+
break;
85+
case "HttpDeleteAttribute":
86+
action.Type = HttpServiceActionTypeTransferObject.Delete;
87+
break;
88+
default:
89+
Logger.Warning($"Unknown controller action attribute {attributeType.Name}");
90+
continue;
91+
}
92+
action.RequireBodyParameter = action.Type.IsBodyParameterRequired();
93+
foreach (ParameterInfo parameter in parameters)
94+
{
95+
HttpServiceActionParameterTransferObject actionParameter = new HttpServiceActionParameterTransferObject();
96+
actionParameter.Name = parameter.Name;
97+
actionParameter.Type = parameter.ParameterType.ToTransferObject();
98+
actionParameter.FromBody = action.RequireBodyParameter && parameter.GetCustomAttributes().Any(parameterAttribute => parameterAttribute.GetType().Name == "FromBodyAttribute");
99+
action.Parameters.Add(actionParameter);
100+
}
101+
if (action.RequireBodyParameter)
102+
{
103+
if (action.Parameters.Count == 0)
89104
{
90-
case "HttpGetAttribute":
91-
action.Type = HttpServiceActionTypeTransferObject.Get;
92-
break;
93-
case "HttpPostAttribute":
94-
action.Type = HttpServiceActionTypeTransferObject.Post;
95-
break;
96-
case "HttpPatchAttribute":
97-
action.Type = HttpServiceActionTypeTransferObject.Patch;
98-
break;
99-
case "HttpPutAttribute":
100-
action.Type = HttpServiceActionTypeTransferObject.Put;
101-
break;
102-
case "HttpDeleteAttribute":
103-
action.Type = HttpServiceActionTypeTransferObject.Delete;
104-
break;
105-
default:
106-
Logger.Warning($"Unknown controller action attribute {attributeType.Name}");
107-
continue;
105+
throw new InvalidOperationException($"Can not write {method.Name}. {action.Type} requires at least one parameter, but no parameter found.");
108106
}
109-
action.RequireBodyParameter = action.Type.IsBodyParameterRequired();
110-
foreach (ParameterInfo parameter in parameters)
107+
if (action.Parameters.Count == 1)
111108
{
112-
HttpServiceActionParameterTransferObject actionParameter = new HttpServiceActionParameterTransferObject();
113-
actionParameter.Name = parameter.Name;
114-
actionParameter.Type = parameter.ParameterType.ToTransferObject();
115-
actionParameter.FromBody = action.RequireBodyParameter && parameter.GetCustomAttributes().Any(parameterAttribute => parameterAttribute.GetType().Name == "FromBodyAttribute");
116-
action.Parameters.Add(actionParameter);
109+
action.Parameters.Single().FromBody = true;
117110
}
118-
if (action.RequireBodyParameter)
111+
else if (action.Parameters.All(x => !x.FromBody))
119112
{
120-
if (action.Parameters.Count == 0)
121-
{
122-
throw new InvalidOperationException($"Can not write {method.Name}. {action.Type} requires at least one parameter, but no parameter found.");
123-
}
124-
if (action.Parameters.Count == 1)
125-
{
126-
action.Parameters.Single().FromBody = true;
127-
}
128-
else if (action.Parameters.All(x => !x.FromBody))
129-
{
130-
throw new InvalidOperationException($"Can not write {method.Name}. {action.Type} requires at least one parameter marked with [FromBody] or can have only one parameter");
131-
}
113+
throw new InvalidOperationException($"Can not write {method.Name}. {action.Type} requires at least one parameter marked with [FromBody] or can have only one parameter");
132114
}
133-
controller.Actions.Add(action);
134115
}
116+
controller.Actions.Add(action);
135117
}
136-
137-
yield return controller;
138118
}
119+
120+
yield return controller;
139121
}
140122
}
141123
}

CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.2</TargetFramework>
6-
<Version>2.3.0</Version>
6+
<Version>2.4.0</Version>
77
<Authors>KY-Programming</Authors>
88
<Product>KY.Generator</Product>
99
<Copyright>2019 - KY-Programming</Copyright>
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="KY.Core.Common" Version="4.6.2" />
15+
<PackageReference Include="KY.Core.Common" Version="4.7.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

CLI.Core.Minimal/nuget.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core.Minimal</id>
5-
<version>2.3.0</version>
5+
<version>2.4.0</version>
66
<title>KY.Generator.CLI.Core.Minimal</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>
@@ -16,7 +16,7 @@ Generate classes from oData, .NET assembly, JSON or TSQL to C# or TypeScript. Su
1616
<copyright>Copyright 2019</copyright>
1717
<tags>KY-Generator KY Generator .netCore CLI</tags>
1818
<dependencies>
19-
<dependency id="KY.Generator.Core" version="2.3.0" />
19+
<dependency id="KY.Generator.Core" version="2.4.0" />
2020
</dependencies>
2121
</metadata>
2222
<files>

CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.2</TargetFramework>
6-
<Version>2.3.0</Version>
6+
<Version>2.4.0</Version>
77
<Authors>KY-Programming</Authors>
88
<Product>KY.Generator</Product>
99
<Copyright>2019 - KY-Programming</Copyright>
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="KY.Core.Common" Version="4.6.2" />
15+
<PackageReference Include="KY.Core.Common" Version="4.7.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

CLI.Core.Standalone/nuget.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core.Standalone</id>
5-
<version>2.3.0</version>
5+
<version>2.4.0</version>
66
<title>KY.Generator.CLI.Core.Standalone</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>
@@ -11,7 +11,7 @@
1111
<iconUrl>https://ky-programming.de/images/logos/128.png</iconUrl>
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>.net Core CLI Standalone for KY-Generator.
14-
This executable contains all features without any dependency</description>
14+
This executable contains all features without any dependency</description>
1515
<description>KY-Generator .NET Core CLI Standalone containing all features without dependencies.
1616
Generate classes from oData, .NET assembly, JSON or TSQL to C# or TypeScript. Support Angular, ASP.NET, ASP.NET Core, C# POCOs, TypeScript POCOs, Entity Framework and more.</description>
1717
<releaseNotes></releaseNotes>

CLI.Core/KY.Generator.CLI.Core.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.2</TargetFramework>
6-
<Version>2.3.0</Version>
6+
<Version>2.4.0</Version>
77
<Authors>KY-Programming</Authors>
88
<Product>KY.Generator</Product>
99
<Copyright>2019 - KY-Programming</Copyright>
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="KY.Core.Common" Version="4.6.2" />
15+
<PackageReference Include="KY.Core.Common" Version="4.7.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

CLI.Core/nuget.nuspec

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core</id>
5-
<version>2.3.0</version>
5+
<version>2.4.0</version>
66
<title>KY.Generator.CLI.Core</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>
@@ -16,17 +16,17 @@ Generate classes from oData, .NET assembly, JSON or TSQL to C# or TypeScript. Su
1616
<copyright>Copyright 2019</copyright>
1717
<tags>KY-Generator KY Generator .netCore CLI</tags>
1818
<dependencies>
19-
<dependency id="KY.Generator.Angular" version="2.3.0" />
20-
<dependency id="KY.Generator.AspDotNet" version="2.3.0" />
21-
<dependency id="KY.Generator.Core" version="2.3.0" />
22-
<dependency id="KY.Generator.Csharp" version="2.3.0" />
23-
<dependency id="KY.Generator.EntityFramework" version="2.3.0" />
24-
<dependency id="KY.Generator.Json" version="2.3.0" />
25-
<dependency id="KY.Generator.OData" version="2.3.0" />
26-
<dependency id="KY.Generator.OpenApi" version="2.3.0" />
27-
<dependency id="KY.Generator.Reflection" version="2.3.0" />
28-
<dependency id="KY.Generator.Tsql" version="2.3.0" />
29-
<dependency id="KY.Generator.TypeScript" version="2.3.0" />
19+
<dependency id="KY.Generator.Angular" version="2.4.0" />
20+
<dependency id="KY.Generator.AspDotNet" version="2.4.0" />
21+
<dependency id="KY.Generator.Core" version="2.4.0" />
22+
<dependency id="KY.Generator.Csharp" version="2.4.0" />
23+
<dependency id="KY.Generator.EntityFramework" version="2.4.0" />
24+
<dependency id="KY.Generator.Json" version="2.4.0" />
25+
<dependency id="KY.Generator.OData" version="2.4.0" />
26+
<dependency id="KY.Generator.OpenApi" version="2.4.0" />
27+
<dependency id="KY.Generator.Reflection" version="2.4.0" />
28+
<dependency id="KY.Generator.Tsql" version="2.4.0" />
29+
<dependency id="KY.Generator.TypeScript" version="2.4.0" />
3030
</dependencies>
3131
</metadata>
3232
<files>

CLI.Minimal/KY.Generator.CLI.Minimal.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
<Reference Include="Costura, Version=3.3.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
4141
<HintPath>..\packages\Costura.Fody.3.3.2\lib\net40\Costura.dll</HintPath>
4242
</Reference>
43-
<Reference Include="KY.Core.Common, Version=4.6.2.0, Culture=neutral, processorArchitecture=MSIL">
44-
<HintPath>..\packages\KY.Core.Common.4.6.2\lib\netstandard2.0\KY.Core.Common.dll</HintPath>
43+
<Reference Include="KY.Core.Common, Version=4.7.0.0, Culture=neutral, processorArchitecture=MSIL">
44+
<HintPath>..\packages\KY.Core.Common.4.7.0\lib\netstandard2.0\KY.Core.Common.dll</HintPath>
4545
</Reference>
4646
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4747
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>

0 commit comments

Comments
 (0)