@@ -47,7 +47,8 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
47
47
48
48
[ Parameter ( Mandatory = false ) ]
49
49
[ ValidateNotNull ]
50
- public object Range { get ; set ; }
50
+ [ ValidateCount ( 4 , 4 ) ]
51
+ public int [ ] Range { get ; set ; }
51
52
52
53
#if DEBUG
53
54
/// <summary>
@@ -79,18 +80,7 @@ protected override void BeginProcessing()
79
80
}
80
81
#endif
81
82
82
- try
83
- {
84
- SetRange ( ) ;
85
- }
86
- catch ( Exception e )
87
- {
88
- this . ThrowTerminatingError ( new ErrorRecord (
89
- e ,
90
- "RANGE_ERROR" ,
91
- ErrorCategory . InvalidArgument ,
92
- Range ) ) ;
93
- }
83
+ this . range = new Range ( Range [ 0 ] , Range [ 1 ] , Range [ 2 ] , Range [ 3 ] ) ;
94
84
95
85
try
96
86
{
@@ -125,59 +115,6 @@ protected override void ProcessRecord()
125
115
this . WriteObject ( formattedScriptDefinition ) ;
126
116
}
127
117
128
- private void SetRange ( )
129
- {
130
- if ( Range == null )
131
- {
132
- this . range = null ;
133
- return ;
134
- }
135
-
136
- // When the range object is constructed with `[range]::new syntax`, `Range as Range` cast works.
137
- // However, if the range object is constructed with `new-object "range"` syntax, then
138
- // we need to use the ImmediatedBaseObject property to cast.
139
- var range = ( Range as Range ?? ( Range as PSObject ) ? . ImmediateBaseObject as Range ) ;
140
- if ( range != null )
141
- {
142
- this . range = range ;
143
- return ;
144
- }
145
-
146
- var objArr = Range as object [ ] ;
147
- int [ ] intArr ;
148
- if ( objArr != null )
149
- {
150
- if ( ! objArr . All ( x => x is int ) )
151
- {
152
- throw new ArgumentException (
153
- "Array should contain integer elements." ,
154
- nameof ( Range ) ) ;
155
- }
156
- intArr = new int [ objArr . Length ] ;
157
- objArr . CopyTo ( intArr , 0 ) ;
158
- }
159
- else
160
- {
161
- // todo check passing int[] casted parameter
162
- intArr = Range as int [ ] ;
163
- if ( intArr == null )
164
- {
165
- throw new ArgumentException (
166
- "Argument should be of type Range or object[] or int[]." ,
167
- nameof ( Range ) ) ;
168
- }
169
- }
170
-
171
- if ( intArr . Length != 4 )
172
- {
173
- throw new ArgumentException (
174
- "Array should be of length 4." ,
175
- nameof ( Range ) ) ;
176
- }
177
-
178
- this . range = new Range ( intArr [ 0 ] , intArr [ 1 ] , intArr [ 2 ] , intArr [ 3 ] ) ;
179
- }
180
-
181
118
private void ValidateInputSettings ( )
182
119
{
183
120
// todo implement this
0 commit comments