From b770ac9f644e73d1b7d186882ab77d7695d3858f Mon Sep 17 00:00:00 2001 From: Michael Rybakin Date: Sat, 23 Sep 2023 01:04:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=B2=D0=BB=D0=B5=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Xml/XmlGlobalFunctions.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/OneScript.StandardLibrary/Xml/XmlGlobalFunctions.cs b/src/OneScript.StandardLibrary/Xml/XmlGlobalFunctions.cs index 65d2ad8fc..fe5d82420 100644 --- a/src/OneScript.StandardLibrary/Xml/XmlGlobalFunctions.cs +++ b/src/OneScript.StandardLibrary/Xml/XmlGlobalFunctions.cs @@ -15,6 +15,7 @@ This Source Code Form is subject to the terms of the using OneScript.StandardLibrary.TypeDescriptions; using OneScript.Types; using OneScript.Values; +using ScriptEngine; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -23,12 +24,21 @@ namespace OneScript.StandardLibrary.Xml [GlobalContext(Category="Функции работы с XML")] public class XmlGlobalFunctions : GlobalContextBase { - private static readonly Dictionary _allowedEnums = new Dictionary - {{typeof(ClrEnumValueWrapper),typeof(AllowedSignEnum)}, - {typeof(ClrEnumValueWrapper),typeof(AllowedLengthEnum)}, - {typeof(ClrEnumValueWrapper),typeof(DateFractionsEnum)} - }; - + private static readonly Dictionary _allowedEnums + = new Dictionary(); + + private XmlGlobalFunctions(IGlobalsManager mgr) + { + foreach (var e in new[] { + (typeof(ClrEnumValueWrapper), typeof(AllowedSignEnum)), + (typeof(ClrEnumValueWrapper), typeof(AllowedLengthEnum)), + (typeof(ClrEnumValueWrapper), typeof(DateFractionsEnum)) + }) + { + _allowedEnums.Add(e.Item1, (EnumerationContext)mgr.GetInstance(e.Item2)); + } + } + /// /// Получает XML представление значения для помещения в текст элемента или значение атрибута XML. /// @@ -156,11 +166,10 @@ public IValue XMLValue(IValue givenType, string presentation) byte[] bytes = Convert.FromBase64String(presentation); return new BinaryDataContext(bytes); } - else if (_allowedEnums.TryGetValue(typeValue.ImplementingClass, out var enumType)) + else if (_allowedEnums.TryGetValue(typeValue.ImplementingClass, out var enumerationContext)) { try { - var enumerationContext = GlobalsHelper.GetEnum(enumType); return enumerationContext[presentation]; } catch (RuntimeException) @@ -170,12 +179,11 @@ public IValue XMLValue(IValue givenType, string presentation) } throw RuntimeException.InvalidNthArgumentType(1); - } - public static IAttachableContext CreateInstance() + public static IAttachableContext CreateInstance(IGlobalsManager mgr) { - return new XmlGlobalFunctions(); + return new XmlGlobalFunctions(mgr); } }