Skip to content

Commit 703e6eb

Browse files
Merge pull request #85 from microsoftgraph/enumFlags
Many changes, needs review
2 parents 4b1a5a2 + 88582d1 commit 703e6eb

16 files changed

+207
-28
lines changed

Templates/CSharp/Base/EntityRequest.Base.template.tt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ public string GetEntityCreateAsyncMethod(OdcmClass odcmClass)
197197

198198
var templateWriterHost = (CustomT4Host)Host;
199199
var templateWriter = (CodeWriterCSharp)templateWriterHost.CodeWriter;
200+
200201
var entityName = this.GetEntityNameString(odcmClass);
201-
var lowerCaseEntityName = entityName.ToLowerFirstChar();
202+
203+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
204+
if (entityName.EndsWith("Request"))
205+
{
206+
entityName = String.Concat(entityName, "Object");
207+
}
208+
209+
var lowerCaseEntityName = entityName.ToLowerFirstChar();
202210

203211
this.AppendCreateAsyncHeader(entityName, lowerCaseEntityName, stringBuilder, false);
204212
stringBuilder.Append(Environment.NewLine);
@@ -235,6 +243,13 @@ public string GetEntityCreateAsyncMethod(OdcmClass odcmClass)
235243

236244
public void AppendGetAsyncHeader(string entityName, StringBuilder stringBuilder, bool includeSendParams)
237245
{
246+
247+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
248+
if (entityName.EndsWith("Request"))
249+
{
250+
entityName = String.Concat(entityName, "Object");
251+
}
252+
238253
if (includeSendParams)
239254
{
240255
stringBuilder.AppendFormat(" ");
@@ -263,6 +278,12 @@ public string GetEntityGetAsyncMethod(OdcmClass odcmClass, bool initializeCollec
263278

264279
var entityName = this.GetEntityNameString(odcmClass);
265280

281+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
282+
if (entityName.EndsWith("Request"))
283+
{
284+
entityName = String.Concat(entityName, "Object");
285+
}
286+
266287
this.AppendGetAsyncHeader(entityName, stringBuilder, false);
267288
stringBuilder.Append(Environment.NewLine);
268289
stringBuilder.AppendFormat(" public System.Threading.Tasks.Task<{0}> GetAsync()", entityName);
@@ -297,6 +318,12 @@ public string GetEntityGetAsyncMethod(OdcmClass odcmClass, bool initializeCollec
297318

298319
public void AppendUpdateAsyncHeader(string entityName, string lowerCaseEntityName, StringBuilder stringBuilder, bool includeSendParams)
299320
{
321+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
322+
if (entityName.EndsWith("Request"))
323+
{
324+
entityName = String.Concat(entityName, "Object");
325+
}
326+
300327
if (includeSendParams)
301328
{
302329
stringBuilder.AppendFormat(" ");
@@ -325,6 +352,13 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass)
325352
var stringBuilder = new StringBuilder();
326353

327354
var entityName = this.GetEntityNameString(odcmClass);
355+
356+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
357+
if (entityName.EndsWith("Request"))
358+
{
359+
entityName = String.Concat(entityName, "Object");
360+
}
361+
328362
var lowerCaseEntityName = entityName.ToLowerFirstChar();
329363

330364
var templateWriterHost = (CustomT4Host)Host;
@@ -395,6 +429,13 @@ public string GetSelectMethod(string requestType)
395429

396430
public string GetSelectExpressionMethod(string requestType, string underlyingType)
397431
{
432+
433+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
434+
if (underlyingType.EndsWith("Request"))
435+
{
436+
underlyingType = String.Concat(underlyingType, "Object");
437+
}
438+
398439
var stringBuilder = new StringBuilder();
399440

400441
stringBuilder.Append(
@@ -429,6 +470,13 @@ public string GetSelectExpressionMethod(string requestType, string underlyingTyp
429470

430471
public string GetExpandExpressionMethod(string requestType, string underlyingType)
431472
{
473+
474+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
475+
if (underlyingType.EndsWith("Request"))
476+
{
477+
underlyingType = String.Concat(underlyingType, "Object");
478+
}
479+
432480
var stringBuilder = new StringBuilder();
433481

434482
stringBuilder.Append(

Templates/CSharp/Base/IEntityRequest.Base.template.tt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public string GetEntityRequestInterfaceDefinition(OdcmClass odcmClass)
4040
// -------------------------------------------------------------
4141
public void AppendEntityCreateAsyncMethodHeader(string entityName, string lowerCaseEntityName, StringBuilder stringBuilder, bool includeSendParams)
4242
{
43+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
44+
if (entityName.EndsWith("Request"))
45+
{
46+
entityName = String.Concat(entityName, "Object");
47+
}
48+
4349
if (includeSendParams)
4450
{
4551
stringBuilder.Append(" ");
@@ -68,6 +74,13 @@ public string GetEntityCreateAsyncMethod(OdcmClass odcmClass)
6874
var stringBuilder = new StringBuilder();
6975

7076
var entityName = this.GetEntityNameString(odcmClass);
77+
78+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
79+
if (entityName.EndsWith("Request"))
80+
{
81+
entityName = String.Concat(entityName, "Object");
82+
}
83+
7184
var lowerCaseEntityName = entityName.ToLowerFirstChar();
7285

7386
this.AppendEntityCreateAsyncMethodHeader(entityName, lowerCaseEntityName, stringBuilder, false);
@@ -83,6 +96,12 @@ public string GetEntityCreateAsyncMethod(OdcmClass odcmClass)
8396

8497
public void AppendDeleteAsyncMethodHeader(string deleteTargetString, StringBuilder stringBuilder, bool includeSendParams)
8598
{
99+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
100+
if (deleteTargetString.EndsWith("Request"))
101+
{
102+
deleteTargetString = String.Concat(deleteTargetString, "Object");
103+
}
104+
86105
if (includeSendParams)
87106
{
88107
stringBuilder.Append(" ");
@@ -106,6 +125,12 @@ public void AppendDeleteAsyncMethodHeader(string deleteTargetString, StringBuild
106125

107126
public string GetDeleteAsyncMethod(string deleteTargetString)
108127
{
128+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
129+
if (deleteTargetString.EndsWith("Request"))
130+
{
131+
deleteTargetString = String.Concat(deleteTargetString, "Object");
132+
}
133+
109134
var stringBuilder = new StringBuilder();
110135

111136
this.AppendDeleteAsyncMethodHeader(deleteTargetString, stringBuilder, false);
@@ -170,6 +195,12 @@ public string GetEntityDeleteAsyncMethod(OdcmClass odcmClass)
170195

171196
public void AppendGetAsyncMethodHeader(string entityName, StringBuilder stringBuilder, bool includeSendParams)
172197
{
198+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
199+
if (entityName.EndsWith("Request"))
200+
{
201+
entityName = String.Concat(entityName, "Object");
202+
}
203+
173204
if (includeSendParams)
174205
{
175206
stringBuilder.Append(" ");
@@ -197,6 +228,12 @@ public string GetEntityGetAsyncMethod(OdcmClass odcmClass)
197228

198229
var entityName = this.GetEntityNameString(odcmClass);
199230

231+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
232+
if (entityName.EndsWith("Request"))
233+
{
234+
entityName = String.Concat(entityName, "Object");
235+
}
236+
200237
this.AppendGetAsyncMethodHeader(entityName, stringBuilder, false);
201238
stringBuilder.Append(Environment.NewLine);
202239
stringBuilder.AppendFormat(" System.Threading.Tasks.Task<{0}> GetAsync();", entityName);
@@ -213,6 +250,12 @@ public string GetEntityGetAsyncMethod(OdcmClass odcmClass)
213250

214251
public void AppendUpdateAsyncMethodHeader(string entityName, string lowerCaseEntityName, StringBuilder stringBuilder, bool includeSendParams)
215252
{
253+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
254+
if (entityName.EndsWith("Request"))
255+
{
256+
entityName = String.Concat(entityName, "Object");
257+
}
258+
216259
if (includeSendParams)
217260
{
218261
stringBuilder.Append(" ");
@@ -241,6 +284,13 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass)
241284
var stringBuilder = new StringBuilder();
242285

243286
var entityName = this.GetEntityNameString(odcmClass);
287+
288+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
289+
if (entityName.EndsWith("Request"))
290+
{
291+
entityName = String.Concat(entityName, "Object");
292+
}
293+
244294
var lowerCaseEntityName = entityName.ToLowerFirstChar();
245295

246296
this.AppendUpdateAsyncMethodHeader(entityName, lowerCaseEntityName, stringBuilder, false);
@@ -264,6 +314,13 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass)
264314

265315
public string GetExpandExpressionMethod(string requestType, string underlyingType)
266316
{
317+
318+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
319+
if (underlyingType.EndsWith("Request"))
320+
{
321+
underlyingType = String.Concat(underlyingType, "Object");
322+
}
323+
267324
var stringBuilder = new StringBuilder();
268325

269326
stringBuilder.Append(
@@ -296,6 +353,13 @@ public string GetExpandMethod(string entityRequest)
296353

297354
public string GetSelectExpressionMethod(string requestType, string underlyingType)
298355
{
356+
357+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
358+
if (underlyingType.EndsWith("Request"))
359+
{
360+
underlyingType = String.Concat(underlyingType, "Object");
361+
}
362+
299363
var stringBuilder = new StringBuilder();
300364

301365
stringBuilder.Append(

Templates/CSharp/Base/SharedCSharp.template.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CustomT4Host host = (CustomT4Host)Host;
66
OdcmModel model = host.CurrentModel;
77
var writer = (CodeWriterCSharp)host.CodeWriter;
8-
bool logTemplateSrc = false;
8+
bool logTemplateSrc = true;
99

1010
#>
1111
<#=writer.WriteHeader()#>

Templates/CSharp/Model/ComplexType.cs.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ namespace <#=complex.Namespace.GetNamespaceName()#>
4949
var propertyType = property.IsCollection ? string.Format("IEnumerable<{0}>", property.GetTypeString()) : property.GetTypeString();
5050
var propertyName = isMethodResponse
5151
? property.Name.Substring(property.Name.IndexOf('.') + 1).ToCheckedCase()
52-
: property.Name.ToCheckedCase().GetSanitizedPropertyName();
52+
: property.Name.ToCheckedCase().GetSanitizedPropertyName(property);
5353

54-
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", property.Name);
54+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Newtonsoft.Json.Required.Default)]", property.Name);
5555

5656
if (property.IsTypeNullable() || property.IsCollection)
5757
{

Templates/CSharp/Model/EntityType.cs.tt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ var entityName = entity.Name.ToCheckedCase();
88

99
var typeDeclaration = entityName;
1010

11+
// In the case a entity type name ends with "Request", we will have a collision with the Request objects
12+
// when we generate. For example, there are entities named EventMessage and EventMessageRequest. Those entities
13+
// lead to the generation of an EventMessageRequest and EventMessageRequestRequest request objects in the same
14+
// namespace as the entities. We add 'Object' to the end of the name to disambiguate the entity.
15+
// This change needs to sync with changes for the *Request templates.
16+
17+
if (typeDeclaration.EndsWith("Request"))
18+
{
19+
typeDeclaration = String.Concat(typeDeclaration, "Object");
20+
}
21+
22+
1123
if (entity.Base != null)
1224
{
1325
typeDeclaration = string.Format("{0} : {1}", typeDeclaration, entity.Base.Name.ToCheckedCase());
@@ -61,7 +73,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
6173
var propertyName = property.Name.ToCheckedCase();
6274
var propertyCollectionPage = property.IsReference() ? string.Concat(entityName, propertyName, "CollectionWithReferencesPage") : string.Concat(entityName, propertyName, "CollectionPage");
6375

64-
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", property.Name);
76+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Newtonsoft.Json.Required.Default)]", property.Name);
6577

6678
if (property.IsCollection())
6779
{
@@ -96,7 +108,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
96108
/// Gets or sets <#=property.Name.SplitCamelCase().ToLower()#>.
97109
/// </summary>
98110
<#=attributeDefinition#>
99-
public <#=propertyType#> <#=propertyName.GetSanitizedPropertyName()#> { get; set; }
111+
public <#=propertyType#> <#=propertyName.GetSanitizedPropertyName(property)#> { get; set; }
100112
<#
101113
}
102114
}
@@ -109,7 +121,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
109121
/// <summary>
110122
/// Gets or sets @odata.type.
111123
/// </summary>
112-
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "@odata.type", Required = Required.Default)]
124+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "@odata.type", Required = Newtonsoft.Json.Required.Default)]
113125
public string ODataType { get; set; }
114126

115127
/// <summary>

Templates/CSharp/Model/EnumType.cs.tt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ namespace <#=enumT.Namespace.GetNamespaceName()#>
1515
/// The enum <#=enumName#>.
1616
/// </summary>
1717
[JsonConverter(typeof(EnumConverter))]
18+
<# if (enumT.IsFlags == true)
19+
{
20+
#>
21+
[System.Flags]
22+
<#
23+
}
24+
#>
1825
public enum <#=enumName#>
1926
{
2027
<#
21-
foreach(var value in enumT.Members)
28+
foreach(var emumMember in enumT.Members)
2229
{
2330
#>
2431

2532
/// <summary>
26-
/// <#=value.Name.SplitCamelCase()#>
33+
/// <#=emumMember.Name.SplitCamelCase()#>
2734
/// </summary>
28-
<#=value.Name.ToCheckedCase().GetSanitizedPropertyName()#>,
29-
<#
30-
}
35+
<#=emumMember.Name.ToCheckedCase().GetSanitizedPropertyName()#> = <#=emumMember.Value#>,
36+
<#
37+
}
3138
#>
3239

3340
}

Templates/CSharp/Model/MethodRequestBody.cs.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
4646
}
4747

4848
var paramName = param.Name.ToCheckedCase().GetSanitizedPropertyName();
49-
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Required.Default)]", param.Name);
49+
var attributeDefinition = string.Format("[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = \"{0}\", Required = Newtonsoft.Json.Required.Default)]", param.Name);
5050
#>
5151

5252
/// <summary>

Templates/CSharp/Requests/EntityCollectionResponse.cs.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (prop.Class.Derived != null && prop.Class.Base == null)
3131
/// <summary>
3232
/// Gets or sets the <see cref="I<#=collectionPage#>"/> value.
3333
/// </summary>
34-
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Required.Default)]
34+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Newtonsoft.Json.Required.Default)]
3535
public I<#=collectionPage#> Value { get; set; }
3636

3737
/// <summary>

Templates/CSharp/Requests/EntityCollectionWithReferencesResponse.cs.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (prop.Class.Derived != null && prop.Class.Base == null)
3131
/// <summary>
3232
/// Gets or sets the <see cref="I<#=collectionPage#>"/> value.
3333
/// </summary>
34-
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Required.Default)]
34+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Newtonsoft.Json.Required.Default)]
3535
public I<#=collectionPage#> Value { get; set; }
3636

3737
/// <summary>

0 commit comments

Comments
 (0)