@@ -6,6 +6,8 @@ This Source Code Form is subject to the terms of the
66----------------------------------------------------------*/
77
88using OneScript . Contexts ;
9+ using OneScript . Execution ;
10+ using OneScript . Types ;
911using ScriptEngine . Machine ;
1012using ScriptEngine . Machine . Contexts ;
1113
@@ -14,25 +16,50 @@ namespace Component
1416 [ ContextClass ( "ПростоКласс" ) ]
1517 public sealed class SimpleClass : AutoContext < SimpleClass > , ISimple
1618 {
19+
20+ // Для вызова некоторых операций значений IValue, таких как AsString(), Count(), требуется указание активного процесса.
21+ // Процесс может быть передан как параметр в конструкторе или как первый параметр методов класса
22+ private readonly IBslProcess _bslProcess ;
23+
24+ private SimpleClass ( IBslProcess bslProcess )
25+ {
26+ _bslProcess = bslProcess ;
27+ }
28+
1729 [ ContextProperty ( "СвойствоПеречисление" ) ]
1830 public SimpleEnum EnumProperty { get ; set ; }
1931
2032 [ ContextProperty ( "ЦелочисленноеСвойство" ) ]
2133 public int IntProperty { get ; set ; }
2234
2335 [ ContextProperty ( "СвойствоСПроизвольнымЗначением" ) ]
24- public IValue AnyValueProperty { get ; set ; }
36+ public IValue AnyValueProperty { get ; set ; } = ValueFactory . Create ( ) ;
2537
26- [ ScriptConstructor ]
27- public static SimpleClass Constructor ( )
38+ [ ContextMethod ( "МетодСПроцессом" ) ]
39+ public string MethodWithProcess ( IBslProcess bslProcess )
40+ {
41+ // Параметр IBslProcess bslProcess не будет виден из скрипта.
42+ // Скрипт будет считать такой метод методом без параметров.
43+ return AnyValueProperty . AsString ( bslProcess ) ;
44+ }
45+
46+ [ ScriptConstructor ]
47+ public static SimpleClass Constructor ( TypeActivationContext ctx )
2848 {
29- return new SimpleClass ( ) ;
49+
50+ // В отличие от методов в конструктор передается TypeActivationContext.
51+
52+ // Параметр TypeActivationContext не будет виден из скрипта.
53+ // Скрипт будет считать такой конструктор конструктором без параметров.
54+ return new SimpleClass ( ctx . CurrentProcess ) ;
3055 }
3156
3257 [ ScriptConstructor ]
33- public static SimpleClass Constructor ( int initialProperty )
58+ public static SimpleClass Constructor ( TypeActivationContext ctx , int initialProperty )
3459 {
35- var result = new SimpleClass ( ) ;
60+ // Параметр TypeActivationContext не будет виден из скрипта.
61+ // Скрипт будет считать такой конструктор конструктором с ОДНИМ параметром.
62+ var result = new SimpleClass ( ctx . CurrentProcess ) ;
3663 result . IntProperty = initialProperty ;
3764 return result ;
3865 }
0 commit comments