@@ -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,58 @@ 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 )
2840 {
29- return new SimpleClass ( ) ;
41+ // Параметр IBslProcess bslProcess не будет виден из скрипта.
42+ // Скрипт будет считать такой метод методом без параметров.
43+ return AnyValueProperty . AsString ( bslProcess ) ;
44+ }
45+
46+ [ ContextMethod ( "МетодСПроцессом" ) ]
47+ public string MethodWithProcess1 ( IBslProcess bslProcess )
48+ {
49+ // Параметр IBslProcess bslProcess не будет виден из скрипта.
50+ // Скрипт будет считать такой метод методом без параметров.
51+ return AnyValueProperty . AsString ( bslProcess ) ;
52+ }
53+
54+ [ ScriptConstructor ]
55+ public static SimpleClass Constructor ( TypeActivationContext ctx )
56+ {
57+
58+ // В отличие от методов в конструктор передается TypeActivationContext.
59+
60+ // Параметр TypeActivationContext не будет виден из скрипта.
61+ // Скрипт будет считать такой конструктор конструктором без параметров.
62+ return new SimpleClass ( ctx . CurrentProcess ) ;
3063 }
3164
3265 [ ScriptConstructor ]
33- public static SimpleClass Constructor ( int initialProperty )
66+ public static SimpleClass Constructor ( TypeActivationContext ctx , int initialProperty )
3467 {
35- var result = new SimpleClass ( ) ;
68+ // Параметр TypeActivationContext не будет виден из скрипта.
69+ // Скрипт будет считать такой конструктор конструктором с ОДНИМ параметром.
70+ var result = new SimpleClass ( ctx . CurrentProcess ) ;
3671 result . IntProperty = initialProperty ;
3772 return result ;
3873 }
0 commit comments