@@ -546,59 +546,43 @@ public ValueTable CopyColumns(string columnNames = null)
546546 [ ContextMethod ( "Скопировать" , "Copy" ) ]
547547 public ValueTable Copy ( IValue rows = null , string columnNames = null )
548548 {
549- var Result = CopyColumns ( columnNames ) ;
549+ var result = CopyColumns ( columnNames ) ;
550550 var columns = GetProcessingColumnList ( columnNames ) ;
551551
552- IEnumerable < ValueTableRow > requestedRows ;
553- if ( rows == null )
554- {
555- requestedRows = _rows ;
556- }
557- else
558- {
559- if ( rows is StructureImpl structure )
560- requestedRows = FindRows ( structure ) . Select ( x => x as ValueTableRow ) ;
561- else if ( rows is ArrayImpl array )
562- requestedRows = GetRowsEnumByArray ( array ) ;
563- else
564- throw RuntimeException . InvalidArgumentType ( ) ;
565- }
552+ IEnumerable < ValueTableRow > requestedRows = rows switch
553+ {
554+ null => _rows ,
555+ StructureImpl structure => FindRows ( structure ) . Select ( x => x as ValueTableRow ) ,
556+ ArrayImpl array => GetRowsEnumByArray ( array ) ,
557+ _ => throw RuntimeException . InvalidArgumentType ( ) ,
558+ } ;
566559
567560 var columnMap = new Dictionary < ValueTableColumn , ValueTableColumn > ( ) ;
568561 foreach ( var column in columns )
569562 {
570- var destinationColumn = Result . Columns . FindColumnByName ( column . Name ) ;
563+ var destinationColumn = result . Columns . FindColumnByName ( column . Name ) ;
571564 columnMap . Add ( column , destinationColumn ) ;
572565 }
573566
574567 foreach ( var row in requestedRows )
575568 {
576- var new_row = Result . Add ( ) ;
569+ var new_row = result . Add ( ) ;
577570 foreach ( var Column in columns )
578571 {
579572 new_row . Set ( columnMap [ Column ] , row . Get ( Column ) ) ;
580573 }
581574 }
582575
583- return Result ;
576+ return result ;
584577 }
585578
586- private IEnumerable < ValueTableRow > GetRowsEnumByArray ( IValue rows )
587- {
588- IEnumerable < ValueTableRow > requestedRows ;
589- var rowsArray = rows as ArrayImpl ;
579+ private IEnumerable < ValueTableRow > GetRowsEnumByArray ( ArrayImpl rowsArray )
580+ {
590581 if ( rowsArray == null )
591582 throw RuntimeException . InvalidArgumentType ( ) ;
592583
593- requestedRows = rowsArray . Select ( x =>
594- {
595- var vtr = x as ValueTableRow ;
596- if ( vtr == null || vtr . Owner ( ) != this )
597- throw RuntimeException . InvalidArgumentValue ( ) ;
598-
599- return vtr ;
600- } ) ;
601- return requestedRows ;
584+ return rowsArray . Select ( x => x is ValueTableRow vtr && vtr . Owner ( ) == this ? vtr
585+ : throw RuntimeException . InvalidArgumentValue ( ) ) ;
602586 }
603587
604588 private struct ValueTableSortRule
0 commit comments