@@ -20,33 +20,36 @@ namespace AutoRest.CSharp.Output.Models
2020{
2121 internal class LowLevelClient : TypeProvider
2222 {
23+ private readonly string _libraryName ;
24+ private readonly TypeFactory _typeFactory ;
25+ private readonly IEnumerable < InputParameter > _clientParameters ;
26+ private readonly InputAuth _authorization ;
27+ private readonly IEnumerable < InputOperation > _operations ;
28+
2329 protected override string DefaultName { get ; }
2430 protected override string DefaultNamespace { get ; }
2531 protected override string DefaultAccessibility => "public" ;
2632
2733 private ConstructorSignature ? _subClientInternalConstructor ;
2834
2935 public string Description { get ; }
30- public ConstructorSignature [ ] PrimaryConstructors { get ; }
31- public ConstructorSignature [ ] SecondaryConstructors { get ; }
3236 public ConstructorSignature SubClientInternalConstructor => _subClientInternalConstructor ??= BuildSubClientInternalConstructor ( ) ;
3337
3438 public IReadOnlyList < LowLevelClient > SubClients { get ; init ; }
35- public IReadOnlyList < RestClientMethod > RequestMethods { get ; }
36- public IReadOnlyList < ResponseClassifierType > ResponseClassifierTypes { get ; }
37- public IReadOnlyList < LowLevelClientMethod > ClientMethods { get ; }
3839 public LowLevelClient ? ParentClient ;
39- public LowLevelSubClientFactoryMethod ? FactoryMethod { get ; }
4040
4141 public ClientOptionsTypeProvider ClientOptions { get ; }
42- public IReadOnlyList < Parameter > Parameters { get ; }
43- public ClientFields Fields { get ; }
42+
4443 public bool IsSubClient { get ; }
45- public bool IsResourceClient { get ; }
44+
45+ private bool ? _isResourceClient ;
46+ public bool IsResourceClient => _isResourceClient ??= Parameters . Any ( p => p . IsResourceIdentifier ) ;
4647
4748 public LowLevelClient ( string name , string ns , string description , string libraryName , LowLevelClient ? parentClient , IEnumerable < InputOperation > operations , IEnumerable < InputParameter > clientParameters , InputAuth authorization , SourceInputModel ? sourceInputModel , ClientOptionsTypeProvider clientOptions , TypeFactory typeFactory )
4849 : base ( ns , sourceInputModel )
4950 {
51+ _libraryName = libraryName ;
52+ _typeFactory = typeFactory ;
5053 DefaultName = name ;
5154 DefaultNamespace = ns ;
5255 Description = description ;
@@ -55,29 +58,43 @@ public LowLevelClient(string name, string ns, string description, string library
5558
5659 ClientOptions = clientOptions ;
5760
58- Parameters = new RestClientBuilder ( clientParameters , typeFactory ) . GetOrderedParametersByRequired ( ) ;
59- IsResourceClient = Parameters . Any ( p => p . IsResourceIdentifier ) ;
60- Fields = ClientFields . CreateForClient ( Parameters , authorization ) ;
61+ _clientParameters = clientParameters ;
62+ _authorization = authorization ;
63+ _operations = operations ;
64+
65+ SubClients = Array . Empty < LowLevelClient > ( ) ;
66+ }
6167
62- ( PrimaryConstructors , SecondaryConstructors ) = BuildPublicConstructors ( Parameters ) ;
68+ private IReadOnlyList < Parameter > ? _parameters ;
69+ public IReadOnlyList < Parameter > Parameters => _parameters ??= new RestClientBuilder ( _clientParameters , _typeFactory ) . GetOrderedParametersByRequired ( ) ;
6370
64- var clientMethods = BuildMethods ( typeFactory , operations , Fields , Declaration . Name ) . ToArray ( ) ;
71+ private ClientFields ? _fields ;
72+ public ClientFields Fields => _fields ??= ClientFields . CreateForClient ( Parameters , _authorization ) ;
6573
66- ClientMethods = clientMethods
74+ private ( ConstructorSignature [ ] PrimaryConstructors , ConstructorSignature [ ] SecondaryConstructors ) ? _constructors ;
75+ private ( ConstructorSignature [ ] PrimaryConstructors , ConstructorSignature [ ] SecondaryConstructors ) Constructors => _constructors ??= BuildPublicConstructors ( Parameters ) ;
76+ public ConstructorSignature [ ] PrimaryConstructors => Constructors . PrimaryConstructors ;
77+ public ConstructorSignature [ ] SecondaryConstructors => Constructors . SecondaryConstructors ;
78+
79+ private IReadOnlyList < LowLevelClientMethod > ? _allClientMethods ;
80+ private IReadOnlyList < LowLevelClientMethod > AllClientMethods => _allClientMethods ??= BuildMethods ( _typeFactory , _operations , Fields , Declaration . Name ) . ToArray ( ) ;
81+
82+ private IReadOnlyList < LowLevelClientMethod > ? _clientMethods ;
83+ public IReadOnlyList < LowLevelClientMethod > ClientMethods => _clientMethods ??= AllClientMethods
6784 . OrderBy ( m => m . LongRunning != null ? 2 : m . PagingInfo != null ? 1 : 0 ) // Temporary sorting to minimize amount of changed files. Will be removed when new LRO is implemented
6885 . ToArray ( ) ;
6986
70- RequestMethods = clientMethods . Select ( m => m . RequestMethod )
87+ private IReadOnlyList < RestClientMethod > ? _requestMethods ;
88+ public IReadOnlyList < RestClientMethod > RequestMethods => _requestMethods ??= AllClientMethods . Select ( m => m . RequestMethod )
7189 . Concat ( ClientMethods . Select ( m => m . PagingInfo ? . NextPageMethod ) . WhereNotNull ( ) )
7290 . Distinct ( )
7391 . ToArray ( ) ;
7492
75- ResponseClassifierTypes = RequestMethods . Select ( m => m . ResponseClassifierType ) . ToArray ( ) ;
76-
77- FactoryMethod = parentClient != null ? BuildFactoryMethod ( parentClient . Fields , libraryName ) : null ;
93+ private IReadOnlyList < ResponseClassifierType > ? _responseClassifierTypes ;
94+ public IReadOnlyList < ResponseClassifierType > ResponseClassifierTypes => _responseClassifierTypes ??= RequestMethods . Select ( m => m . ResponseClassifierType ) . ToArray ( ) ;
7895
79- SubClients = Array . Empty < LowLevelClient > ( ) ;
80- }
96+ private LowLevelSubClientFactoryMethod ? _factoryMethod ;
97+ public LowLevelSubClientFactoryMethod ? FactoryMethod => _factoryMethod ??= ParentClient != null ? BuildFactoryMethod ( ParentClient . Fields , _libraryName ) : null ;
8198
8299 public static IEnumerable < LowLevelClientMethod > BuildMethods ( TypeFactory typeFactory , IEnumerable < InputOperation > operations , ClientFields fields , string clientName )
83100 {
0 commit comments