@@ -45,7 +45,10 @@ public ValueTableColumnCollection(ValueTable owner)
4545 /// <returns>КолонкаТаблицыЗначений</returns>
4646 [ ContextMethod ( "Добавить" , "Add" ) ]
4747 public ValueTableColumn Add ( string name , TypeDescription type = null , string title = null , int width = 0 )
48- {
48+ {
49+ if ( ! Utils . IsValidIdentifier ( name ) )
50+ throw ColumnException . WrongColumnName ( name ) ;
51+
4952 if ( FindColumnByName ( name ) != null )
5053 throw ColumnException . DuplicatedColumnName ( name ) ;
5154
@@ -67,6 +70,9 @@ public ValueTableColumn Add(string name, TypeDescription type = null, string tit
6770 [ ContextMethod ( "Вставить" , "Insert" ) ]
6871 public ValueTableColumn Insert ( int index , string name , TypeDescription type = null , string title = null , int width = 0 )
6972 {
73+ if ( ! Utils . IsValidIdentifier ( name ) )
74+ throw ColumnException . WrongColumnName ( name ) ;
75+
7076 if ( FindColumnByName ( name ) != null )
7177 throw ColumnException . DuplicatedColumnName ( name ) ;
7278
@@ -125,7 +131,7 @@ public IValue Find(string name)
125131 public void Delete ( IValue column )
126132 {
127133 var vtColumn = GetColumnByIIndex ( column ) ;
128- _owner . ForEach ( ( ValueTableRow x ) =>
134+ _owner . ForEach ( ( ValueTableRow x ) =>
129135 {
130136 x . OnOwnerColumnRemoval ( vtColumn ) ;
131137 } ) ;
@@ -150,10 +156,7 @@ public ValueTableColumn FindColumnByName(string name)
150156 return _columns . Find ( column => _namesComparer . Equals ( name , column . Name ) ) ;
151157 }
152158
153- public ValueTableColumn FindColumnByIndex ( int index )
154- {
155- return _columns [ index ] ;
156- }
159+ public ValueTableColumn FindColumnByIndex ( int index ) => _columns [ index ] ;
157160
158161 public IEnumerator < ValueTableColumn > GetEnumerator ( )
159162 {
@@ -170,10 +173,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
170173
171174 public override bool IsIndexed => true ;
172175
173- public override IValue GetIndexedValue ( IValue index )
174- {
175- return GetColumnByIIndex ( index ) ;
176- }
176+ public override IValue GetIndexedValue ( IValue index ) => GetColumnByIIndex ( index ) ;
177177
178178 public override int GetPropertyNumber ( string name )
179179 {
@@ -183,11 +183,8 @@ public override int GetPropertyNumber(string name)
183183 return idx ;
184184 }
185185
186- public override int GetPropCount ( )
187- {
188- return _columns . Count ;
189- }
190-
186+ public override int GetPropCount ( ) => _columns . Count ;
187+
191188 public override string GetPropName ( int propNum )
192189 {
193190 return FindColumnByIndex ( propNum ) . Name ;
@@ -198,39 +195,30 @@ public override IValue GetPropValue(int propNum)
198195 return FindColumnByIndex ( propNum ) ;
199196 }
200197
201- public override bool IsPropWritable ( int propNum )
202- {
203- return false ;
204- }
205-
206- public override bool IsPropReadable ( int propNum )
207- {
208- return true ;
209- }
198+ public override bool IsPropWritable ( int propNum ) => false ;
199+
200+ public override bool IsPropReadable ( int propNum ) => true ;
210201
211202 public ValueTableColumn GetColumnByIIndex ( IValue index )
212203 {
213204 if ( index . SystemType == BasicTypes . String )
214205 {
215- ValueTableColumn Column = FindColumnByName ( index . ToString ( ) ) ;
216- if ( Column == null )
217- throw PropertyAccessException . PropNotFoundException ( index . ToString ( ) ) ;
218- return Column ;
206+ return FindColumnByName ( index . ToString ( ) )
207+ ?? throw PropertyAccessException . PropNotFoundException ( index . ToString ( ) ) ;
219208 }
220209
221210 if ( index . SystemType == BasicTypes . Number )
222211 {
223212 int i_index = Decimal . ToInt32 ( index . AsNumber ( ) ) ;
224213 if ( i_index < 0 || i_index >= Count ( ) )
225- throw RuntimeException . InvalidArgumentValue ( ) ;
214+ throw RuntimeException . IndexOutOfRange ( ) ;
226215
227- ValueTableColumn Column = FindColumnByIndex ( i_index ) ;
228- return Column ;
216+ return FindColumnByIndex ( i_index ) ;
229217 }
230218
231- if ( index is ValueTableColumn )
219+ if ( index is ValueTableColumn column )
232220 {
233- return index as ValueTableColumn ;
221+ return column ;
234222 }
235223
236224 throw RuntimeException . InvalidArgumentType ( ) ;
@@ -247,13 +235,12 @@ public int GetColumnNumericIndex(IValue index)
247235 {
248236 int iIndex = Decimal . ToInt32 ( index . AsNumber ( ) ) ;
249237 if ( iIndex < 0 || iIndex >= Count ( ) )
250- throw RuntimeException . InvalidArgumentValue ( ) ;
238+ throw RuntimeException . IndexOutOfRange ( ) ;
251239
252240 return iIndex ;
253241 }
254242
255- var column = index as ValueTableColumn ;
256- if ( column != null )
243+ if ( index is ValueTableColumn column )
257244 {
258245 return IndexOf ( column ) ;
259246 }
0 commit comments