Skip to content

Commit 0cd65f0

Browse files
authored
Merge pull request #1704 from dmpas/feature/addin-bslprocess-issue
Немного ясности в пробросе процесса в компонент.
2 parents d86e60f + 3504724 commit 0cd65f0

2 files changed

Lines changed: 33 additions & 106 deletions

File tree

src/Component/SimpleClass.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77

88
using OneScript.Contexts;
9+
using OneScript.Execution;
10+
using OneScript.Types;
911
using ScriptEngine.Machine;
1012
using 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
}

src/Component/UseLibrary.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)