Skip to content

Commit e25ea91

Browse files
committed
MethodRequest.cs.tt - refactored template, supports GET, POST, PATCH, PUT; sets HTTP verb in the async func
1 parent e63bd19 commit e25ea91

File tree

2 files changed

+478
-43
lines changed

2 files changed

+478
-43
lines changed

Templates/CSharp/Requests/IMethodRequest.cs.tt

Lines changed: 168 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCa
3030
var requestType = entityName + methodName + "Request";
3131

3232
var returnEntityType = method.ReturnType == null ? null : method.ReturnType.Name.GetTypeString().ToCheckedCase();
33+
var returnEntityParameter = string.Empty;
34+
if (returnEntityType != null) {returnEntityParameter = returnEntityType.ToLower();}
3335
var returnTypeObject = method.ReturnType == null ? null : method.ReturnType.AsOdcmClass();
3436

3537
var isCollection = method.IsCollection;
@@ -42,10 +44,6 @@ var methodReturnType = sendAsyncReturnType == null
4244
? "System.Threading.Tasks.Task"
4345
: "System.Threading.Tasks.Task<" + sendAsyncReturnType + ">";
4446

45-
var methodReturnTag = sendAsyncReturnType == null
46-
? "The task to await."
47-
: string.Concat("The", sendAsyncReturnType);
48-
4947
bool hasParameters = method.Parameters != null && method.Parameters.Any();
5048
bool includeRequestBody = hasParameters && isAction;
5149
bool returnsStream = string.Equals(sendAsyncReturnType, "Stream");
@@ -93,25 +91,183 @@ namespace <#=method.Namespace.GetNamespaceName()#>
9391
sendParameterHeadersForOverload = "/// <param name=\"cancellationToken\">The <see cref=\"CancellationToken\"/> for the request.</param>";
9492
sendOverloadParameters = "CancellationToken cancellationToken";
9593
}
94+
#>
95+
96+
<#
97+
if(isAction) // POST
98+
{
99+
#>
100+
101+
/// <summary>
102+
/// Issues the POST request.
103+
/// </summary>
104+
<#=methodReturnType#> PostAsync();
96105

97-
foreach (string httpMethod in httpMethods)
106+
/// <summary>
107+
/// Issues the POST request.
108+
/// </summary>
109+
/// <param name=""cancellationToken"">The <see cref=""CancellationToken""/> for the request.</param>
110+
<#
111+
if (returnsStream)
98112
{
113+
#>
114+
/// <param name=""httpCompletionOption"">The <see cref=""HttpCompletionOption""/> for the request.</param>
115+
<#
116+
}
117+
#>
118+
/// <returns>The task to await for async call.</returns>
119+
<#=methodReturnType#> PostAsync(
120+
<#
121+
if (returnsStream)
122+
{
123+
#>
124+
CancellationToken cancellationToken,
125+
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead);
126+
<#
127+
}
128+
else
129+
{
130+
#>
131+
CancellationToken cancellationToken);
132+
<#
133+
}
134+
#>
135+
136+
<# } // End POST
137+
99138
#>
100139

140+
<#
141+
if(method.IsFunction) // GET for a OData function.
142+
{
143+
#>
144+
/// <summary>
145+
/// Issues the GET request.
146+
/// </summary>
147+
<#=methodReturnType#> GetAsync();
148+
101149
/// <summary>
102-
/// Issues the <#=httpMethod#> request.
150+
/// Issues the GET request.
103151
/// </summary>
104-
<#=methodReturnType#> <#=httpMethod.ToLower().ToCheckedCase()#>Async();
152+
/// <param name=""cancellationToken"">The <see cref=""CancellationToken""/> for the request.</param>
153+
<#
154+
if (returnsStream)
155+
{
156+
#>
157+
/// <param name=""httpCompletionOption"">The <see cref=""HttpCompletionOption""/> for the request.</param>
158+
<#
159+
}
160+
#>
161+
/// <returns>The task to await for async call.</returns>
162+
<#=methodReturnType#> GetAsync(
163+
<#
164+
if (returnsStream)
165+
{
166+
#>
167+
CancellationToken cancellationToken,
168+
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead);
169+
<#
170+
}
171+
else
172+
{
173+
#>
174+
CancellationToken cancellationToken);
175+
<#
176+
}
177+
#>
178+
179+
<# } // End GET
180+
#>
181+
182+
<#
183+
if(method.IsFunction && method.IsComposable) // PATCH for a OData function.
184+
{
185+
#>
105186

106187
/// <summary>
107-
/// Issues the <#=httpMethod#> request.
188+
/// Issues the PATCH request.
108189
/// </summary>
109-
/// <#=sendParameterHeadersForOverload#>
110-
/// <returns><#=methodReturnTag#></returns>
111-
<#=methodReturnType#> <#=httpMethod.ToLower().ToCheckedCase()#>Async(<#=sendOverloadParameters#>);
190+
/// <param name=<#=returnEntityParameter#>>The <#=returnEntityType#> object set with the properties to update.</param>
191+
/// <returns>The task to await for async call.</returns>
192+
<#=methodReturnType#> PatchAsync(<#=returnEntityType#> <#=returnEntityParameter#>);
112193

194+
/// <summary>
195+
/// Issues the PATCH request.
196+
/// </summary>
197+
/// <param name=<#=returnEntityParameter#>>The <#=returnEntityType#> object set with the properties to update.</param>
198+
/// <param name=""cancellationToken"">The <see cref=""CancellationToken""/> for the request.</param>
199+
<#
200+
if (returnsStream)
201+
{
202+
#>
203+
/// <param name=""httpCompletionOption"">The <see cref=""HttpCompletionOption""/> for the request.</param>
204+
<#
205+
}
206+
#>
207+
/// <returns>The task to await for async call.</returns>
208+
<#=methodReturnType#> PatchAsync(<#=returnEntityType#> <#=returnEntityParameter#>,
209+
<#
210+
if (returnsStream)
211+
{
212+
#>
213+
CancellationToken cancellationToken,
214+
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead);
215+
<#
216+
}
217+
else
218+
{
219+
#>
220+
CancellationToken cancellationToken);
221+
<#
222+
}
223+
#>
224+
225+
<# } // End PATCH for a OData function.
226+
#>
113227
<#
114-
} // end foreach
228+
if(method.IsFunction && method.IsComposable) // PUT for a OData function.
229+
{
230+
#>
231+
232+
/// <summary>
233+
/// Issues the PUT request.
234+
/// </summary>
235+
/// <param name=<#=returnEntityParameter#>>The <#=returnEntityType#> object to update.</param>
236+
/// <returns>The task to await for async call.</returns>
237+
<#=methodReturnType#> PutAsync(<#=returnEntityType#> <#=returnEntityParameter#>);
238+
239+
/// <summary>
240+
/// Issues the PUT request.
241+
/// </summary>
242+
/// <param name=<#=returnEntityParameter#>>The <#=returnEntityType#> object to update.</param>
243+
/// <param name=""cancellationToken"">The <see cref=""CancellationToken""/> for the request.</param>
244+
<#
245+
if (returnsStream)
246+
{
247+
#>
248+
/// <param name=""httpCompletionOption"">The <see cref=""HttpCompletionOption""/> for the request.</param>
249+
<#
250+
}
251+
#>
252+
/// <returns>The task to await for async call.</returns>
253+
<#=methodReturnType#> PutAsync(<#=returnEntityType#> <#=returnEntityParameter#>,
254+
<#
255+
if (returnsStream)
256+
{
257+
#>
258+
CancellationToken cancellationToken,
259+
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead);
260+
<#
261+
}
262+
else
263+
{
264+
#>
265+
CancellationToken cancellationToken);
266+
<#
267+
}
268+
#>
269+
270+
<# } // End PUT for a OData function.
115271
#>
116272

117273

0 commit comments

Comments
 (0)