Skip to content

Commit c7584be

Browse files
committed
Generic types
1 parent 44a77db commit c7584be

3 files changed

Lines changed: 69 additions & 5 deletions

File tree

src/Test/GenericTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Test
6+
{
7+
8+
9+
public class GetCookiesForWebsiteQuery : Query<GetCookiesForWebsiteResult>
10+
{
11+
public override string Alias => "GetCookiesForWebsite";
12+
13+
public Guid WebsiteKey { get; set; }
14+
15+
}
16+
17+
public class GetCookiesForWebsiteResult
18+
{
19+
public string WebsiteName {get;set;}
20+
21+
22+
23+
24+
}
25+
26+
public abstract class Query<T> : IQuery<T>
27+
{
28+
public abstract string Alias { get; }
29+
30+
}
31+
32+
public interface IQuery
33+
{
34+
/// <summary>
35+
/// Used when performing requests from the front end
36+
/// </summary>
37+
string Alias { get; }
38+
39+
}
40+
41+
42+
/// <summary>
43+
/// Base class for Queries using the <see cref="IMediator"/>
44+
/// </summary>
45+
/// <typeparam name="TResponse"></typeparam>
46+
public interface IQuery<out TResponse> : IQuery
47+
{
48+
49+
}
50+
51+
}

src/Test/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static void Main(string[] args)
1717

1818
builder
1919
.ExcludeType(typeof(Program))
20-
.AddCSType(typeof(Poco));
20+
//.AddCSType(typeof(Poco))
21+
.AddCSType(typeof(GetCookiesForWebsiteQuery));
2122
//.AddCSType(typeof(TestA.Employee));
2223
//.AddCSType(typeof(TestA.Equipment))
2324
//.AddCSType(typeof(TestB.Strange<>));

src/TypeScriptBuilder/TypeScriptGenerator.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,16 @@ public string TypeName(Type type, bool forceClass = false)
109109
return "{}";
110110
}
111111

112-
// any other enumerable
113-
if (genericType.GetInterfaces().Any(e => e.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
114-
return TypeName(generics[0]) + "[]";
112+
try
113+
{
114+
// any other enumerable
115+
if (genericType.GetInterfaces().Any(e => e.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
116+
return TypeName(generics[0]) + "[]";
117+
}
118+
catch (Exception e)
119+
{
120+
return "any";
121+
}
115122

116123
AddCSType(genericType);
117124

@@ -180,7 +187,12 @@ void GenerateTypeDefinition(Type type)
180187
baseType = ti.BaseType;
181188

182189
if (ti.IsClass && !flat && baseType != null && baseType != typeof(object))
183-
Builder.AppendLine($" extends {TypeName(baseType)}");
190+
{
191+
var typeName = TypeName(baseType);
192+
if(typeName != "any")
193+
Builder.AppendLine($" extends {typeName}");
194+
}
195+
184196

185197
Builder.OpenScope();
186198

0 commit comments

Comments
 (0)