diff --git a/src/Component/SimpleClass.cs b/src/Component/SimpleClass.cs index 54b743579..d9dac2a07 100644 --- a/src/Component/SimpleClass.cs +++ b/src/Component/SimpleClass.cs @@ -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; @@ -14,6 +16,16 @@ namespace Component [ContextClass("ПростоКласс")] public sealed class SimpleClass : AutoContext, ISimple { + + // Для вызова некоторых операций значений IValue, таких как AsString(), Count(), требуется указание активного процесса. + // Процесс может быть передан как параметр в конструкторе или как первый параметр методов класса + private readonly IBslProcess _bslProcess; + + private SimpleClass(IBslProcess bslProcess) + { + _bslProcess = bslProcess; + } + [ContextProperty("СвойствоПеречисление")] public SimpleEnum EnumProperty { get; set; } @@ -21,18 +33,33 @@ public sealed class SimpleClass : AutoContext, ISimple 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; } diff --git a/src/Component/UseLibrary.cs b/src/Component/UseLibrary.cs deleted file mode 100644 index 1ca7ff8f5..000000000 --- a/src/Component/UseLibrary.cs +++ /dev/null @@ -1,100 +0,0 @@ -/*---------------------------------------------------------- -This Source Code Form is subject to the terms of the -Mozilla Public License, v.2.0. If a copy of the MPL -was not distributed with this file, You can obtain one -at http://mozilla.org/MPL/2.0/. -----------------------------------------------------------*/ - -using OneScript.StandardLibrary; -using OneScript.StandardLibrary.Binary; -using OneScript.StandardLibrary.Collections; -using OneScript.StandardLibrary.Collections.ValueList; -using OneScript.StandardLibrary.Collections.ValueTable; -using OneScript.StandardLibrary.Collections.ValueTree; -using OneScript.StandardLibrary.Http; -using OneScript.StandardLibrary.Net; -using OneScript.StandardLibrary.Processes; -using OneScript.StandardLibrary.Text; -using OneScript.StandardLibrary.Xml; -using OneScript.StandardLibrary.Zip; -using OneScript.StandardLibrary.TypeDescriptions; -using ScriptEngine.Machine; - -namespace Component -{ - public static class UseLibrary - { - public static void Use() where T : IValue - { - } - - public static void Use() - { - /* Суть следующих выражений в том, что они перестанут компилироваться, - если какой-либо из классов поменяет область видимости - или переедет в иное пространство имён - (https://github.com/EvilBeaver/OneScript/commit/20e48fa7692b5430b819eb4b6982be1b591e536f)*/ - - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - Use(); - Use(); - - Use(); - Use(); - Use(); - - Use(); - Use(); - } - } -} \ No newline at end of file