Skip to content

Commit 0789cd4

Browse files
committed
Big refactor of NativeTypesMetadata
1 parent 2d69856 commit 0789cd4

7 files changed

Lines changed: 293 additions & 242 deletions

File tree

src/ServiceStack.Client/UrlExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using ServiceStack.Text;
1010
#else
1111
using System.Collections.Concurrent;
12+
using ServiceStack.Text;
13+
1214
#endif
1315

1416
namespace ServiceStack
@@ -449,7 +451,7 @@ internal static IDictionary<string, RouteMember> GetQueryProperties(Type request
449451
};
450452
}
451453

452-
if (ServiceStack.Text.JsConfig.IncludePublicFields)
454+
if (JsConfig.IncludePublicFields)
453455
{
454456
foreach (var fieldInfo in requestType.GetPublicFields())
455457
{

src/ServiceStack.Common/MetadataTypes.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ public MetadataTypesConfig(
1212
bool addReturnMarker = true,
1313
bool convertDescriptionToComments = true,
1414
bool addDataContractAttributes = false,
15-
bool makeDataContractsExtensible = false,
15+
bool addDataAnnotationAttributes = false,
1616
bool addIndexesToDataMembers = false,
1717
string addDefaultXmlNamespace = null,
18-
bool initializeCollections = true,
1918
bool addResponseStatus = false,
19+
bool makeDataContractsExtensible = false,
20+
bool initializeCollections = true,
2021
int? addImplicitVersion = null)
2122
{
2223
BaseUrl = baseUrl;
@@ -25,6 +26,7 @@ public MetadataTypesConfig(
2526
AddReturnMarker = addReturnMarker;
2627
AddDescriptionAsComments = convertDescriptionToComments;
2728
AddDataContractAttributes = addDataContractAttributes;
29+
AddDataAnnotationAttributes = addDataAnnotationAttributes;
2830
AddDefaultXmlNamespace = addDefaultXmlNamespace;
2931
MakeDataContractsExtensible = makeDataContractsExtensible;
3032
AddIndexesToDataMembers = addIndexesToDataMembers;
@@ -39,12 +41,13 @@ public MetadataTypesConfig(
3941
public bool AddReturnMarker { get; set; }
4042
public bool AddDescriptionAsComments { get; set; }
4143
public bool AddDataContractAttributes { get; set; }
42-
public bool MakeDataContractsExtensible { get; set; }
44+
public bool AddDataAnnotationAttributes { get; set; }
4345
public bool AddIndexesToDataMembers { get; set; }
44-
public bool InitializeCollections { get; set; }
4546
public int? AddImplicitVersion { get; set; }
4647
public bool AddResponseStatus { get; set; }
4748
public string AddDefaultXmlNamespace { get; set; }
49+
public bool MakeDataContractsExtensible { get; set; }
50+
public bool InitializeCollections { get; set; }
4851
public List<string> DefaultNamespaces { get; set; }
4952

5053
public Dictionary<string, string> TypeAlias { get; set; }
@@ -83,16 +86,24 @@ public class MetadataType
8386
public string[] InheritsGenericArgs { get; set; }
8487
public string Description { get; set; }
8588
public bool ReturnVoidMarker { get; set; }
86-
public string[] ReturnMarkerGenericArgs { get; set; }
89+
90+
public MetadataTypeName ReturnMarkerTypeName { get; set; }
8791

8892
public List<MetadataRoute> Routes { get; set; }
93+
8994
public MetadataDataContract DataContract { get; set; }
9095

9196
public List<MetadataPropertyType> Properties { get; set; }
9297

9398
public List<MetadataAttribute> Attributes { get; set; }
9499
}
95100

101+
public class MetadataTypeName
102+
{
103+
public string Name { get; set; }
104+
public string[] GenericArgs { get; set; }
105+
}
106+
96107
public class MetadataRoute
97108
{
98109
public string Path { get; set; }

src/ServiceStack/NativeTypes/CSharp/CSharpGenerator.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ public string GetCode(MetadataTypes metadata)
4141
sb.AppendLine("ServerVersion: {0}".Fmt(metadata.Version));
4242
sb.AppendLine("MakePartial: {0}".Fmt(Config.MakePartial));
4343
sb.AppendLine("MakeVirtual: {0}".Fmt(Config.MakeVirtual));
44+
sb.AppendLine("MakeDataContractsExtensible: {0}".Fmt(Config.MakeDataContractsExtensible));
4445
sb.AppendLine("AddReturnMarker: {0}".Fmt(Config.AddReturnMarker));
4546
sb.AppendLine("AddDescriptionAsComments: {0}".Fmt(Config.AddDescriptionAsComments));
4647
sb.AppendLine("AddDataContractAttributes: {0}".Fmt(Config.AddDataContractAttributes));
48+
sb.AppendLine("AddDataAnnotationAttributes: {0}".Fmt(Config.AddDataAnnotationAttributes));
4749
sb.AppendLine("AddDefaultXmlNamespace: {0}".Fmt(Config.AddDefaultXmlNamespace));
48-
sb.AppendLine("MakeDataContractsExtensible: {0}".Fmt(Config.MakeDataContractsExtensible));
4950
sb.AppendLine("AddIndexesToDataMembers: {0}".Fmt(Config.AddIndexesToDataMembers));
50-
sb.AppendLine("InitializeCollections: {0}".Fmt(Config.InitializeCollections));
5151
sb.AppendLine("AddResponseStatus: {0}".Fmt(Config.AddResponseStatus));
5252
sb.AppendLine("AddImplicitVersion: {0}".Fmt(Config.AddImplicitVersion));
53+
sb.AppendLine("InitializeCollections: {0}".Fmt(Config.InitializeCollections));
5354
sb.AppendLine("DefaultNamespaces: {0}".Fmt(Config.DefaultNamespaces.ToArray().Join(", ")));
5455
sb.AppendLine("*/");
5556
sb.AppendLine();
@@ -84,15 +85,15 @@ public string GetCode(MetadataTypes metadata)
8485
ImplementsFn = () => {
8586
if (!Config.AddReturnMarker
8687
&& !request.ReturnVoidMarker
87-
&& request.ReturnMarkerGenericArgs == null)
88+
&& request.ReturnMarkerTypeName == null)
8889
return null;
8990

9091
if (request.ReturnVoidMarker)
9192
return "IReturnVoid";
92-
if (request.ReturnMarkerGenericArgs != null)
93-
return Type("IReturn`1", request.ReturnMarkerGenericArgs);
93+
if (request.ReturnMarkerTypeName != null)
94+
return Type("IReturn`1", new[] { Type(request.ReturnMarkerTypeName) });
9495
return response != null
95-
? Type("IReturn`1", new[] { response.Name })
96+
? Type("IReturn`1", new[] { Type(response.Name, response.GenericArgs) })
9697
: null;
9798
},
9899
IsRequest = true,
@@ -153,7 +154,7 @@ private string AppendType(ref StringBuilderWrapper sb, MetadataType type, string
153154
AppendDataContract(sb, type.DataContract);
154155

155156
var partial = Config.MakePartial ? "partial " : "";
156-
sb.AppendLine("public {0}class {1}".Fmt(partial, type.Name.SafeToken()));
157+
sb.AppendLine("public {0}class {1}".Fmt(partial, Type(type.Name, type.GenericArgs)));
157158

158159
//: BaseClass, Interfaces
159160
var inheritsList = new List<string>();
@@ -204,7 +205,7 @@ private void AddConstuctor(StringBuilderWrapper sb, MetadataType type, CreateTyp
204205
sb.AppendLine();
205206
}
206207

207-
sb.AppendLine("public {0}()".Fmt(type.Name.SafeToken()));
208+
sb.AppendLine("public {0}()".Fmt(NameOnly(type.Name)));
208209
sb.AppendLine("{");
209210
sb = sb.Indent();
210211

@@ -329,6 +330,11 @@ public string TypeValue(string type, string value)
329330
return value;
330331
}
331332

333+
public string Type(MetadataTypeName typeName)
334+
{
335+
return Type(typeName.Name, typeName.GenericArgs);
336+
}
337+
332338
public string Type(string type, string[] genericArgs)
333339
{
334340
if (genericArgs != null)
@@ -368,6 +374,11 @@ private string TypeAlias(string type)
368374
return typeAlias ?? type.SafeToken();
369375
}
370376

377+
public string NameOnly(string type)
378+
{
379+
return type.SplitOnFirst('`')[0].SafeToken();
380+
}
381+
371382
public void AppendComments(StringBuilderWrapper sb, string desc)
372383
{
373384
if (desc == null) return;

src/ServiceStack/NativeTypes/MetadataTypesHandler.cs

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)