Skip to content

Commit 9850b83

Browse files
mmainermmainer
authored andcommitted
Fixed scneario where entity based model generation conflicts with Request model generation. EventMessage entity results in a EventMessageRequest request object. Problem is that there is an EventMessageRequest entity generated in the same namespace. This checkin fixes this.
1 parent 664f587 commit 9850b83

File tree

4 files changed

+140
-8
lines changed

4 files changed

+140
-8
lines changed

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

Lines changed: 43 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(" ");
@@ -297,6 +312,12 @@ public string GetEntityGetAsyncMethod(OdcmClass odcmClass, bool initializeCollec
297312

298313
public void AppendUpdateAsyncHeader(string entityName, string lowerCaseEntityName, StringBuilder stringBuilder, bool includeSendParams)
299314
{
315+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
316+
if (entityName.EndsWith("Request"))
317+
{
318+
entityName = String.Concat(entityName, "Object");
319+
}
320+
300321
if (includeSendParams)
301322
{
302323
stringBuilder.AppendFormat(" ");
@@ -325,6 +346,13 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass)
325346
var stringBuilder = new StringBuilder();
326347

327348
var entityName = this.GetEntityNameString(odcmClass);
349+
350+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
351+
if (entityName.EndsWith("Request"))
352+
{
353+
entityName = String.Concat(entityName, "Object");
354+
}
355+
328356
var lowerCaseEntityName = entityName.ToLowerFirstChar();
329357

330358
var templateWriterHost = (CustomT4Host)Host;
@@ -395,6 +423,13 @@ public string GetSelectMethod(string requestType)
395423

396424
public string GetSelectExpressionMethod(string requestType, string underlyingType)
397425
{
426+
427+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
428+
if (underlyingType.EndsWith("Request"))
429+
{
430+
underlyingType = String.Concat(underlyingType, "Object");
431+
}
432+
398433
var stringBuilder = new StringBuilder();
399434

400435
stringBuilder.Append(
@@ -429,6 +464,13 @@ public string GetSelectExpressionMethod(string requestType, string underlyingTyp
429464

430465
public string GetExpandExpressionMethod(string requestType, string underlyingType)
431466
{
467+
468+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
469+
if (underlyingType.EndsWith("Request"))
470+
{
471+
underlyingType = String.Concat(underlyingType, "Object");
472+
}
473+
432474
var stringBuilder = new StringBuilder();
433475

434476
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);
@@ -330,6 +380,13 @@ public string GetSelectMethod(string entityRequest)
330380
public string GetEntityExpandMethods(OdcmClass odcmClass)
331381
{
332382
string entityName = this.GetEntityNameString(odcmClass);
383+
384+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
385+
if (entityName.EndsWith("Request"))
386+
{
387+
entityName = String.Concat(entityName, "Object");
388+
}
389+
333390
return this.GetExpandMethod(this.GetRequestString(entityName)) +
334391
Environment.NewLine + Environment.NewLine + " " +
335392
this.GetExpandExpressionMethod(this.GetRequestString(entityName), entityName);
@@ -338,6 +395,13 @@ public string GetEntityExpandMethods(OdcmClass odcmClass)
338395
public string GetEntitySelectMethods(OdcmClass odcmClass)
339396
{
340397
string entityName = this.GetEntityNameString(odcmClass);
398+
399+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
400+
if (entityName.EndsWith("Request"))
401+
{
402+
entityName = String.Concat(entityName, "Object");
403+
}
404+
341405
return this.GetSelectMethod(this.GetRequestString(entityName)) +
342406
Environment.NewLine + Environment.NewLine + " " +
343407
this.GetSelectExpressionMethod(this.GetRequestString(entityName), entityName);

Templates/CSharp/Model/EntityType.cs.tt

Lines changed: 12 additions & 0 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());

Templates/CSharp/Requests/EntityRequest.cs.tt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,26 @@ namespace <#=this.GetNamespaceName(entity)#>
6262
Write(this.GetEntitySelectMethods(entity));
6363
Write("\n\n");
6464
}
65+
66+
// This change supports the scenario where we have an entity based model whose name ends with "Request".
67+
// This will disambiguate with Request objects that are created for models.
68+
var thisEntity_Name = entity.Name;
69+
var thisEntityName = entityName;
70+
71+
// Special case for when an entity name ends with "Request". Associated with the change in EntityType.cs.tt
72+
if (entityName.EndsWith("Request"))
73+
{
74+
thisEntity_Name = String.Concat(entity.Name, "Object");
75+
thisEntityName = String.Concat(entityName, "Object");
76+
}
77+
78+
6579
#>
6680
/// <summary>
6781
/// Initializes any collection properties after deserialization, like next requests for paging.
6882
/// </summary>
69-
/// <param name="<#=entity.Name#>ToInitialize">The <see cref="<#=entityName#>"/> with the collection properties to initialize.</param>
70-
private void InitializeCollectionProperties(<#=entityName#> <#=entity.Name#>ToInitialize)
83+
/// <param name="<#=thisEntity_Name#>ToInitialize">The <see cref="<#=thisEntityName#>"/> with the collection properties to initialize.</param>
84+
private void InitializeCollectionProperties(<#=thisEntityName#> <#=thisEntity_Name#>ToInitialize)
7185
{
7286
<#
7387
var navigationCollectionProperties = entity.Properties.Where(property => property.IsCollection() && property.IsNavigation());
@@ -76,7 +90,7 @@ namespace <#=this.GetNamespaceName(entity)#>
7690
{
7791
#>
7892

79-
if (<#=entity.Name#>ToInitialize != null && <#=entity.Name#>ToInitialize.AdditionalData != null)
93+
if (<#=thisEntity_Name#>ToInitialize != null && <#=thisEntity_Name#>ToInitialize.AdditionalData != null)
8094
{
8195
<#
8296
foreach(var property in navigationCollectionProperties)
@@ -88,17 +102,17 @@ namespace <#=this.GetNamespaceName(entity)#>
88102
{
89103
#>
90104

91-
if (<#=entity.Name#>ToInitialize.<#=propertyName#> != null && <#=entity.Name#>ToInitialize.<#=propertyName#>.CurrentPage != null)
105+
if (<#=thisEntity_Name#>ToInitialize.<#=propertyName#> != null && <#=thisEntity_Name#>ToInitialize.<#=propertyName#>.CurrentPage != null)
92106
{
93-
<#=entity.Name#>ToInitialize.<#=propertyName#>.AdditionalData = <#=entity.Name#>ToInitialize.AdditionalData;
107+
<#=thisEntity_Name#>ToInitialize.<#=propertyName#>.AdditionalData = <#=thisEntity_Name#>ToInitialize.AdditionalData;
94108

95109
object nextPageLink;
96-
<#=entity.Name#>ToInitialize.AdditionalData.TryGetValue("<#=propertyName.ToLowerFirstChar()#>@odata.nextLink", out nextPageLink);
110+
<#=thisEntity_Name#>ToInitialize.AdditionalData.TryGetValue("<#=propertyName.ToLowerFirstChar()#>@odata.nextLink", out nextPageLink);
97111
var nextPageLinkString = nextPageLink as string;
98112

99113
if (!string.IsNullOrEmpty(nextPageLinkString))
100114
{
101-
<#=entity.Name#>ToInitialize.<#=propertyName#>.InitializeNextPageRequest(
115+
<#=thisEntity_Name#>ToInitialize.<#=propertyName#>.InitializeNextPageRequest(
102116
this.Client,
103117
nextPageLinkString);
104118
}

0 commit comments

Comments
 (0)