20
20
using System . Collections ;
21
21
using System . Collections . Generic ;
22
22
using System . IO ;
23
- using System . Runtime . CompilerServices ;
24
23
using static Microsoft . TypeSpec . Generator . Snippets . Snippet ;
25
24
26
25
namespace Azure . Generator . Management . Providers
@@ -30,9 +29,9 @@ internal sealed class ResourceCollectionClientProvider : TypeProvider
30
29
private readonly ResourceMetadata _resourceMetadata ;
31
30
32
31
private readonly ResourceClientProvider _resource ;
33
- private readonly InputServiceMethod ? _getAll ;
34
- private readonly InputServiceMethod ? _create ;
35
- private readonly InputServiceMethod ? _get ;
32
+ private readonly ResourceMethod ? _getAll ;
33
+ private readonly ResourceMethod ? _create ;
34
+ private readonly ResourceMethod ? _get ;
36
35
37
36
// Support for multiple rest clients
38
37
private readonly Dictionary < InputClient , RestClientInfo > _clientInfos ;
@@ -79,9 +78,9 @@ private static RequestPathPattern GetContextualRequestPattern(ResourceMetadata r
79
78
80
79
private static void InitializeMethods (
81
80
ResourceMetadata resourceMetadata ,
82
- ref InputServiceMethod ? getMethod ,
83
- ref InputServiceMethod ? createMethod ,
84
- ref InputServiceMethod ? getAllMethod )
81
+ ref ResourceMethod ? getMethod ,
82
+ ref ResourceMethod ? createMethod ,
83
+ ref ResourceMethod ? getAllMethod )
85
84
{
86
85
foreach ( var method in resourceMetadata . Methods )
87
86
{
@@ -93,32 +92,16 @@ private static void InitializeMethods(
93
92
switch ( method . Kind )
94
93
{
95
94
case ResourceOperationKind . Get :
96
- AssignMethodKind ( ref getMethod , resourceMetadata . ResourceIdPattern , method ) ;
95
+ getMethod = method ;
97
96
break ;
98
97
case ResourceOperationKind . List :
99
- AssignMethodKind ( ref getAllMethod , resourceMetadata . ResourceIdPattern , method ) ;
98
+ getAllMethod = method ;
100
99
break ;
101
100
case ResourceOperationKind . Create :
102
- AssignMethodKind ( ref createMethod , resourceMetadata . ResourceIdPattern , method ) ;
101
+ createMethod = method ;
103
102
break ;
104
103
}
105
104
}
106
-
107
- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
108
- static void AssignMethodKind ( ref InputServiceMethod ? method , string resourceIdPattern , ResourceMethod resourceMethod )
109
- {
110
- if ( method is not null )
111
- {
112
- ManagementClientGenerator . Instance . Emitter . ReportDiagnostic (
113
- "general-warning" , // TODO -- in the near future, we should have a resource-specific diagnostic ID
114
- $ "Resource { resourceIdPattern } has multiple '{ resourceMethod . Kind } ' methods."
115
- ) ;
116
- }
117
- else
118
- {
119
- method = ManagementClientGenerator . Instance . InputLibrary . GetMethodByCrossLanguageDefinitionId ( resourceMethod . Id ) ;
120
- }
121
- }
122
105
}
123
106
124
107
public ResourceClientProvider Resource => _resource ;
@@ -262,64 +245,64 @@ private MethodProvider[] BuildEnumeratorMethods()
262
245
263
246
private List < MethodProvider > BuildCreateOrUpdateMethods ( )
264
247
{
265
- var result = new List < MethodProvider > ( ) ;
266
248
if ( _create is null )
267
249
{
268
- return result ;
250
+ return [ ] ;
269
251
}
270
252
271
- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _create , _clientInfos ) ;
253
+ var result = new List < MethodProvider > ( ) ;
254
+ var restClientInfo = _clientInfos [ _create . InputClient ] ;
272
255
foreach ( var isAsync in new List < bool > { true , false } )
273
256
{
274
- var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _create ! . Operation , isAsync ) ;
257
+ var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _create . InputMethod . Operation , isAsync ) ;
275
258
var methodName = ResourceHelpers . GetOperationMethodName ( ResourceOperationKind . Create , isAsync ) ;
276
- result . Add ( new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , _create , isAsync , methodName , forceLro : true ) ) ;
259
+ result . Add ( new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , _create . InputMethod , isAsync , methodName : methodName , forceLro : true ) ) ;
277
260
}
278
261
279
262
return result ;
280
263
}
281
264
282
- private MethodProvider BuildGetAllMethod ( InputServiceMethod getAll , bool isAsync )
265
+ private MethodProvider BuildGetAllMethod ( ResourceMethod getAll , bool isAsync )
283
266
{
284
- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( getAll , _clientInfos ) ;
285
- return getAll switch
267
+ var restClientInfo = _clientInfos [ getAll . InputClient ] ;
268
+ return getAll . InputMethod switch
286
269
{
287
270
InputPagingServiceMethod pagingGetAll => new PageableOperationMethodProvider ( this , ContextualPath , restClientInfo , pagingGetAll , isAsync , ResourceOperationKind . List ) ,
288
- _ => new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , getAll , isAsync , ResourceHelpers . GetOperationMethodName ( ResourceOperationKind . List , isAsync ) )
271
+ _ => new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , getAll . InputMethod , isAsync , ResourceHelpers . GetOperationMethodName ( ResourceOperationKind . List , isAsync ) )
289
272
} ;
290
273
}
291
274
292
275
private List < MethodProvider > BuildGetMethods ( )
293
276
{
294
- var result = new List < MethodProvider > ( ) ;
295
277
if ( _get is null )
296
278
{
297
- return result ;
279
+ return [ ] ;
298
280
}
299
281
300
- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
282
+ var result = new List < MethodProvider > ( ) ;
283
+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
301
284
foreach ( var isAsync in new List < bool > { true , false } )
302
285
{
303
- var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get ! . Operation , isAsync ) ;
304
- result . Add ( new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , _get , isAsync ) ) ;
286
+ var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get . InputMethod . Operation , isAsync ) ;
287
+ result . Add ( new ResourceOperationMethodProvider ( this , ContextualPath , restClientInfo , _get . InputMethod , isAsync ) ) ;
305
288
}
306
289
307
290
return result ;
308
291
}
309
292
310
293
private List < MethodProvider > BuildExistsMethods ( )
311
294
{
312
- var result = new List < MethodProvider > ( ) ;
313
295
if ( _get is null )
314
296
{
315
- return result ;
297
+ return [ ] ;
316
298
}
317
299
318
- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
300
+ var result = new List < MethodProvider > ( ) ;
301
+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
319
302
foreach ( var isAsync in new List < bool > { true , false } )
320
303
{
321
- var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get ! . Operation , isAsync ) ;
322
- var existsMethodProvider = new ExistsOperationMethodProvider ( this , restClientInfo , _get , isAsync ) ;
304
+ var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get . InputMethod . Operation , isAsync ) ;
305
+ var existsMethodProvider = new ExistsOperationMethodProvider ( this , restClientInfo , _get . InputMethod , isAsync ) ;
323
306
result . Add ( existsMethodProvider ) ;
324
307
}
325
308
@@ -334,11 +317,11 @@ private List<MethodProvider> BuildGetIfExistsMethods()
334
317
return result ;
335
318
}
336
319
337
- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
320
+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
338
321
foreach ( var isAsync in new List < bool > { true , false } )
339
322
{
340
- var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get ! . Operation , isAsync ) ;
341
- var getIfExistsMethodProvider = new GetIfExistsOperationMethodProvider ( this , restClientInfo , _get , isAsync ) ;
323
+ var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _get . InputMethod . Operation , isAsync ) ;
324
+ var getIfExistsMethodProvider = new GetIfExistsOperationMethodProvider ( this , restClientInfo , _get . InputMethod , isAsync ) ;
342
325
result . Add ( getIfExistsMethodProvider ) ;
343
326
}
344
327
0 commit comments