@@ -31,13 +31,11 @@ namespace Microsoft.Azure.Commands.Profile
31
31
SupportsShouldProcess = true ) ]
32
32
[ Alias ( "Select-AzureRmSubscription" ) ]
33
33
[ OutputType ( typeof ( PSAzureContext ) ) ]
34
- public class SetAzureRMContextCommand : AzureRMCmdlet , IDynamicParameters
34
+ public class SetAzureRMContextCommand : AzureRMCmdlet
35
35
{
36
36
private const string SubscriptionNameParameterSet = "SubscriptionName" ;
37
37
private const string SubscriptionIdParameterSet = "SubscriptionId" ;
38
38
private const string ContextParameterSet = "Context" ;
39
- private RuntimeDefinedParameter _tenantId ;
40
- private RuntimeDefinedParameter _subscriptionId ;
41
39
42
40
[ Parameter ( ParameterSetName = SubscriptionNameParameterSet , Mandatory = false , HelpMessage = "Subscription Name" , ValueFromPipelineByPropertyName = true ) ]
43
41
[ ValidateNotNullOrEmpty ]
@@ -46,21 +44,16 @@ public class SetAzureRMContextCommand : AzureRMCmdlet, IDynamicParameters
46
44
[ Parameter ( ParameterSetName = ContextParameterSet , Mandatory = true , HelpMessage = "Context" , ValueFromPipeline = true ) ]
47
45
public PSAzureContext Context { get ; set ; }
48
46
49
- private string TenantId
50
- {
51
- get
52
- {
53
- return _tenantId == null ? null : ( string ) _tenantId . Value ;
54
- }
55
- }
47
+ [ Parameter ( ParameterSetName = SubscriptionNameParameterSet , Mandatory = false ,
48
+ HelpMessage = "Tenant name or ID" , ValueFromPipelineByPropertyName = true ) ]
49
+ [ Parameter ( ParameterSetName = SubscriptionIdParameterSet , Mandatory = false ,
50
+ HelpMessage = "Tenant name or ID" , ValueFromPipelineByPropertyName = true ) ]
51
+ [ Alias ( "Domain" ) ]
52
+ public string TenantId { get ; set ; }
56
53
57
- private string SubscriptionId
58
- {
59
- get
60
- {
61
- return _subscriptionId == null ? null : ( string ) _subscriptionId . Value ;
62
- }
63
- }
54
+ [ Parameter ( ParameterSetName = SubscriptionIdParameterSet , Mandatory = false ,
55
+ HelpMessage = "Subscription Identifer (GUID)" , ValueFromPipelineByPropertyName = true ) ]
56
+ public string SubscriptionId { get ; set ; }
64
57
65
58
public override void ExecuteCmdlet ( )
66
59
{
@@ -127,79 +120,5 @@ private void CompleteContextProcessing()
127
120
}
128
121
WriteObject ( ( PSAzureContext ) AzureRmProfileProvider . Instance . Profile . Context ) ;
129
122
}
130
-
131
- public object GetDynamicParameters ( )
132
- {
133
- return CreateDynamicParameterDictionary ( ) ;
134
- }
135
-
136
- private RuntimeDefinedParameterDictionary CreateDynamicParameterDictionary ( )
137
- {
138
- var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary ( ) ;
139
-
140
- var subscriptionIdAttributes = new Collection < Attribute >
141
- {
142
- new ParameterAttribute
143
- {
144
- ParameterSetName = SubscriptionIdParameterSet ,
145
- Mandatory = false ,
146
- HelpMessage = "Subscription" ,
147
- ValueFromPipelineByPropertyName = true
148
- }
149
- } ;
150
-
151
- var tenantIdAttributes = new Collection < Attribute >
152
- {
153
- new ParameterAttribute
154
- {
155
- ParameterSetName = SubscriptionNameParameterSet ,
156
- Mandatory = false ,
157
- HelpMessage = "Tenant name or ID" ,
158
- ValueFromPipelineByPropertyName = true
159
- } ,
160
- new ParameterAttribute
161
- {
162
- ParameterSetName = SubscriptionIdParameterSet ,
163
- Mandatory = false ,
164
- HelpMessage = "Tenant name or ID" ,
165
- ValueFromPipelineByPropertyName = true
166
- } ,
167
- new AliasAttribute ( "Domain" )
168
- } ;
169
-
170
- if ( AzureRmProfileProvider . Instance != null
171
- && AzureRmProfileProvider . Instance . Profile != null
172
- && AzureRmProfileProvider . Instance . Profile . Context != null
173
- && AzureRmProfileProvider . Instance . Profile . Context . Account != null )
174
- {
175
- var account = AzureRmProfileProvider . Instance . Profile . Context . Account ;
176
- if ( account . IsPropertySet ( AzureAccount . Property . Subscriptions ) )
177
- {
178
- var subscriptions = account . GetPropertyAsArray ( AzureAccount . Property . Subscriptions ) ;
179
- if ( subscriptions != null && subscriptions . Length > 0 )
180
- {
181
- subscriptionIdAttributes . Add (
182
- new ValidateSetAttribute ( subscriptions ) ) ;
183
- }
184
- }
185
- if ( account . IsPropertySet ( AzureAccount . Property . Tenants ) )
186
- {
187
- var tenants = account . GetPropertyAsArray ( AzureAccount . Property . Tenants ) ;
188
- if ( tenants != null && tenants . Length > 0 )
189
- {
190
- tenantIdAttributes . Add (
191
- new ValidateSetAttribute ( tenants ) ) ;
192
- }
193
- }
194
- }
195
-
196
- _tenantId = new RuntimeDefinedParameter ( "TenantId" , typeof ( string ) , tenantIdAttributes ) ;
197
- _subscriptionId = new RuntimeDefinedParameter ( "SubscriptionId" , typeof ( string ) , subscriptionIdAttributes ) ;
198
-
199
- runtimeDefinedParameterDictionary . Add ( "SubscriptionId" , _subscriptionId ) ;
200
- runtimeDefinedParameterDictionary . Add ( "TenantId" , _tenantId ) ;
201
-
202
- return runtimeDefinedParameterDictionary ;
203
- }
204
123
}
205
124
}
0 commit comments