From 13e6154879ab5d7e48558f1e5eb31ec2d7693544 Mon Sep 17 00:00:00 2001 From: sfaqer Date: Wed, 30 Sep 2026 21:32:11 +1000 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B2=D0=BE=D0=B9=20=D0=BA=D1=8D=D1=88?= =?UTF-8?q?=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9=20=D1=83=20?= =?UTF-8?q?=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=B3=D0=BE=20XS-=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=87=D0=B8=D1=81=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Шесть перечислений XS оборачивают один XmlSchemaDerivationMethod и делили статический кэш значений: FromNativeValue возвращал значения последнего созданного перечисления. Кэш теперь свой у каждого перечисления. Co-Authored-By: Claude Opus 5.5 --- .../XMLSchema/Enumerations/XSComplexFinal.cs | 2 +- .../Enumerations/XSDisallowedSubstitutions.cs | 2 +- .../Enumerations/XSProhibitedSubstitutions.cs | 2 +- .../XMLSchema/Enumerations/XSSchemaFinal.cs | 2 +- .../XMLSchema/Enumerations/XSSimpleFinal.cs | 2 +- .../XSSubstitutionGroupExclusions.cs | 2 +- .../Machine/Contexts/ClrEnumWrapper.cs | 18 ++++++++++++-- tests/XMLSchema/test-XMLSchema.os | 24 +++++++++++++++++++ 8 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSComplexFinal.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSComplexFinal.cs index eb2d2d115..587179ac3 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSComplexFinal.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSComplexFinal.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("ЗавершенностьСоставногоТипаXS", "XSComplexFinal")] - public sealed class EnumerationXSComplexFinal : ClrEnumWrapperCached + public sealed class EnumerationXSComplexFinal : ClrEnumWrapperCached { private EnumerationXSComplexFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSDisallowedSubstitutions.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSDisallowedSubstitutions.cs index db80ce228..e50e313b7 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSDisallowedSubstitutions.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSDisallowedSubstitutions.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("НедопустимыеПодстановкиXS", "XSDisallowedSubstitutions")] - public sealed class EnumerationXSDisallowedSubstitutions : ClrEnumWrapperCached + public sealed class EnumerationXSDisallowedSubstitutions : ClrEnumWrapperCached { private EnumerationXSDisallowedSubstitutions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSProhibitedSubstitutions.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSProhibitedSubstitutions.cs index a1e8aca1a..1ce81f277 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSProhibitedSubstitutions.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSProhibitedSubstitutions.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("ЗапрещенныеПодстановкиXS", "XSProhibitedSubstitutions")] - public sealed class EnumerationXSProhibitedSubstitutions : ClrEnumWrapperCached + public sealed class EnumerationXSProhibitedSubstitutions : ClrEnumWrapperCached { private EnumerationXSProhibitedSubstitutions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSchemaFinal.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSchemaFinal.cs index 1490c287b..eaac8b49b 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSchemaFinal.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSchemaFinal.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("ЗавершенностьСхемыXS", "XSSchemaFinal")] - public sealed class EnumerationXSSchemaFinal : ClrEnumWrapperCached + public sealed class EnumerationXSSchemaFinal : ClrEnumWrapperCached { private EnumerationXSSchemaFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSimpleFinal.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSimpleFinal.cs index 09230581b..7ddb91eda 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSimpleFinal.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSimpleFinal.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("ЗавершенностьПростогоТипаXS", "XSSimpleFinal")] - public sealed class EnumerationXSSimpleFinal : ClrEnumWrapperCached + public sealed class EnumerationXSSimpleFinal : ClrEnumWrapperCached { private EnumerationXSSimpleFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSubstitutionGroupExclusions.cs b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSubstitutionGroupExclusions.cs index e84d04226..4dbbd7548 100644 --- a/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSubstitutionGroupExclusions.cs +++ b/src/OneScript.StandardLibrary/XMLSchema/Enumerations/XSSubstitutionGroupExclusions.cs @@ -13,7 +13,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.StandardLibrary.XMLSchema.Enumerations { [SystemEnum("ИсключенияГруппПодстановкиXS", "XSSubstitutionGroupExclusions")] - public sealed class EnumerationXSSubstitutionGroupExclusions : ClrEnumWrapperCached + public sealed class EnumerationXSSubstitutionGroupExclusions : ClrEnumWrapperCached { private EnumerationXSSubstitutionGroupExclusions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) diff --git a/src/ScriptEngine/Machine/Contexts/ClrEnumWrapper.cs b/src/ScriptEngine/Machine/Contexts/ClrEnumWrapper.cs index 19143699a..43479f7ac 100644 --- a/src/ScriptEngine/Machine/Contexts/ClrEnumWrapper.cs +++ b/src/ScriptEngine/Machine/Contexts/ClrEnumWrapper.cs @@ -130,12 +130,26 @@ protected static TE CreateInstance(ITypeManager typeManager,EnumCreationDele } } - public abstract class ClrEnumWrapperCached : ClrEnumWrapper where T : struct + public abstract class ClrEnumWrapperCached : ClrEnumWrapperCached, T> where T : struct + { + protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) + : base(typeRepresentation, valuesType) + { + } + } + + /// + /// Кэш значений свой у каждого перечисления TSelf: несколько перечислений могут оборачивать + /// одно перечисление Clr (например, XmlSchemaDerivationMethod), и общий кэш по T путал бы их значения + /// + public abstract class ClrEnumWrapperCached : ClrEnumWrapper + where T : struct + where TSelf : ClrEnumWrapperCached { private static readonly Dictionary> _valuesCache = new Dictionary>(); - protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) + protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType) : base(typeRepresentation, valuesType) { _valuesCache.Clear(); diff --git a/tests/XMLSchema/test-XMLSchema.os b/tests/XMLSchema/test-XMLSchema.os index 904fef56e..3efdd5946 100644 --- a/tests/XMLSchema/test-XMLSchema.os +++ b/tests/XMLSchema/test-XMLSchema.os @@ -12,6 +12,8 @@ СписокТестов.Добавить("ТестУстановитьПространствоИмен"); СписокТестов.Добавить("ТестФормаАтрибутовПоУмолчанию"); СписокТестов.Добавить("ТестФормаЭлементовПоУмолчанию"); + СписокТестов.Добавить("ТестЗавершенностьПоУмолчанию"); + СписокТестов.Добавить("ТестБлокировкаПоУмолчанию"); СписокТестов.Добавить("ТестОписаниеЭлемента"); СписокТестов.Добавить("ТестОпределениеПростогоТипа"); СписокТестов.Добавить("ТестОпределениеСоставногоТипа"); @@ -112,6 +114,28 @@ EndProcedure КонецПроцедуры +Процедура ТестЗавершенностьПоУмолчанию() Экспорт + + СхемаXML = Новый СхемаXML; + + СхемаXML.ЗавершенностьПоУмолчанию.Значения().Добавить(ЗавершенностьСхемыXS.Ограничение); + + ЮнитТест.ПроверитьИстину(СхемаXML.ЗавершенностьПоУмолчанию.Ограничение); + ЮнитТест.ПроверитьЛожь(СхемаXML.ЗавершенностьПоУмолчанию.Расширение); + +КонецПроцедуры + +Процедура ТестБлокировкаПоУмолчанию() Экспорт + + СхемаXML = Новый СхемаXML; + + СхемаXML.БлокировкаПоУмолчанию.Значения().Добавить(НедопустимыеПодстановкиXS.Ограничение); + + ЮнитТест.ПроверитьИстину(СхемаXML.БлокировкаПоУмолчанию.Ограничение); + ЮнитТест.ПроверитьЛожь(СхемаXML.БлокировкаПоУмолчанию.Расширение); + +КонецПроцедуры + Процедура ТестОписаниеЭлемента() Экспорт СхемаXML = Новый СхемаXML;