2020using System . Collections ;
2121using System . Collections . Generic ;
2222using System . IO ;
23- using System . Runtime . CompilerServices ;
2423using static Microsoft . TypeSpec . Generator . Snippets . Snippet ;
2524
2625namespace Azure . Generator . Management . Providers
@@ -30,9 +29,9 @@ internal sealed class ResourceCollectionClientProvider : TypeProvider
3029 private readonly ResourceMetadata _resourceMetadata ;
3130
3231 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 ;
3635
3736 // Support for multiple rest clients
3837 private readonly Dictionary < InputClient , RestClientInfo > _clientInfos ;
@@ -79,9 +78,9 @@ private static RequestPathPattern GetContextualRequestPattern(ResourceMetadata r
7978
8079 private static void InitializeMethods (
8180 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 )
8584 {
8685 foreach ( var method in resourceMetadata . Methods )
8786 {
@@ -93,32 +92,16 @@ private static void InitializeMethods(
9392 switch ( method . Kind )
9493 {
9594 case ResourceOperationKind . Get :
96- AssignMethodKind ( ref getMethod , resourceMetadata . ResourceIdPattern , method ) ;
95+ getMethod = method ;
9796 break ;
9897 case ResourceOperationKind . List :
99- AssignMethodKind ( ref getAllMethod , resourceMetadata . ResourceIdPattern , method ) ;
98+ getAllMethod = method ;
10099 break ;
101100 case ResourceOperationKind . Create :
102- AssignMethodKind ( ref createMethod , resourceMetadata . ResourceIdPattern , method ) ;
101+ createMethod = method ;
103102 break ;
104103 }
105104 }
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- }
122105 }
123106
124107 public ResourceClientProvider Resource => _resource ;
@@ -262,64 +245,64 @@ private MethodProvider[] BuildEnumeratorMethods()
262245
263246 private List < MethodProvider > BuildCreateOrUpdateMethods ( )
264247 {
265- var result = new List < MethodProvider > ( ) ;
266248 if ( _create is null )
267249 {
268- return result ;
250+ return [ ] ;
269251 }
270252
271- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _create , _clientInfos ) ;
253+ var result = new List < MethodProvider > ( ) ;
254+ var restClientInfo = _clientInfos [ _create . InputClient ] ;
272255 foreach ( var isAsync in new List < bool > { true , false } )
273256 {
274- var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _create ! . Operation , isAsync ) ;
257+ var convenienceMethod = restClientInfo . RestClientProvider . GetConvenienceMethodByOperation ( _create . InputMethod . Operation , isAsync ) ;
275258 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 ) ) ;
277260 }
278261
279262 return result ;
280263 }
281264
282- private MethodProvider BuildGetAllMethod ( InputServiceMethod getAll , bool isAsync )
265+ private MethodProvider BuildGetAllMethod ( ResourceMethod getAll , bool isAsync )
283266 {
284- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( getAll , _clientInfos ) ;
285- return getAll switch
267+ var restClientInfo = _clientInfos [ getAll . InputClient ] ;
268+ return getAll . InputMethod switch
286269 {
287270 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 ) )
289272 } ;
290273 }
291274
292275 private List < MethodProvider > BuildGetMethods ( )
293276 {
294- var result = new List < MethodProvider > ( ) ;
295277 if ( _get is null )
296278 {
297- return result ;
279+ return [ ] ;
298280 }
299281
300- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
282+ var result = new List < MethodProvider > ( ) ;
283+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
301284 foreach ( var isAsync in new List < bool > { true , false } )
302285 {
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 ) ) ;
305288 }
306289
307290 return result ;
308291 }
309292
310293 private List < MethodProvider > BuildExistsMethods ( )
311294 {
312- var result = new List < MethodProvider > ( ) ;
313295 if ( _get is null )
314296 {
315- return result ;
297+ return [ ] ;
316298 }
317299
318- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
300+ var result = new List < MethodProvider > ( ) ;
301+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
319302 foreach ( var isAsync in new List < bool > { true , false } )
320303 {
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 ) ;
323306 result . Add ( existsMethodProvider ) ;
324307 }
325308
@@ -334,11 +317,11 @@ private List<MethodProvider> BuildGetIfExistsMethods()
334317 return result ;
335318 }
336319
337- var restClientInfo = _resourceMetadata . GetRestClientForServiceMethod ( _get , _clientInfos ) ;
320+ var restClientInfo = _clientInfos [ _get . InputClient ] ;
338321 foreach ( var isAsync in new List < bool > { true , false } )
339322 {
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 ) ;
342325 result . Add ( getIfExistsMethodProvider ) ;
343326 }
344327
0 commit comments