Skip to content

Commit 09a17de

Browse files
committed
Merge branch 'v7' into master
2 parents 5c3b1db + 09f32b1 commit 09a17de

File tree

14 files changed

+91
-7
lines changed

14 files changed

+91
-7
lines changed

Angular/Writers/AngularServiceWriter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,18 @@ public virtual void Write(AngularWriteConfiguration configuration)
108108
TypeTransferObject returnModelType = isEnumerable ? action.ReturnType.Generics.First().Type : action.ReturnType;
109109
ModelTransferObject returnModel = returnModelType as ModelTransferObject ?? this.transferObjects.OfType<ModelTransferObject>().FirstOrDefault(x => x.Equals(returnModelType));
110110
this.AddUsing(action.ReturnType, classTemplate, controllerOptions, relativeModelPath);
111+
TypeTemplate aliasType = null;
112+
if (returnType.Name == "unknown")
113+
{
114+
aliasType = Code.Type("TDefault");
115+
returnType = aliasType;
116+
}
111117
MethodTemplate methodTemplate = classTemplate.AddMethod(action.Name, Code.Generic("Observable", returnType))
112118
.FormatName(controllerOptions);
119+
if (aliasType != null)
120+
{
121+
methodTemplate.WithGeneric(aliasType.Name, Code.Type("unknown"));
122+
}
113123
TypeTemplate subjectType = Code.Generic("Subject", returnType);
114124
methodTemplate.WithCode(Code.Declare(subjectType, subjectName, Code.New(subjectType)));
115125
foreach (HttpServiceActionParameterTransferObject parameter in action.Parameters)

Common/Languages/BaseLanguage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected BaseLanguage(IDependencyResolver resolver)
6060
this.AddWriter<LocalVariableTemplate, LocalVariableWriter>();
6161
this.AddWriter<MethodTemplate, MethodWriter>();
6262
this.AddWriter<ExtensionMethodTemplate, MethodWriter>();
63+
this.AddWriter<MethodGenericTemplate, MethodGenericWriter>();
6364
this.AddWriter<MultilineCodeFragment, MultilineCodeFragmentWriter>();
6465
this.AddWriter<NamespaceTemplate, NamespaceWriter>();
6566
this.AddWriter<NewTemplate, NewWriter>();

Common/Templates/Extensions/MethodTemplateExtension.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public static MethodTemplate Override(this MethodTemplate methodTemplate, bool v
3535
return methodTemplate;
3636
}
3737

38+
public static MethodTemplate WithGeneric(this MethodTemplate methodTemplate, string alias, TypeTemplate defaultType = null)
39+
{
40+
methodTemplate.Generics.Add(new MethodGenericTemplate(alias, defaultType));
41+
return methodTemplate;
42+
}
43+
3844
public static ParameterTemplate AddParameter(this MethodTemplate methodTemplate, TypeTemplate type, string name, ICodeFragment defaultValue = null)
3945
{
4046
var parameter = new ParameterTemplate(type, name, defaultValue);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace KY.Generator.Templates
2+
{
3+
public class MethodGenericTemplate : ICodeFragment
4+
{
5+
public string Alias { get; set; }
6+
public TypeTemplate DefaultType { get; set; }
7+
8+
public MethodGenericTemplate(string alias, TypeTemplate defaultType = null)
9+
{
10+
this.Alias = alias;
11+
this.DefaultType = defaultType;
12+
}
13+
}
14+
}

Common/Templates/Structural/MethodTemplate.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class MethodTemplate : AttributeableTempalte
1616
public MultilineCodeFragment Code { get; }
1717
public ClassTemplate Class { get; }
1818
public CommentTemplate Comment { get; set; }
19+
public List<MethodGenericTemplate> Generics { get; set; }
1920

2021
public MethodTemplate(ClassTemplate classTemplate, string name, TypeTemplate type)
2122
{
@@ -25,6 +26,7 @@ public MethodTemplate(ClassTemplate classTemplate, string name, TypeTemplate typ
2526
this.Visibility = Visibility.Public;
2627
this.Parameters = new List<ParameterTemplate>();
2728
this.Code = new MultilineCodeFragment();
29+
this.Generics = new List<MethodGenericTemplate>();
2830
}
2931
}
30-
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using KY.Generator.Output;
2+
using KY.Generator.Templates;
3+
4+
namespace KY.Generator.Writers
5+
{
6+
public class MethodGenericWriter : ITemplateWriter
7+
{
8+
public void Write(ICodeFragment fragment, IOutputCache output)
9+
{
10+
MethodGenericTemplate template = (MethodGenericTemplate)fragment;
11+
output.Add(template.Alias)
12+
.If(template.DefaultType != null).Add(" = ").Add(template.DefaultType).EndIf();
13+
}
14+
}
15+
}

Common/Writers/MethodWriter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using KY.Generator.Output;
34
using KY.Generator.Templates;
45

@@ -9,13 +10,18 @@ public class MethodWriter : ITemplateWriter
910
public virtual void Write(ICodeFragment fragment, IOutputCache output)
1011
{
1112
MethodTemplate template = (MethodTemplate)fragment;
13+
if (template.Generics != null && template.Generics.Any(x => x.DefaultType != null))
14+
{
15+
throw new InvalidOperationException($"This language does not support default types for generic methods. {template.Class.Name}.{template.Name}");
16+
}
1217
output.Add(template.Comment)
1318
.Add(template.Attributes)
1419
.Add(template.Visibility.ToString().ToLower()).Add(" ")
1520
.If(template.IsStatic).Add("static ").EndIf()
1621
.If(template.IsOverride).Add("override ").EndIf()
1722
.If(template.Type != null).Add(template.Type).Add(" ").EndIf()
1823
.Add(template.Name)
24+
.If(template.Generics != null && template.Generics.Count > 0).Add("<").Add(template.Generics, ", ").Add(">").EndIf()
1925
.Add("(")
2026
.If(template is ExtensionMethodTemplate).Add("this ").EndIf()
2127
.Add(template.Parameters.OrderBy(x => x.DefaultValue == null ? 0 : 1), ", ")
@@ -29,4 +35,4 @@ public virtual void Write(ICodeFragment fragment, IOutputCache output)
2935
protected virtual void BeforeBlock(ICodeFragment fragment, IOutputCache output)
3036
{ }
3137
}
32-
}
38+
}

EntityFramework/KY.Generator.EntityFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Authors>KY-Programming</Authors>
66
<Company>KY-Programming</Company>
77
<Product>KY.Generator</Product>
8-
<Version>7.5.0</Version>
8+
<Version>7.6.0</Version>
99
<Copyright>2021 - KY-Programming</Copyright>
1010
<Description>EntityFramework Module for KY-Generator
1111
Download KY.Generator to use this module</Description>

OData/KY.Generator.OData.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<Company>KY-Programming</Company>
66
<Authors>KY-Programming</Authors>
7-
<Version>7.5.0</Version>
7+
<Version>7.6.0</Version>
88
<Product>KY.Generator</Product>
99
<Description>oData Module for KY-Generator
1010
Download KY.Generator to use this module</Description>

OpenApi/KY.Generator.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<Company>KY-Programming</Company>
66
<Authors>KY-Programming</Authors>
7-
<Version>7.5.0</Version>
7+
<Version>7.6.0</Version>
88
<Product>KY.Generator</Product>
99
<Description>OpenApi Module for KY-Generator
1010
Download KY.Generator to use this module</Description>

0 commit comments

Comments
 (0)