Skip to content

Commit 92b69c7

Browse files
authored
Merge pull request #24 from microsoftgraph/shiftylogic/working
For .NET: annotations + function /action overloads + excel prep + bug fixes
2 parents cef1ea3 + 4e8e0ee commit 92b69c7

25 files changed

+1560
-1671
lines changed

Templates/CSharp/Base/EntityRequestBuilder.Base.template.tt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,15 @@ public string GetStreamProperties(OdcmClass entity)
265265
// Creates the set of property definitions for OData method properties on the entity
266266
public string GetMethodProperties(OdcmClass entity)
267267
{
268+
var allMethods = new List<OdcmMethod>();
269+
foreach (var method in entity.Methods)
270+
{
271+
allMethods.Add(method);
272+
allMethods.AddRange(method.Overloads);
273+
}
274+
268275
var methodPropertiesStringBuilder = new StringBuilder();
269-
foreach(var method in entity.Methods)
276+
foreach(var method in allMethods)
270277
{
271278
var methodName = this.GetMethodName(method);
272279
var baseName = string.Concat(this.GetEntityNameString(method.Class), methodName);
@@ -290,7 +297,7 @@ public string GetMethodProperties(OdcmClass entity)
290297

291298
foreach (var param in requiredParameters)
292299
{
293-
var paramVariableName = param.Name.ToLowerFirstChar();
300+
var paramVariableName = param.Name.GetSanitizedParameterName();
294301
var paramTypeString = param.Type.GetTypeString();
295302

296303
if (param.IsCollection)
@@ -309,7 +316,7 @@ public string GetMethodProperties(OdcmClass entity)
309316

310317
foreach (var param in optionalParameters)
311318
{
312-
var paramVariableName = param.Name.ToLowerFirstChar();
319+
var paramVariableName = param.Name.GetSanitizedParameterName();
313320
var paramTypeString = param.Type.GetTypeString();
314321

315322
if (param.IsCollection)

Templates/CSharp/Base/IEntityRequestBuilder.Base.template.tt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,15 @@ public string GetStreamProperties(OdcmClass entity)
212212
// Creates the set of property definitions for OData method properties on the entity
213213
public string GetMethodProperties(OdcmClass entity)
214214
{
215+
var allMethods = new List<OdcmMethod>();
216+
foreach (var method in entity.Methods)
217+
{
218+
allMethods.Add(method);
219+
allMethods.AddRange(method.Overloads);
220+
}
221+
215222
var methodPropertiesStringBuilder = new StringBuilder();
216-
foreach(var method in entity.Methods)
223+
foreach(var method in allMethods)
217224
{
218225
var methodName = this.GetMethodName(method);
219226
var baseName = string.Concat(this.GetEntityNameString(method.Class), methodName);
@@ -229,7 +236,7 @@ public string GetMethodProperties(OdcmClass entity)
229236

230237
foreach (var param in requiredParameters)
231238
{
232-
var paramVariableName = param.Name.ToLowerFirstChar();
239+
var paramVariableName = param.Name.GetSanitizedParameterName();
233240
var paramTypeString = param.Type.GetTypeString();
234241

235242
if (param.IsCollection)
@@ -244,7 +251,7 @@ public string GetMethodProperties(OdcmClass entity)
244251

245252
foreach (var param in optionalParameters)
246253
{
247-
var paramVariableName = param.Name.ToLowerFirstChar();
254+
var paramVariableName = param.Name.GetSanitizedParameterName();
248255
var paramTypeString = param.Type.GetTypeString();
249256

250257
if (param.IsCollection)

Templates/CSharp/Model/MethodRequestBody.cs.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66
var method = host.CurrentType.AsOdcmMethod();
77
var entityName = method.Class.Name.ToCheckedCase();
88
var requestBody = entityName + method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase() + "RequestBody";
9+
10+
// These types of request bodies are only used for OData actions, which when containing parameters,
11+
// will always result in POST calls. The OData spec is explicit in saying that overload methods bound
12+
// to other types are explicitly not allowed. Therefore, any overload methods found here are invalid
13+
// and violate the spec.
14+
System.Diagnostics.Debug.Assert(!method.Overloads.Any(), "Overload actions are not allowed in OData services");
15+
916
#>
1017

1118
namespace <#=method.Namespace.GetNamespaceName()#>
1219
{
1320
using System;
1421
using System.Collections.Generic;
22+
using System.IO;
1523
using System.Runtime.Serialization;
1624

1725
/// <summary>

Templates/CSharp/Requests/EntityCollectionRequest.cs.tt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var innerEntityType = innerEntity.Name.ToCheckedCase();
88
var collectionRequest = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionRequest");
99
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionResponse");
1010
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");
11-
11+
var features = host.CurrentType.GetFeatures();
1212
#>
1313

1414
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -67,6 +67,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
6767
return null;
6868
}
6969

70+
<# if (features.CanExpand) { #>
7071
/// <summary>
7172
/// Adds the specified expand value to the request.
7273
/// </summary>
@@ -78,6 +79,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7879
return this;
7980
}
8081

82+
<# } #>
83+
<# if (features.CanSelect) { #>
8184
/// <summary>
8285
/// Adds the specified select value to the request.
8386
/// </summary>
@@ -89,6 +92,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8992
return this;
9093
}
9194

95+
<# } #>
96+
<# if (features.CanUseTop) { #>
9297
/// <summary>
9398
/// Adds the specified top value to the request.
9499
/// </summary>
@@ -99,7 +104,9 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
99104
this.QueryOptions.Add(new QueryOption("$top", value.ToString()));
100105
return this;
101106
}
102-
107+
108+
<# } #>
109+
<# if (features.CanFilter) { #>
103110
/// <summary>
104111
/// Adds the specified filter value to the request.
105112
/// </summary>
@@ -111,6 +118,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
111118
return this;
112119
}
113120

121+
<# } #>
122+
<# if (features.CanSkip) { #>
114123
/// <summary>
115124
/// Adds the specified skip value to the request.
116125
/// </summary>
@@ -122,6 +131,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
122131
return this;
123132
}
124133

134+
<# } #>
135+
<# if (features.CanSort) { #>
125136
/// <summary>
126137
/// Adds the specified orderby value to the request.
127138
/// </summary>
@@ -132,5 +143,6 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
132143
this.QueryOptions.Add(new QueryOption("$orderby", value));
133144
return this;
134145
}
146+
<# } #>
135147
}
136148
}

Templates/CSharp/Requests/EntityCollectionWithReferencesRequest.cs.tt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var propName = prop.Name.ToCheckedCase();
1111
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), propName , "CollectionWithReferencesResponse");
1212
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), propName , "CollectionWithReferencesPage");
1313

14+
var features = host.CurrentType.GetFeatures();
1415
#>
1516

1617
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -69,6 +70,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
6970
return null;
7071
}
7172

73+
<# if (features.CanExpand) { #>
7274
/// <summary>
7375
/// Adds the specified expand value to the request.
7476
/// </summary>
@@ -80,6 +82,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8082
return this;
8183
}
8284

85+
<# } #>
86+
<# if (features.CanSelect) { #>
8387
/// <summary>
8488
/// Adds the specified select value to the request.
8589
/// </summary>
@@ -91,6 +95,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
9195
return this;
9296
}
9397

98+
<# } #>
99+
<# if (features.CanUseTop) { #>
94100
/// <summary>
95101
/// Adds the specified top value to the request.
96102
/// </summary>
@@ -102,6 +108,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
102108
return this;
103109
}
104110

111+
<# } #>
112+
<# if (features.CanFilter) { #>
105113
/// <summary>
106114
/// Adds the specified filter value to the request.
107115
/// </summary>
@@ -113,6 +121,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
113121
return this;
114122
}
115123

124+
<# } #>
125+
<# if (features.CanSkip) { #>
116126
/// <summary>
117127
/// Adds the specified skip value to the request.
118128
/// </summary>
@@ -124,6 +134,8 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
124134
return this;
125135
}
126136

137+
<# } #>
138+
<# if (features.CanSort) { #>
127139
/// <summary>
128140
/// Adds the specified orderby value to the request.
129141
/// </summary>
@@ -135,4 +147,5 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
135147
return this;
136148
}
137149
}
150+
<# } #>
138151
}

Templates/CSharp/Requests/EntityReferenceRequest.cs.tt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
OdcmClass entity = host.CurrentType.AsOdcmClass();
77
var entityName = this.GetEntityNameString(entity);
88

9+
var features = host.CurrentType.GetFeatures();
10+
911
#>
1012

1113
namespace <#=this.GetNamespaceName(entity)#>
@@ -18,7 +20,9 @@ namespace <#=this.GetNamespaceName(entity)#>
1820
<#=this.GetEntityReferenceRequestClassDefinition(entity)#>
1921
{
2022
<#=this.GetEntityReferenceRequestConstructor(entity)#>
21-
23+
<# if (features.CanDelete) { #>
24+
2225
<#=this.GetEntityReferenceDeleteAsyncMethod(entity)#>
26+
<# } #>
2327
}
2428
}

Templates/CSharp/Requests/EntityRequest.cs.tt

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
OdcmClass entity = host.CurrentType.AsOdcmClass();
77
var entityName = this.GetEntityNameString(entity);
88

9+
var features = host.CurrentType.GetFeatures();
10+
911
#>
1012

1113
namespace <#=this.GetNamespaceName(entity)#>
@@ -21,42 +23,70 @@ namespace <#=this.GetNamespaceName(entity)#>
2123
{
2224
<#=this.GetEntityRequestConstructor(entity)#>
2325

24-
<#=this.GetEntityCreateAsyncMethod(entity)#>
25-
26-
<#=this.GetEntityDeleteAsyncMethod(entity)#>
26+
<#
27+
if (features.CanCreate)
28+
{
29+
Write(" ");
30+
Write(this.GetEntityCreateAsyncMethod(entity));
31+
Write("\n\n");
32+
}
2733

28-
<#=this.GetEntityGetAsyncMethod(entity)#>
34+
if (features.CanDelete)
35+
{
36+
Write(" ");
37+
Write(this.GetEntityDeleteAsyncMethod(entity));
38+
Write("\n\n");
39+
}
2940

30-
<#=this.GetEntityUpdateAsyncMethod(entity)#>
41+
Write(" ");
42+
Write(this.GetEntityGetAsyncMethod(entity));
43+
Write("\n\n");
3144

32-
<#=this.GetEntityExpandMethod(entity)#>
45+
if (features.CanUpdate)
46+
{
47+
Write(" ");
48+
Write(this.GetEntityUpdateAsyncMethod(entity));
49+
Write("\n\n");
50+
}
3351

34-
<#=this.GetEntitySelectMethod(entity)#>
52+
if (features.CanExpand)
53+
{
54+
Write(" ");
55+
Write(this.GetEntityExpandMethod(entity));
56+
Write("\n\n");
57+
}
3558

59+
if (features.CanSelect)
60+
{
61+
Write(" ");
62+
Write(this.GetEntitySelectMethod(entity));
63+
Write("\n\n");
64+
}
65+
#>
3666
/// <summary>
3767
/// Initializes any collection properties after deserialization, like next requests for paging.
3868
/// </summary>
3969
/// <param name="<#=entity.Name#>ToInitialize">The <see cref="<#=entityName#>"/> with the collection properties to initialize.</param>
4070
private void InitializeCollectionProperties(<#=entityName#> <#=entity.Name#>ToInitialize)
4171
{
42-
<#
72+
<#
4373
var navigationCollectionProperties = entity.Properties.Where(property => property.IsCollection() && property.IsNavigation());
4474

4575
if (navigationCollectionProperties.Any())
4676
{
47-
#>
77+
#>
4878

4979
if (<#=entity.Name#>ToInitialize != null && <#=entity.Name#>ToInitialize.AdditionalData != null)
5080
{
51-
<#
81+
<#
5282
foreach(var property in navigationCollectionProperties)
5383
{
5484
var propertyName = property.Name.ToCheckedCase().GetSanitizedPropertyName();
5585
var propertyType = property.GetTypeString();
5686

5787
if (propertyType.IsComplex())
5888
{
59-
#>
89+
#>
6090

6191
if (<#=entity.Name#>ToInitialize.<#=propertyName#> != null && <#=entity.Name#>ToInitialize.<#=propertyName#>.CurrentPage != null)
6292
{
@@ -73,16 +103,16 @@ namespace <#=this.GetNamespaceName(entity)#>
73103
nextPageLinkString);
74104
}
75105
}
76-
<#
106+
<#
77107
}
78108
}
79-
#>
109+
#>
80110

81111
}
82112

83-
<#
113+
<#
84114
}
85-
#>
115+
#>
86116

87117
}
88118
}

Templates/CSharp/Requests/EntityRequestBuilder.cs.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace <#=this.GetNamespaceName(entity)#>
1111
{
1212
using System;
1313
using System.Collections.Generic;
14+
using System.IO;
1415

1516
<#=this.GetEntityRequestBuilderClassDefinition(entity)#>
1617
{

0 commit comments

Comments
 (0)