@@ -10,11 +10,11 @@ This Source Code Form is subject to the terms of the
1010using System . Linq ;
1111using OneScript . Contexts ;
1212using OneScript . Exceptions ;
13+ using OneScript . Execution ;
1314using OneScript . Types ;
1415using OneScript . Values ;
1516using ScriptEngine . Machine ;
1617using ScriptEngine . Machine . Contexts ;
17- using ScriptEngine . Types ;
1818
1919namespace OneScript . StandardLibrary . Collections . ValueTree
2020{
@@ -362,12 +362,12 @@ private List<ValueTreeSortRule> GetSortRules(string columns)
362362 {
363363 string [ ] description = column . Trim ( ) . Split ( ' ' ) ;
364364 if ( description . Count ( ) == 0 )
365- throw PropertyAccessException . PropNotFoundException ( "" ) ; // TODO: WrongColumnNameException
365+ throw WrongColumnNameException ( ) ;
366366
367367 ValueTreeSortRule desc = new ValueTreeSortRule ( ) ;
368368 desc . Column = this . Columns . FindColumnByName ( description [ 0 ] ) ;
369369 if ( desc . Column == null )
370- throw PropertyAccessException . PropNotFoundException ( description [ 0 ] ) ;
370+ throw WrongColumnNameException ( description [ 0 ] ) ;
371371
372372 if ( description . Count ( ) > 1 )
373373 {
@@ -389,14 +389,15 @@ private class RowComparator : IComparer<ValueTreeRow>
389389 {
390390 readonly List < ValueTreeSortRule > _rules ;
391391
392- readonly GenericIValueComparer _comparer = new GenericIValueComparer ( ) ;
392+ readonly GenericIValueComparer _comparer ;
393393
394- public RowComparator ( List < ValueTreeSortRule > rules )
394+ public RowComparator ( IBslProcess process , List < ValueTreeSortRule > rules )
395395 {
396396 if ( rules . Count ( ) == 0 )
397397 throw RuntimeException . InvalidArgumentValue ( ) ;
398398
399399 this . _rules = rules ;
400+ _comparer = new GenericIValueComparer ( process ) ;
400401 }
401402
402403 private int OneCompare ( ValueTreeRow x , ValueTreeRow y , ValueTreeSortRule rule )
@@ -430,20 +431,20 @@ public int Compare(ValueTreeRow x, ValueTreeRow y)
430431 /// <param name="sortChildren">Булево. Если Истина, сортировка будет применена также к вложенным строкам.</param>
431432 /// <param name="comparator">СравнениеЗначений. Не используется.</param>
432433 [ ContextMethod ( "Сортировать" , "Sort" ) ]
433- public void Sort ( string columns , bool sortChildren = false , IValue comparator = null )
434+ public void Sort ( IBslProcess process , string columns , bool sortChildren = false , IValue comparator = null )
434435 {
435- Sort ( new RowComparator ( GetSortRules ( columns ) ) , sortChildren ) ;
436+ Sort ( process , new RowComparator ( process , GetSortRules ( columns ) ) , sortChildren ) ;
436437 }
437438
438- private void Sort ( RowComparator comparator , bool sortChildren )
439+ private void Sort ( IBslProcess process , RowComparator comparator , bool sortChildren )
439440 {
440441 _rows . Sort ( comparator ) ;
441442
442443 if ( sortChildren )
443444 {
444445 foreach ( var row in _rows )
445446 {
446- row . Rows . Sort ( comparator , sortChildren ) ;
447+ row . Rows . Sort ( process , comparator , sortChildren ) ;
447448 }
448449 }
449450 }
@@ -486,6 +487,17 @@ public override IEnumerator<ValueTreeRow> GetEnumerator()
486487 public override IValue GetIndexedValue ( IValue index )
487488 {
488489 return Get ( ( int ) index . AsNumber ( ) ) ;
490+ }
491+
492+ private static RuntimeException WrongColumnNameException ( )
493+ {
494+ return new RuntimeException ( "Неверное имя колонки" ) ;
489495 }
496+
497+ private static RuntimeException WrongColumnNameException ( string columnName )
498+ {
499+ return new RuntimeException ( string . Format ( "Неверное имя колонки '{0}'" , columnName ) ) ;
500+ }
501+
490502 }
491503}
0 commit comments