/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.2
src/OneScript.StandardLibrary/Xml/XmlWriterSettingsImpl.cs
92 строки
3 KB
EvilBeaver
Удален устаревший метод OnAttach и массово исправлены неиспользуемые using
02 дек 2025, 11:20
02 дек 2025, 11:20
0301fed
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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 System.Xml; using OneScript.Contexts; using OneScript.StandardLibrary.Text; using ScriptEngine.Machine.Contexts; namespace OneScript.StandardLibrary.Xml { /// <summary> /// Параметры, используемые для формирования XML /// </summary> [ContextClass("ПараметрыЗаписиXML", "XMLWriterSettings")] public class XmlWriterSettingsImpl : AutoContext<XmlWriterSettingsImpl> { public XmlWriterSettingsImpl(string encoding, string version, bool indent, bool indentAttributes, string indentChars) { Version = version; Encoding = encoding; Indent = indent; IndentAttributes = indentAttributes; IndentChars = indentChars; } /// <summary> /// Версия XML /// </summary> [ContextProperty("Версия", "Version")] public string Version { get; } /// <summary> /// Кодировка /// </summary> [ContextProperty("Кодировка", "Encoding")] public string Encoding { get; } /// <summary> /// Использование отступа для вложенных элементов /// </summary> [ContextProperty("Отступ", "Indent")] public bool Indent { get; } /// <summary> /// Использование отступов для атрибутов /// </summary> [ContextProperty("ОтступАтрибутов", "IndentAttributes")] public bool IndentAttributes { get; } /// <summary> /// Символы, используемые для формирования отступа /// </summary> [ContextProperty("СимволыОтступа", "IndentChars")] public string IndentChars { get; } public XmlWriterSettings GetClrSettings(bool addBom = false) { var result = new XmlWriterSettings { Indent = Indent, IndentChars = IndentChars, NewLineOnAttributes = IndentAttributes, Encoding = TextEncodingEnum.GetEncodingByName(Encoding, addBom), NewLineChars = System.Environment.NewLine, NamespaceHandling = NamespaceHandling.OmitDuplicates }; return result; } [ScriptConstructor] public static XmlWriterSettingsImpl Constructor( string encoding = null, string version = null, bool indent = true, bool indentAttributes = false, string indentChars = null) { return new XmlWriterSettingsImpl( encoding ?? "UTF-8", version ?? "1.0", indent, indentAttributes, indentChars ?? "\t"); } } }