Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/Component/SimpleClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This Source Code Form is subject to the terms of the
----------------------------------------------------------*/

using OneScript.Contexts;
using OneScript.Execution;
using OneScript.Types;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;

Expand All @@ -14,25 +16,50 @@ namespace Component
[ContextClass("ПростоКласс")]
public sealed class SimpleClass : AutoContext<SimpleClass>, ISimple
{

// Для вызова некоторых операций значений IValue, таких как AsString(), Count(), требуется указание активного процесса.
// Процесс может быть передан как параметр в конструкторе или как первый параметр методов класса
private readonly IBslProcess _bslProcess;

private SimpleClass(IBslProcess bslProcess)
{
_bslProcess = bslProcess;
}

[ContextProperty("СвойствоПеречисление")]
public SimpleEnum EnumProperty { get; set; }

[ContextProperty("ЦелочисленноеСвойство")]
public int IntProperty { get; set; }

[ContextProperty("СвойствоСПроизвольнымЗначением")]
public IValue AnyValueProperty { get; set; }
public IValue AnyValueProperty { get; set; } = ValueFactory.Create();

[ScriptConstructor]
public static SimpleClass Constructor()
[ContextMethod("МетодСПроцессом")]
public string MethodWithProcess(IBslProcess bslProcess)
{
// Параметр IBslProcess bslProcess не будет виден из скрипта.
// Скрипт будет считать такой метод методом без параметров.
return AnyValueProperty.AsString(bslProcess);
}

[ScriptConstructor]
public static SimpleClass Constructor(TypeActivationContext ctx)
{
return new SimpleClass();

// В отличие от методов в конструктор передается TypeActivationContext.

// Параметр TypeActivationContext не будет виден из скрипта.
// Скрипт будет считать такой конструктор конструктором без параметров.
return new SimpleClass(ctx.CurrentProcess);
}

[ScriptConstructor]
public static SimpleClass Constructor(int initialProperty)
public static SimpleClass Constructor(TypeActivationContext ctx, int initialProperty)
{
var result = new SimpleClass();
// Параметр TypeActivationContext не будет виден из скрипта.
// Скрипт будет считать такой конструктор конструктором с ОДНИМ параметром.
var result = new SimpleClass(ctx.CurrentProcess);
result.IntProperty = initialProperty;
return result;
}
Expand Down
100 changes: 0 additions & 100 deletions src/Component/UseLibrary.cs

This file was deleted.