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
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSComplexFinal : ClrEnumWrapperCached<EnumerationXSComplexFinal, XmlSchemaDerivationMethod>
{
private EnumerationXSComplexFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSDisallowedSubstitutions : ClrEnumWrapperCached<EnumerationXSDisallowedSubstitutions, XmlSchemaDerivationMethod>
{
private EnumerationXSDisallowedSubstitutions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSProhibitedSubstitutions : ClrEnumWrapperCached<EnumerationXSProhibitedSubstitutions, XmlSchemaDerivationMethod>
{
private EnumerationXSProhibitedSubstitutions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSSchemaFinal : ClrEnumWrapperCached<EnumerationXSSchemaFinal, XmlSchemaDerivationMethod>
{
private EnumerationXSSchemaFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSSimpleFinal : ClrEnumWrapperCached<EnumerationXSSimpleFinal, XmlSchemaDerivationMethod>
{
private EnumerationXSSimpleFinal(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlSchemaDerivationMethod>
public sealed class EnumerationXSSubstitutionGroupExclusions : ClrEnumWrapperCached<EnumerationXSSubstitutionGroupExclusions, XmlSchemaDerivationMethod>
{
private EnumerationXSSubstitutionGroupExclusions(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
Expand Down
18 changes: 16 additions & 2 deletions src/ScriptEngine/Machine/Contexts/ClrEnumWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,26 @@ protected static TE CreateInstance<TE>(ITypeManager typeManager,EnumCreationDele
}
}

public abstract class ClrEnumWrapperCached<T> : ClrEnumWrapper<T> where T : struct
public abstract class ClrEnumWrapperCached<T> : ClrEnumWrapperCached<ClrEnumWrapperCached<T>, T> where T : struct
{
protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
{
}
}

/// <summary>
/// Кэш значений свой у каждого перечисления TSelf: несколько перечислений могут оборачивать
/// одно перечисление Clr (например, XmlSchemaDerivationMethod), и общий кэш по T путал бы их значения
/// </summary>
public abstract class ClrEnumWrapperCached<TSelf, T> : ClrEnumWrapper<T>
where T : struct
where TSelf : ClrEnumWrapperCached<TSelf, T>
{
private static readonly Dictionary<T, ClrEnumValueWrapper<T>> _valuesCache
= new Dictionary<T, ClrEnumValueWrapper<T>>();

protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
protected ClrEnumWrapperCached(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
: base(typeRepresentation, valuesType)
{
_valuesCache.Clear();
Expand Down
24 changes: 24 additions & 0 deletions tests/XMLSchema/test-XMLSchema.os
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
СписокТестов.Добавить("ТестУстановитьПространствоИмен");
СписокТестов.Добавить("ТестФормаАтрибутовПоУмолчанию");
СписокТестов.Добавить("ТестФормаЭлементовПоУмолчанию");
СписокТестов.Добавить("ТестЗавершенностьПоУмолчанию");
СписокТестов.Добавить("ТестБлокировкаПоУмолчанию");
СписокТестов.Добавить("ТестОписаниеЭлемента");
СписокТестов.Добавить("ТестОпределениеПростогоТипа");
СписокТестов.Добавить("ТестОпределениеСоставногоТипа");
Expand Down Expand Up @@ -112,6 +114,28 @@ EndProcedure

КонецПроцедуры

Процедура ТестЗавершенностьПоУмолчанию() Экспорт

СхемаXML = Новый СхемаXML;

СхемаXML.ЗавершенностьПоУмолчанию.Значения().Добавить(ЗавершенностьСхемыXS.Ограничение);

ЮнитТест.ПроверитьИстину(СхемаXML.ЗавершенностьПоУмолчанию.Ограничение);
ЮнитТест.ПроверитьЛожь(СхемаXML.ЗавершенностьПоУмолчанию.Расширение);

КонецПроцедуры

Процедура ТестБлокировкаПоУмолчанию() Экспорт

СхемаXML = Новый СхемаXML;

СхемаXML.БлокировкаПоУмолчанию.Значения().Добавить(НедопустимыеПодстановкиXS.Ограничение);

ЮнитТест.ПроверитьИстину(СхемаXML.БлокировкаПоУмолчанию.Ограничение);
ЮнитТест.ПроверитьЛожь(СхемаXML.БлокировкаПоУмолчанию.Расширение);

КонецПроцедуры

Процедура ТестОписаниеЭлемента() Экспорт

СхемаXML = Новый СхемаXML;
Expand Down