Skip to content

Commit a73bd11

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #126 from microsoftgraph/request-entity-bugfix
Acute fixes for RequestObject bugs
2 parents 92d9992 + 64c7374 commit a73bd11

File tree

10 files changed

+58
-1
lines changed

10 files changed

+58
-1
lines changed

Templates/CSharp/Base/CollectionRequest.Base.template.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public string GetPostAsyncMethod(OdcmProperty odcmProperty, string requestBody =
7373
var sanitizedPropertyName = odcmProperty.Projection.Type.Name.GetSanitizedPropertyName(odcmProperty.Name);
7474
var propertyType = this.GetPropertyTypeName(odcmProperty);
7575

76+
if (propertyType.EndsWith("Request"))
77+
{
78+
propertyType = String.Concat(propertyType, "Object");
79+
}
80+
7681
var templateWriterHost = (CustomT4Host)Host;
7782
var templateWriter = (CodeWriterCSharp)templateWriterHost.CodeWriter;
7883

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public string GetDeleteAsyncMethod(string deleteTargetString, string deleteTarge
7070
{
7171
var stringBuilder = new StringBuilder();
7272

73+
if (deleteTargetType.EndsWith("Request"))
74+
{
75+
deleteTargetType = String.Concat(deleteTargetType, "Object");
76+
}
77+
7378
this.AppendDeleteAsyncHeader(deleteTargetString, stringBuilder, false);
7479
stringBuilder.Append(Environment.NewLine);
7580
stringBuilder.Append(" public System.Threading.Tasks.Task DeleteAsync()");

Templates/CSharp/Base/ICollectionRequest.Base.template.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public string GetPostAsyncMethod(OdcmProperty odcmProperty)
5151
var sanitizedPropertyName = odcmProperty.Projection.Type.Name.GetSanitizedPropertyName(odcmProperty.Name);
5252
var propertyType = this.GetPropertyTypeName(odcmProperty);
5353

54+
if (propertyType.EndsWith("Request"))
55+
{
56+
propertyType = String.Concat(propertyType, "Object");
57+
}
58+
5459
var templateWriterHost = (CustomT4Host)Host;
5560
var templateWriter = (CodeWriterCSharp)templateWriterHost.CodeWriter;
5661

Templates/CSharp/Requests/EntityCollectionPage.cs.tt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ var innerEntity = prop.Projection.Type;
88
var innerEntityType = innerEntity is OdcmPrimitiveType ? innerEntity.GetTypeString() : innerEntity.Name.ToCheckedCase();
99
var entityCollectionRequest = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionRequest");
1010
var entityCollectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");
11-
11+
if (innerEntityType.EndsWith("Request"))
12+
{
13+
innerEntityType = String.Concat(innerEntityType, "Object");
14+
}
1215
#>
1316

1417
namespace <#=prop.Class.AsOdcmClass().Namespace.GetNamespaceName()#>

Templates/CSharp/Requests/EntityCollectionRequest.cs.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
var prop = host.CurrentType.AsOdcmProperty();
66
var innerEntity = prop.Projection.Type;
77
var innerEntityType = innerEntity.Name.ToCheckedCase();
8+
if (innerEntityType.EndsWith("Request"))
9+
{
10+
innerEntityType = String.Concat(innerEntityType, "Object");
11+
}
812
var collectionRequest = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionRequest");
913
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionResponse");
1014
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");

Templates/CSharp/Requests/IEntityCollectionPage.cs.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
var prop = host.CurrentType.AsOdcmProperty();
77
var innerEntity = prop.Projection.Type;
88
var innerEntityType = innerEntity is OdcmPrimitiveType ? innerEntity.GetTypeString() : innerEntity.Name.ToCheckedCase();
9+
if (innerEntityType.EndsWith("Request"))
10+
{
11+
innerEntityType = String.Concat(innerEntityType, "Object");
12+
}
13+
914
var entityCollectionRequest = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionRequest");
1015
var entityCollectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");
1116

Templates/CSharp/Requests/IEntityCollectionRequest.cs.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
var prop = host.CurrentType.AsOdcmProperty();
66
var innerEntity = prop.Projection.Type;
77
var innerEntityType = innerEntity.Name.ToCheckedCase();
8+
if (innerEntityType.EndsWith("Request"))
9+
{
10+
innerEntityType = String.Concat(innerEntityType, "Object");
11+
}
12+
813
var collectionRequest = this.GetPropertyCollectionRequestName(prop);
914
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionResponse");
1015
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");

Templates/CSharp/Requests/IStreamRequest.cs.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ else
2626
propRequest = propClass + prop.Name.ToCheckedCase() + "Request";
2727
namespaceValue = prop.Class.AsOdcmClass().Namespace.GetNamespaceName();
2828
}
29+
30+
if (propClass.EndsWith("Request"))
31+
{
32+
propClass = String.Concat(propClass, "Object");
33+
}
2934
#>
3035

3136
namespace <#=namespaceValue#>

Templates/CSharp/Requests/StreamRequest.cs.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ else
2323
{
2424
propName = prop.Name;
2525
propClass = prop.Class.Name.ToCheckedCase();
26+
2627
propRequest = propClass + prop.Name.ToCheckedCase() + "Request";
2728
namespaceValue = prop.Class.AsOdcmClass().Namespace.GetNamespaceName();
2829
}
30+
if (propClass.EndsWith("Request"))
31+
{
32+
propClass = String.Concat(propClass, "Object");
33+
}
2934
#>
3035

3136
namespace <#=namespaceValue#>

src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ public static string GetSanitizedPropertyName(this OdcmProperty property)
216216
return GetSanitizedPropertyName(property.Name);
217217
}
218218

219+
public static string GetSanitizedClassName(this OdcmClass odcmClass)
220+
{
221+
return GetSanitizedClassName(odcmClass.Name, odcmClass);
222+
}
223+
219224
public static string GetSanitizedPropertyName(this string property, string prefix = null)
220225
{
221226
return GetSanitizedPropertyName(property, null, prefix);
@@ -262,6 +267,16 @@ public static string GetSanitizedPropertyName(this string property, OdcmProperty
262267
return property;
263268
}
264269

270+
public static string GetSanitizedClassName(this string className, OdcmClass odcmClass)
271+
{
272+
var entityName = className.ToCheckedCase();
273+
if (entityName.EndsWith("Request"))
274+
{
275+
entityName = String.Concat(entityName, "Object");
276+
}
277+
return entityName;
278+
}
279+
265280
public static string GetSanitizedParameterName(this string parameter, string prefix = null)
266281
{
267282
if (GetReservedNames().Contains(parameter))

0 commit comments

Comments
 (0)