Decompiled source of SmartFormat v3.5.0
BepInEx/core/SmartFormat/netstandard2.1/SmartFormat.dll
Decompiled 5 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Buffers; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Cysharp.Text; using Microsoft.CodeAnalysis; using SmartFormat.Core.Extensions; using SmartFormat.Core.Formatting; using SmartFormat.Core.Output; using SmartFormat.Core.Parsing; using SmartFormat.Core.Settings; using SmartFormat.Extensions; using SmartFormat.Extensions.PersistentVariables; using SmartFormat.Pooling.ObjectPools; using SmartFormat.Pooling.SmartPools; using SmartFormat.Pooling.SpecializedPools; using SmartFormat.Utilities; using SmartFormat.ZString; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: InternalsVisibleTo("SmartFormat.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1cdb8ba81e1a00f0f9509a8f0c896e0de0da6875652fffd44fb867e6b78fd78c31c6fdb07544b2ae53ed4b56daa90333d32ac14387f7f68d39165da8f99b8c294c1cee1bcc4bbcbe2dd73879824b53708837f425e2bf5c7d2cf868de9548c44871888bf9db5cb425064dda4b17134f8e3b52e1f686315a1832043c7b58fb0ac")] [assembly: InternalsVisibleTo("Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1cdb8ba81e1a00f0f9509a8f0c896e0de0da6875652fffd44fb867e6b78fd78c31c6fdb07544b2ae53ed4b56daa90333d32ac14387f7f68d39165da8f99b8c294c1cee1bcc4bbcbe2dd73879824b53708837f425e2bf5c7d2cf868de9548c44871888bf9db5cb425064dda4b17134f8e3b52e1f686315a1832043c7b58fb0ac")] [assembly: AssemblyCompany("SmartFormat")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright 2011-2024 SmartFormat Project")] [assembly: AssemblyDescription("This package contains the core SmartFormat assemblies with core extensions built-in.\r\n\r\nSmartFormat is a lightweight text templating library written in C#.\r\nIt can format various data sources into a string with a minimal, intuitive syntax similar to string.Format.\r\nIt uses extensions to provide named placeholders, localization, pluralization, gender conjugation, and list and time formatting.\r\n ")] [assembly: AssemblyFileVersion("3.5.0.886")] [assembly: AssemblyInformationalVersion("3.5.0+c097ea6fc668033580909317ed90679dacbb0e8a")] [assembly: AssemblyProduct("SmartFormat")] [assembly: AssemblyTitle("SmartFormat")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/axuno/SmartFormat.git")] [assembly: AssemblyVersion("3.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SmartFormat { internal class Evaluator { internal readonly record struct FormatEventArgs(Format Format); internal readonly record struct OutputWrittenEventArgs(string WrittenValue); internal readonly record struct LiteralEventArgs(string Text); internal readonly record struct PlaceholderEventArgs(Placeholder Placeholder); internal readonly record struct SelectorValueEventArgs(Selector Selector, bool Success, Type? SourceType, object? Value); internal readonly record struct FormattingEventArgs(Selector Selector, object? Value, bool Success, Type? FormatterType); private readonly SmartFormatter _formatter; private readonly SmartSettings _settings; private readonly Registry _registry; internal EventHandler<FormatEventArgs>? OnFormat; internal EventHandler<LiteralEventArgs>? OnLiteral; internal EventHandler<PlaceholderEventArgs>? OnPlaceholder; internal EventHandler<SelectorValueEventArgs>? OnSelectorValue; internal EventHandler<SelectorValueEventArgs>? OnSelectorFailure; internal EventHandler<FormattingEventArgs>? OnFormattingStart; internal EventHandler<OutputWrittenEventArgs>? OnOutputWritten; internal EventHandler<FormattingEventArgs>? OnFormattingEnd; public event EventHandler<FormattingErrorEventArgs>? OnFormattingFailure; public Evaluator(SmartFormatter formatter) { _formatter = formatter; _settings = _formatter.Settings; _registry = _formatter.Registry; } public void WriteFormat(FormattingInfo formattingInfo) { Format format = formattingInfo.Format; OnFormat?.Invoke(this, new FormatEventArgs(format)); foreach (FormatItem item in format.Items) { if (item is LiteralText literalText) { OnLiteral?.Invoke(this, new LiteralEventArgs(literalText.ToString())); formattingInfo.Write(literalText.ToString().AsSpan()); continue; } Placeholder placeholder = (Placeholder)item; FormattingInfo formattingInfo2 = formattingInfo.CreateChild(placeholder); OnPlaceholder?.Invoke(this, new PlaceholderEventArgs(placeholder)); if (EvaluatePlaceholder(formattingInfo2)) { InvokeFormatters(formattingInfo2); } } } private bool EvaluatePlaceholder(FormattingInfo formattingInfo) { formattingInfo.Result = null; Placeholder placeholder = formattingInfo.Placeholder; try { EvaluateSelectors(formattingInfo); } catch (Exception innerException) { int startIndex = placeholder.Format?.StartIndex ?? placeholder.Selectors[placeholder.Selectors.Count - 1].EndIndex; FormatError(placeholder, innerException, startIndex, formattingInfo); return false; } return true; } public bool TryGetValue(FormattingInfo parentFormattingInfo, Placeholder placeholder, out object? result) { result = null; if (placeholder.Selectors.Count == 0) { result = parentFormattingInfo.CurrentValue; return true; } FormattingInfo formattingInfo = FormattingInfoPool.Instance.Get().Initialize(parentFormattingInfo, parentFormattingInfo.FormatDetails, placeholder, parentFormattingInfo.CurrentValue); parentFormattingInfo.Children.Add(formattingInfo); try { EvaluateSelectors(formattingInfo); result = formattingInfo.CurrentValue; return true; } catch { return false; } } private void EvaluateSelectors(FormattingInfo formattingInfo) { formattingInfo.Result = null; bool flag = true; foreach (Selector selector in formattingInfo.Placeholder.Selectors) { if (!SkipThisSelector(selector)) { formattingInfo.Selector = selector; (bool, Type) handled = _registry.InvokeSourceExtensions(formattingInfo); if (handled.Item1) { formattingInfo.CurrentValue = formattingInfo.Result; OnSelectorValue?.Invoke(this, new SelectorValueEventArgs(selector, handled.Item1, handled.Item2, formattingInfo.CurrentValue)); } else if (flag) { flag = false; HandleNestedScope(formattingInfo, selector, ref handled); OnSelectorValue?.Invoke(this, new SelectorValueEventArgs(selector, handled.Item1, handled.Item2, formattingInfo.CurrentValue)); } if (!handled.Item1) { OnSelectorFailure?.Invoke(this, new SelectorValueEventArgs(selector, handled.Item1, null, null)); throw formattingInfo.FormattingException("No source extension could handle the selector named \"" + selector.RawText + "\"", selector); } } } } private void HandleNestedScope(FormattingInfo formattingInfo, Selector selector, ref (bool Success, Type? SourceType) handled) { FormattingInfo formattingInfo2 = formattingInfo; while (!handled.Success && formattingInfo2.Parent != null) { formattingInfo2 = formattingInfo2.Parent; formattingInfo2.Selector = selector; formattingInfo2.Result = null; handled = _registry.InvokeSourceExtensions(formattingInfo2); if (handled.Success) { formattingInfo.CurrentValue = formattingInfo2.Result; } } } private bool SkipThisSelector(Selector selector) { if (selector.Length == 0) { return true; } if (selector.Operator.Length > 0 && selector.Operator[0] == _settings.Parser.AlignmentOperator) { return true; } return false; } private void InvokeFormatters(FormattingInfo formattingInfo) { if (formattingInfo.DisableFormattingExtensions) { return; } Placeholder placeholder = formattingInfo.Placeholder; try { OnFormattingStart?.Invoke(this, new FormattingEventArgs(formattingInfo.Selector, formattingInfo.CurrentValue, Success: true, null)); (bool, Type) tuple = _registry.InvokeFormatterExtensions(formattingInfo); OnFormattingEnd?.Invoke(this, new FormattingEventArgs(formattingInfo.Selector, formattingInfo.CurrentValue, tuple.Item1, tuple.Item2)); if (!tuple.Item1) { throw formattingInfo.FormattingException("No suitable Formatter could be found", formattingInfo.Format, formattingInfo.Selector?.SelectorIndex ?? (-1)); } } catch (Exception innerException) { int startIndex = placeholder.Format?.StartIndex ?? placeholder.Selectors[placeholder.Selectors.Count - 1].EndIndex; FormatError(placeholder, innerException, startIndex, formattingInfo); } } private void FormatError(FormatItem errorItem, Exception innerException, int startIndex, FormattingInfo formattingInfo) { FormattingErrorEventArgs formattingErrorEventArgs = new FormattingErrorEventArgs(errorItem.RawText, startIndex, _settings.Formatter.ErrorAction != FormatErrorAction.ThrowError); this.OnFormattingFailure?.Invoke(this, formattingErrorEventArgs); _formatter.FormatError(formattingErrorEventArgs); switch (_settings.Formatter.ErrorAction) { case FormatErrorAction.Ignore: break; case FormatErrorAction.ThrowError: throw (innerException as FormattingException) ?? new FormattingException(errorItem, innerException, startIndex); case FormatErrorAction.OutputErrorInResult: formattingInfo.FormatDetails.FormattingException = (innerException as FormattingException) ?? new FormattingException(errorItem, innerException, startIndex); formattingInfo.Write(innerException.Message); formattingInfo.FormatDetails.FormattingException = null; break; case FormatErrorAction.MaintainTokens: formattingInfo.Write(formattingInfo.Placeholder?.RawText ?? "'null'"); break; } } } public class FormattingErrorEventArgs : EventArgs { public string Placeholder { get; } public int ErrorIndex { get; } public bool IgnoreError { get; } internal FormattingErrorEventArgs(string rawText, int errorIndex, bool ignoreError) { Placeholder = rawText; ErrorIndex = errorIndex; IgnoreError = ignoreError; } } public static class Smart { [ThreadStatic] private static SmartFormatter? _formatter; public static SmartFormatter Default { get { if (_formatter == null) { _formatter = CreateDefaultSmartFormat(); } return _formatter; } set { _formatter = value; } } public static string Format(string format, params object?[] args) { return Default.Format(format, args); } public static string Format(IFormatProvider provider, string format, params object?[] args) { return Default.Format(provider, format, args); } public static string Format(string format, object? arg0, object? arg1, object? arg2) { return Default.Format(format, arg0, arg1, arg2); } public static string Format(string format, object? arg0, object? arg1) { return Default.Format(format, arg0, arg1); } public static string Format(string format, object? arg0) { return Default.Format(format, arg0); } public static SmartFormatter CreateDefaultSmartFormat(SmartSettings? settings = null) { return new SmartFormatter(settings).AddExtensions(new StringSource(), new ListFormatter(), new DictionarySource(), new ValueTupleSource(), new ReflectionSource(), new DefaultSource(), new KeyValuePairSource()).AddExtensions(new PluralLocalizationFormatter(), new ConditionalFormatter(), new IsMatchFormatter(), new NullFormatter(), new ChooseFormatter(), new SubStringFormatter(), new DefaultFormatter()); } } public static class SmartExtensions { public static void AppendSmart(this StringBuilder sb, string format, params object[] args) { StringOutput output = new StringOutput(sb); Smart.Default.FormatInto(output, format, args); } public static void AppendLineSmart(this StringBuilder sb, string format, params object[] args) { sb.AppendSmart(format, args); sb.AppendLine(); } public static void WriteSmart(this TextWriter writer, string format, params object[] args) { TextWriterOutput output = new TextWriterOutput(writer); Smart.Default.FormatInto(output, format, args); } public static void WriteLineSmart(this TextWriter writer, string format, params object[] args) { writer.WriteSmart(format, args); writer.WriteLine(); } public static string FormatSmart(this string format, params object[] args) { return Smart.Format(format, args); } } public class SmartFormatter { internal List<ISource> SourceExtensions => Registry.SourceExtensions; internal List<SmartFormat.Core.Extensions.IFormatter> FormatterExtensions => Registry.FormatterExtensions; public Parser Parser { get; } public SmartSettings Settings { get; } internal Registry Registry { get; } internal Evaluator Evaluator { get; } public event EventHandler<FormattingErrorEventArgs>? OnFormattingFailure; public SmartFormatter(SmartSettings? settings = null) { Settings = settings ?? new SmartSettings(); Parser = new Parser(Settings); Registry = new Registry(this); Evaluator = new Evaluator(this); } internal void FormatError(FormattingErrorEventArgs args) { this.OnFormattingFailure?.Invoke(this, args); } public IReadOnlyList<ISource> GetSourceExtensions() { return Registry.GetSourceExtensions(); } public IReadOnlyList<SmartFormat.Core.Extensions.IFormatter> GetFormatterExtensions() { return Registry.GetFormatterExtensions(); } public SmartFormatter AddExtensions(params ISource[] sourceExtensions) { Registry.AddExtensions(sourceExtensions); return this; } public SmartFormatter AddExtensions(params SmartFormat.Core.Extensions.IFormatter[] formatterExtensions) { Registry.AddExtensions(formatterExtensions); return this; } public SmartFormatter InsertExtension(int position, ISource sourceExtension) { Registry.InsertExtension(position, sourceExtension); return this; } public SmartFormatter InsertExtension(int position, SmartFormat.Core.Extensions.IFormatter formatterExtension) { Registry.InsertExtension(position, formatterExtension); return this; } public T? GetSourceExtension<T>() where T : class, ISource { return Registry.GetSourceExtension<T>(); } public T? GetFormatterExtension<T>() where T : class, SmartFormat.Core.Extensions.IFormatter { return Registry.GetFormatterExtension<T>(); } public bool RemoveSourceExtension<T>() where T : class, ISource { return Registry.RemoveSourceExtension<T>(); } public bool RemoveFormatterExtension<T>() where T : class, SmartFormat.Core.Extensions.IFormatter { return Registry.RemoveFormatterExtension<T>(); } public string Format(string format, params object?[] args) { return Format((IFormatProvider?)null, format, (IList<object?>)args); } public string Format(string format, IList<object?> args) { return Format(null, format, args); } public string Format(IFormatProvider? provider, string format, params object?[] args) { return Format(provider, format, (IList<object?>)args); } public string Format(IFormatProvider? provider, string format, IList<object?> args) { Format format2 = Parser.ParseFormat(format); try { return Format(provider, format2, args); } finally { FormatPool.Instance.Return(format2); } } public string Format(Format formatParsed, params object?[] args) { return Format((IFormatProvider?)null, formatParsed, (IList<object?>)args); } public string Format(Format formatParsed, IList<object?> args) { return Format(null, formatParsed, args); } public string Format(IFormatProvider? provider, Format formatParsed, params object?[] args) { return Format(provider, formatParsed, (IList<object?>)args); } public string Format(IFormatProvider? provider, Format formatParsed, IList<object?> args) { using ZStringOutput zStringOutput = new ZStringOutput(ZStringBuilderUtilities.CalcCapacity(formatParsed)); FormatInto(zStringOutput, provider, formatParsed, args); return zStringOutput.ToString(); } public void Format(FormattingInfo formattingInfo) { Registry.ThrowIfNoExtensions(); Evaluator.WriteFormat(formattingInfo); } public void FormatInto(IOutput output, string format, params object?[] args) { FormatInto(output, format, (IList<object?>)args); } public void FormatInto(IOutput output, string format, IList<object?> args) { FormatInto(output, null, format, args); } public void FormatInto(IOutput output, IFormatProvider? provider, string format, IList<object?> args) { Format format2 = Parser.ParseFormat(format); try { FormatInto(output, provider, format2, args); } finally { FormatPool.Instance.Return(format2); } } public void FormatInto(IOutput output, IFormatProvider? provider, Format format, params object?[] args) { FormatInto(output, provider, format, (IList<object?>)args); } public void FormatInto(IOutput output, IFormatProvider? provider, Format formatParsed, IList<object?> args) { Registry.ThrowIfNoExtensions(); ExecuteFormattingAction(this, provider, formatParsed, args, output, Evaluator.WriteFormat); } private static void ExecuteFormattingAction(SmartFormatter formatter, IFormatProvider? provider, Format formatParsed, IList<object?> args, IOutput output, Action<FormattingInfo> doWork) { object currentValue = ((args.Count > 0) ? args[0] : args); FormatDetails instance; using (FormatDetailsPool.Instance.Pool.Get(out instance)) { instance.Initialize(formatter, formatParsed, args, provider, output); FormattingInfo instance2; using (FormattingInfoPool.Instance.Pool.Get(out instance2)) { instance2.Initialize(instance, formatParsed, currentValue); doWork(instance2); } } } } } namespace SmartFormat.ZString { public struct ZCharArray : IDisposable { private static readonly ArrayPool<char> Pool = ArrayPool<char>.Create(10000000, 100); private char[]? _bufferArray; private int _currentLength; public const int DefaultBufferCapacity = 1000000; public const int MaxBufferCapacity = 10000000; internal Span<char> Span { get { ThrowIfDisposed(); return _bufferArray.AsSpan(0, _currentLength); } } public int Length { get { ThrowIfDisposed(); return _currentLength; } } public int Capacity { get { ThrowIfDisposed(); return _bufferArray.Length; } } public bool IsDisposed => _bufferArray == null; public ZCharArray() : this(1000000) { } public ZCharArray(int length) { _bufferArray = Pool.Rent(length); _currentLength = 0; } public ReadOnlySpan<char> GetSpan() { ThrowIfDisposed(); return _bufferArray.AsSpan(0, _currentLength); } public void Reset() { ThrowIfDisposed(); _currentLength = 0; } private void Grow(int length) { char[] array = Pool.Rent(length); Array.Copy(_bufferArray, array, Math.Min(_bufferArray.Length, length)); Pool.Return(_bufferArray); _bufferArray = array; } public void Write(Span<char> data) { ThrowIfDisposed(); GrowBufferIfNeeded(data.Length); data.CopyTo(_bufferArray.AsSpan(_currentLength, data.Length)); _currentLength += data.Length; } public void Write(ReadOnlySpan<char> data) { ThrowIfDisposed(); GrowBufferIfNeeded(data.Length); data.CopyTo(_bufferArray.AsSpan(_currentLength, data.Length)); _currentLength += data.Length; } public void Write(string data) { ThrowIfDisposed(); GrowBufferIfNeeded(data.Length); data.AsSpan().CopyTo(_bufferArray.AsSpan(_currentLength, data.Length)); _currentLength += data.Length; } public void Write(char c) { ThrowIfDisposed(); GrowBufferIfNeeded(1); _bufferArray[_currentLength++] = c; } public void Write(char c, int count) { ThrowIfDisposed(); GrowBufferIfNeeded(count); for (int i = 0; i < count; i++) { _bufferArray[_currentLength++] = c; } } public void Write(IFormattable data, string format, IFormatProvider? provider = null) { ThrowIfDisposed(); ReadOnlySpan<char> data2 = data.ToString(format, provider).AsSpan(); GrowBufferIfNeeded(data2.Length); Write(data2); } private void GrowBufferIfNeeded(int dataLength) { int num = _currentLength + dataLength; if (num > Capacity) { Grow(num * 2); } } private void ThrowIfDisposed() { if (IsDisposed) { throw new ObjectDisposedException("ZCharArray"); } } public override string ToString() { ThrowIfDisposed(); return new string(_bufferArray, 0, _currentLength); } public void Dispose() { if (!IsDisposed) { Pool.Return(_bufferArray); _bufferArray = null; } } } [ExcludeFromCodeCoverage] public class ZStringBuilder : IDisposable { private Utf16ValueStringBuilder _vsb; public int Length => ((Utf16ValueStringBuilder)(ref _vsb)).Length; public ZStringBuilder(bool disposeImmediately) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) _vsb = new Utf16ValueStringBuilder(disposeImmediately); } public ReadOnlySpan<char> AsSpan() { return ((Utf16ValueStringBuilder)(ref _vsb)).AsSpan(); } public ReadOnlyMemory<char> AsMemory() { return ((Utf16ValueStringBuilder)(ref _vsb)).AsMemory(); } public ArraySegment<char> AsArraySegment() { return ((Utf16ValueStringBuilder)(ref _vsb)).AsArraySegment(); } public void Dispose() { ((Utf16ValueStringBuilder)(ref _vsb)).Dispose(); } public void Clear() { ((Utf16ValueStringBuilder)(ref _vsb)).Clear(); } public void TryGrow(int sizeHint) { ((Utf16ValueStringBuilder)(ref _vsb)).TryGrow(sizeHint); } public void Grow(int sizeHint) { ((Utf16ValueStringBuilder)(ref _vsb)).Grow(sizeHint); } public void AppendLine() { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(); } public void AppendLine(char value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(string value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(ReadOnlySpan<char> value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine<T>(T value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine<T>(value); } public void AppendLine(byte value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(byte value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(DateTime value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(DateTime value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(DateTimeOffset value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(DateTimeOffset value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(decimal value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(decimal value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(double value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(double value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(short value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(short value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(int value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(int value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(long value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(long value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(sbyte value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(sbyte value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(float value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(float value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(TimeSpan value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(TimeSpan value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(ushort value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(ushort value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(uint value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(uint value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(ulong value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(ulong value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void AppendLine(Guid value) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value); } public void AppendLine(Guid value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendLine(value, format); } public void Append(char value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(char value, int repeatCount) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, repeatCount); } public void Append(string value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(ReadOnlySpan<char> value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append<T>(T value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append<T>(value); } public void Append(ZStringBuilder value) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) ((Utf16ValueStringBuilder)(ref _vsb)).Append<Utf16ValueStringBuilder>(value._vsb); } public void Append(byte value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(byte value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(DateTime value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(DateTime value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(DateTimeOffset value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(DateTimeOffset value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(decimal value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(decimal value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(double value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(double value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(short value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(short value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(int value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(int value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(long value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(long value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(sbyte value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(sbyte value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(float value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(float value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(TimeSpan value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(TimeSpan value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(ushort value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(ushort value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(uint value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(uint value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(ulong value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(ulong value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Append(Guid value) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value); } public void Append(Guid value, string format) { ((Utf16ValueStringBuilder)(ref _vsb)).Append(value, format); } public void Insert(int index, string value, int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Insert(index, value, count); } public void Insert(int index, string value) { ((Utf16ValueStringBuilder)(ref _vsb)).Insert(index, value); } public void Insert(int index, ReadOnlySpan<char> value, int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Insert(index, value, count); } public void Replace(char oldChar, char newChar) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldChar, newChar); } public void Replace(char oldChar, char newChar, int startIndex, int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldChar, newChar, startIndex, count); } public void Replace(string oldValue, string newValue) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldValue, newValue); } public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldValue, newValue); } public void Replace(string oldValue, string newValue, int startIndex, int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldValue, newValue, startIndex, count); } public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue, int startIndex, int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Replace(oldValue, newValue, startIndex, count); } public void ReplaceAt(char newChar, int replaceIndex) { ((Utf16ValueStringBuilder)(ref _vsb)).ReplaceAt(newChar, replaceIndex); } public void Remove(int startIndex, int length) { ((Utf16ValueStringBuilder)(ref _vsb)).Remove(startIndex, length); } public bool TryCopyTo(Span<char> destination, out int charsWritten) { return ((Utf16ValueStringBuilder)(ref _vsb)).TryCopyTo(destination, ref charsWritten); } public override string ToString() { return ((object)(Utf16ValueStringBuilder)(ref _vsb)).ToString(); } public Memory<char> GetMemory(int sizeHint) { return ((Utf16ValueStringBuilder)(ref _vsb)).GetMemory(sizeHint); } public Span<char> GetSpan(int sizeHint) { return ((Utf16ValueStringBuilder)(ref _vsb)).GetSpan(sizeHint); } public void Advance(int count) { ((Utf16ValueStringBuilder)(ref _vsb)).Advance(count); } public void AppendFormat<T1>(ReadOnlySpan<char> format, T1 arg1) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1>(format, arg1); } public void AppendFormat<T1, T2>(ReadOnlySpan<char> format, T1 arg1, T2 arg2) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2>(format, arg1, arg2); } public void AppendFormat<T1, T2, T3>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3>(format, arg1, arg2, arg3); } public void AppendFormat<T1, T2, T3, T4>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4>(format, arg1, arg2, arg3, arg4); } public void AppendFormat<T1, T2, T3, T4, T5>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5>(format, arg1, arg2, arg3, arg4, arg5); } public void AppendFormat<T1, T2, T3, T4, T5, T6>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6>(format, arg1, arg2, arg3, arg4, arg5, arg6); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); } public void AppendFormat<T1>(string format, T1 arg1) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1>(format, arg1); } public void AppendFormat<T1, T2>(string format, T1 arg1, T2 arg2) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2>(format, arg1, arg2); } public void AppendFormat<T1, T2, T3>(string format, T1 arg1, T2 arg2, T3 arg3) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3>(format, arg1, arg2, arg3); } public void AppendFormat<T1, T2, T3, T4>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4>(format, arg1, arg2, arg3, arg4); } public void AppendFormat<T1, T2, T3, T4, T5>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5>(format, arg1, arg2, arg3, arg4, arg5); } public void AppendFormat<T1, T2, T3, T4, T5, T6>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6>(format, arg1, arg2, arg3, arg4, arg5, arg6); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } public void AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendFormat<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); } public void AppendJoin<T>(char separator, params T[] values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, List<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, ReadOnlySpan<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, IEnumerable<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, ICollection<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, IList<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, IReadOnlyList<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(char separator, IReadOnlyCollection<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, params T[] values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, List<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, ReadOnlySpan<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, IEnumerable<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, ICollection<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, IList<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, IReadOnlyList<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } public void AppendJoin<T>(string separator, IReadOnlyCollection<T> values) { ((Utf16ValueStringBuilder)(ref _vsb)).AppendJoin<T>(separator, values); } void IDisposable.Dispose() { ((Utf16ValueStringBuilder)(ref _vsb)).Dispose(); GC.SuppressFinalize(this); } } internal static class ZStringBuilderUtilities { internal const int DefaultBufferSize = 32768; internal static int CalcCapacity(Format format) { return format.Length + format.Items.Count * 8; } internal static ZStringBuilder CreateZStringBuilder() { return new ZStringBuilder(disposeImmediately: false); } internal static ZStringBuilder CreateZStringBuilder(Format format) { return CreateZStringBuilder(CalcCapacity(format)); } internal static ZStringBuilder CreateZStringBuilder(int capacity) { ZStringBuilder zStringBuilder = new ZStringBuilder(disposeImmediately: false); if (capacity > 32768) { zStringBuilder.Grow(capacity - 32768); } return zStringBuilder; } } [ExcludeFromCodeCoverage] public sealed class ZStringWriter : TextWriter { private readonly ZStringWriter _zw; private Encoding? _encoding; public override Encoding Encoding => _encoding ?? (_encoding = new UnicodeEncoding(bigEndian: false, byteOrderMark: false)); public ZStringWriter() : this(CultureInfo.CurrentCulture) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown _zw = new ZStringWriter((IFormatProvider)CultureInfo.CurrentCulture); } public ZStringWriter(IFormatProvider formatProvider) : base(formatProvider) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown _zw = new ZStringWriter(formatProvider); } public override void Close() { Dispose(disposing: true); } protected override void Dispose(bool disposing) { ((TextWriter)(object)_zw).Dispose(); base.Dispose(disposing); } public override void Write(char value) { ((TextWriter)(object)_zw).Write(value); } public override void Write(char[] buffer, int index, int count) { ((TextWriter)(object)_zw).Write(buffer, index, count); } public override void Write(string? value) { ((TextWriter)(object)_zw).Write(value ?? string.Empty); } public override void Write(bool value) { ((TextWriter)(object)_zw).Write(value); } public override void Write(decimal value) { ((TextWriter)(object)_zw).Write(value); } public override Task WriteAsync(char value) { return ((TextWriter)(object)_zw).WriteAsync(value); } public override Task WriteAsync(string? value) { return ((TextWriter)(object)_zw).WriteAsync(value ?? string.Empty); } public override Task WriteAsync(char[] buffer, int index, int count) { return ((TextWriter)(object)_zw).WriteAsync(buffer, index, count); } public override Task WriteLineAsync(char value) { return ((TextWriter)(object)_zw).WriteLineAsync(value); } public override Task WriteLineAsync(string? value) { return ((TextWriter)(object)_zw).WriteLineAsync(value ?? string.Empty); } public override Task WriteLineAsync(char[] buffer, int index, int count) { return ((TextWriter)(object)_zw).WriteLineAsync(buffer, index, count); } public override Task FlushAsync() { return ((TextWriter)(object)_zw).FlushAsync(); } public override string ToString() { return ((object)_zw).ToString(); } public override void Write(ReadOnlySpan<char> buffer) { ((TextWriter)(object)_zw).Write(buffer); } public override void WriteLine(ReadOnlySpan<char> buffer) { ((TextWriter)(object)_zw).WriteLine(buffer); } public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default(CancellationToken)) { return ((TextWriter)(object)_zw).WriteAsync(buffer, cancellationToken); } public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default(CancellationToken)) { return ((TextWriter)(object)_zw).WriteAsync(buffer, cancellationToken); } } } namespace SmartFormat.Utilities { public class FormatDelegate : IFormattable { private readonly Func<string?, string>? _getFormat1; private readonly Func<string?, IFormatProvider?, string>? _getFormat2; public FormatDelegate(Func<string?, string> getFormat) { _getFormat1 = getFormat; } public FormatDelegate(Func<string?, IFormatProvider?, string> getFormat) { _getFormat2 = getFormat; } string IFormattable.ToString(string? format, IFormatProvider? formatProvider) { if (_getFormat1 != null) { return _getFormat1(format); } if (_getFormat2 != null) { return _getFormat2(format, formatProvider); } return string.Empty; } } public interface ILocalizationProvider { string? GetString(string name); string? GetString(string name, string cultureName); string? GetString(string name, CultureInfo cultureInfo); } public class LocalizationProvider : ILocalizationProvider { internal readonly Dictionary<string, ResourceManager> Resources = new Dictionary<string, ResourceManager>(); public virtual CultureInfo? FallbackCulture { get; set; } public virtual bool ReturnNameIfNotFound { get; set; } public LocalizationProvider(bool isCaseSensitive = true, params ResourceManager[] resources) { foreach (ResourceManager resourceManager in resources) { DoAddResource(resourceManager, isCaseSensitive); } } public virtual void AddResource(ResourceManager resourceManager, bool isCaseSensitive = true) { DoAddResource(resourceManager, isCaseSensitive); } private void DoAddResource(ResourceManager resourceManager, bool isCaseSensitive = true) { if (!Resources.ContainsKey(resourceManager.BaseName)) { resourceManager.IgnoreCase = !isCaseSensitive; Resources.Add(resourceManager.BaseName, resourceManager); } } public virtual bool Remove(string resourceBaseName) { if (!Resources.ContainsKey(resourceBaseName)) { return false; } Resources.Remove(resourceBaseName); return true; } public virtual void Clear() { Resources.Clear(); } public virtual string? GetString(string name) { return GetString(name, (CultureInfo?)null); } public virtual string? GetString(string name, string cultureName) { return GetString(name, CultureInfo.GetCultureInfo(cultureName)); } public virtual string? GetString(string name, CultureInfo? cultureInfo) { foreach (ResourceManager value in Resources.Values) { string text = ((cultureInfo != null) ? value.GetString(name, cultureInfo) : value.GetString(name)); if (text == null && FallbackCulture != null) { value.GetString(name, FallbackCulture); } if (text != null) { return text; } } if (!ReturnNameIfNotFound) { return null; } return name; } } public static class PluralRules { public delegate int PluralRuleDelegate(decimal value, int pluralWordsCount); private static Dictionary<string, PluralRuleDelegate> DefaultLangToDelegate { get; } = new Dictionary<string, PluralRuleDelegate> { { "az", Singular }, { "bm", Singular }, { "bo", Singular }, { "dz", Singular }, { "fa", Singular }, { "hu", Singular }, { "id", Singular }, { "ig", Singular }, { "ii", Singular }, { "ja", Singular }, { "jv", Singular }, { "ka", Singular }, { "kde", Singular }, { "kea", Singular }, { "km", Singular }, { "kn", Singular }, { "ko", Singular }, { "ms", Singular }, { "my", Singular }, { "root", Singular }, { "sah", Singular }, { "ses", Singular }, { "sg", Singular }, { "th", Singular }, { "to", Singular }, { "vi", Singular }, { "wo", Singular }, { "yo", Singular }, { "zh", Singular }, { "af", DualOneOther }, { "bem", DualOneOther }, { "bg", DualOneOther }, { "bn", DualOneOther }, { "brx", DualOneOther }, { "ca", DualOneOther }, { "cgg", DualOneOther }, { "chr", DualOneOther }, { "da", DualOneOther }, { "de", DualOneOther }, { "dv", DualOneOther }, { "ee", DualOneOther }, { "el", DualOneOther }, { "en", DualOneOther }, { "eo", DualOneOther }, { "es", DualOneOther }, { "et", DualOneOther }, { "eu", DualOneOther }, { "fi", DualOneOther }, { "fo", DualOneOther }, { "fur", DualOneOther }, { "fy", DualOneOther }, { "gl", DualOneOther }, { "gsw", DualOneOther }, { "gu", DualOneOther }, { "ha", DualOneOther }, { "haw", DualOneOther }, { "he", DualOneOther }, { "is", DualOneOther }, { "it", DualOneOther }, { "kk", DualOneOther }, { "kl", DualOneOther }, { "ku", DualOneOther }, { "lb", DualOneOther }, { "lg", DualOneOther }, { "lo", DualOneOther }, { "mas", DualOneOther }, { "ml", DualOneOther }, { "mn", DualOneOther }, { "mr", DualOneOther }, { "nah", DualOneOther }, { "nb", DualOneOther }, { "ne", DualOneOther }, { "nl", DualOneOther }, { "nn", DualOneOther }, { "no", DualOneOther }, { "nyn", DualOneOther }, { "om", DualOneOther }, { "or", DualOneOther }, { "pa", DualOneOther }, { "pap", DualOneOther }, { "ps", DualOneOther }, { "pt", DualOneOther }, { "rm", DualOneOther }, { "saq", DualOneOther }, { "so", DualOneOther }, { "sq", DualOneOther }, { "ssy", DualOneOther }, { "sw", DualOneOther }, { "sv", DualOneOther }, { "syr", DualOneOther }, { "ta", DualOneOther }, { "te", DualOneOther }, { "tk", DualOneOther }, { "tr", DualOneOther }, { "ur", DualOneOther }, { "wae", DualOneOther }, { "xog", DualOneOther }, { "zu", DualOneOther }, { "ak", DualWithZero }, { "am", DualWithZero }, { "bh", DualWithZero }, { "fil", DualWithZero }, { "guw", DualWithZero }, { "hi", DualWithZero }, { "ln", DualWithZero }, { "mg", DualWithZero }, { "nso", DualWithZero }, { "ti", DualWithZero }, { "tl", DualWithZero }, { "wa", DualWithZero }, { "ff", DualFromZeroToTwo }, { "fr", DualFromZeroToTwo }, { "kab", DualFromZeroToTwo }, { "ga", TripleOneTwoOther }, { "iu", TripleOneTwoOther }, { "ksh", TripleOneTwoOther }, { "kw", TripleOneTwoOther }, { "se", TripleOneTwoOther }, { "sma", TripleOneTwoOther }, { "smi", TripleOneTwoOther }, { "smj", TripleOneTwoOther }, { "smn", TripleOneTwoOther }, { "sms", TripleOneTwoOther }, { "be", RussianSerboCroatian }, { "bs", RussianSerboCroatian }, { "hr", RussianSerboCroatian }, { "ru", RussianSerboCroatian }, { "sh", RussianSerboCroatian }, { "sr", RussianSerboCroatian }, { "uk", RussianSerboCroatian }, { "ar", Arabic }, { "br", Breton }, { "cs", Czech }, { "cy", Welsh }, { "gv", Manx }, { "lag", Langi }, { "lt", Lithuanian }, { "lv", Latvian }, { "mb", Macedonian }, { "mo", Moldavian }, { "mt", Maltese }, { "pl", Polish }, { "ro", Romanian }, { "shi", Tachelhit }, { "sk", Slovak }, { "sl", Slovenian }, { "tzm", CentralMoroccoTamazight } }; public static Dictionary<string, PluralRuleDelegate> IsoLangToDelegate { get; private set; } = new Dictionary<string, PluralRuleDelegate>(DefaultLangToDelegate); private static PluralRuleDelegate Singular => (decimal value, int pluralWordsCount) => 0; private static PluralRuleDelegate DualOneOther => (decimal value, int pluralWordsCount) => pluralWordsCount switch { 2 => (!(value == 1m)) ? 1 : 0, 3 => (!(value == 0m)) ? ((value == 1m) ? 1 : 2) : 0, 4 => (!(value < 0m)) ? ((value == 0m) ? 1 : ((value == 1m) ? 2 : 3)) : 0, _ => -1, }; private static PluralRuleDelegate DualWithZero => (decimal value, int pluralWordsCount) => (!(value == 0m) && !(value == 1m)) ? 1 : 0; private static PluralRuleDelegate DualFromZeroToTwo => delegate(decimal value, int pluralWordsCount) { switch (pluralWordsCount) { case 2: if (!(value >= 0m) || !(value < 2m)) { return 1; } return 0; case 3: return GetWordsCount3Value(value); case 4: return GetWordsCount4Value(value); default: return -1; } }; private static PluralRuleDelegate TripleOneTwoOther => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? ((value == 2m) ? 1 : 2) : 0; private static PluralRuleDelegate RussianSerboCroatian => (decimal value, int pluralWordsCount) => (!(value % 10m == 1m) || !(value % 100m != 11m)) ? (((value % 10m).BetweenWithoutFraction(2m, 4m) && !(value % 100m).BetweenWithoutFraction(12m, 14m)) ? 1 : 2) : 0; private static PluralRuleDelegate Arabic => (decimal value, int pluralWordsCount) => (!(value == 0m)) ? ((value == 1m) ? 1 : ((!(value == 2m)) ? ((!(value % 100m).BetweenWithoutFraction(3m, 10m)) ? ((!(value % 100m).BetweenWithoutFraction(11m, 99m)) ? 5 : 4) : 3) : 2)) : 0; private static PluralRuleDelegate Breton => delegate(decimal value, int pluralWordsCount) { if (value <= 1m) { if (value == 0m) { return 0; } if (value == 1m) { return 1; } } else { if (value == 2m) { return 2; } if (value == 3m) { return 3; } if (value == 6m) { return 4; } } return 5; }; private static PluralRuleDelegate Czech => (decimal value, int pluralWordsCount) => (!(value == 0m)) ? ((value == 1m) ? 1 : ((!value.BetweenWithoutFraction(2m, 4m)) ? ((!(value % 1m == 0m)) ? 4 : 3) : 2)) : 0; private static PluralRuleDelegate Welsh => delegate(decimal value, int pluralWordsCount) { if (value <= 1m) { if (value == 0m) { return 0; } if (value == 1m) { return 1; } } else { if (value == 2m) { return 2; } if (value == 3m) { return 3; } if (value == 6m) { return 4; } } return 5; }; private static PluralRuleDelegate Manx => (decimal value, int pluralWordsCount) => (!(value % 10m).BetweenWithoutFraction(1m, 2m) && !(value % 20m == 0m)) ? 1 : 0; private static PluralRuleDelegate Langi => delegate(decimal value, int pluralWordsCount) { if (value > 0m) { if (value < 2m) { return 1; } } else if (value == 0m) { return 0; } return 2; }; private static PluralRuleDelegate Lithuanian => (decimal value, int pluralWordsCount) => (!(value % 10m == 1m) || (value % 100m).BetweenWithoutFraction(11m, 19m)) ? (((value % 10m).BetweenWithoutFraction(2m, 9m) && !(value % 100m).BetweenWithoutFraction(11m, 19m)) ? 1 : 2) : 0; private static PluralRuleDelegate Latvian => (decimal value, int pluralWordsCount) => (!(value == 0m)) ? ((value % 10m == 1m && value % 100m != 11m) ? 1 : 2) : 0; private static PluralRuleDelegate Macedonian => (decimal value, int pluralWordsCount) => (!(value % 10m == 1m) || !(value != 11m)) ? 1 : 0; private static PluralRuleDelegate Moldavian => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? ((value == 0m || (value != 1m && (value % 100m).BetweenWithoutFraction(1m, 19m))) ? 1 : 2) : 0; private static PluralRuleDelegate Maltese => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? ((value == 0m || (value % 100m).BetweenWithoutFraction(2m, 10m)) ? 1 : ((!(value % 100m).BetweenWithoutFraction(11m, 19m)) ? 3 : 2)) : 0; private static PluralRuleDelegate Polish => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? (((value % 10m).BetweenWithoutFraction(2m, 4m) && !(value % 100m).BetweenWithoutFraction(12m, 14m)) ? 1 : ((!(value % 10m).BetweenWithoutFraction(0m, 1m) && !(value % 10m).BetweenWithoutFraction(5m, 9m) && !(value % 100m).BetweenWithoutFraction(12m, 14m)) ? 3 : 2)) : 0; private static PluralRuleDelegate Romanian => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? ((value == 0m || (value % 100m).BetweenWithoutFraction(1m, 19m)) ? 1 : 2) : 0; private static PluralRuleDelegate Tachelhit => (decimal value, int pluralWordsCount) => (!(value >= 0m) || !(value <= 1m)) ? (value.BetweenWithoutFraction(2m, 10m) ? 1 : 2) : 0; private static PluralRuleDelegate Slovak => (decimal value, int pluralWordsCount) => (!(value == 1m)) ? (value.BetweenWithoutFraction(2m, 4m) ? 1 : 2) : 0; private static PluralRuleDelegate Slovenian => (decimal value, int pluralWordsCount) => (!(value % 100m == 1m)) ? ((value % 100m == 2m) ? 1 : ((!(value % 100m).BetweenWithoutFraction(3m, 4m)) ? 3 : 2)) : 0; private static PluralRuleDelegate CentralMoroccoTamazight => (decimal value, int pluralWordsCount) => (!value.BetweenWithoutFraction(0m, 1m) && !value.BetweenWithoutFraction(11m, 99m)) ? 1 : 0; public static void RestoreDefault() { IsoLangToDelegate = new Dictionary<string, PluralRuleDelegate>(DefaultLangToDelegate); } private static int GetWordsCount3Value(decimal n) { if (n > 0m) { if (n < 2m) { return 1; } } else if (n == 0m) { return 0; } return 2; } private static int GetWordsCount4Value(decimal n) { if (!(n < 0m)) { if (n < 2m) { if (n == 0m) { return 1; } return 2; } return 3; } return 0; } public static PluralRuleDelegate GetPluralRule(string? twoLetterIsoLanguageName) { if (twoLetterIsoLanguageName != null && IsoLangToDelegate.TryGetValue(twoLetterIsoLanguageName, out PluralRuleDelegate value)) { return value; } throw new ArgumentException("IsoLangToDelegate not found for " + (twoLetterIsoLanguageName ?? "'null'"), "twoLetterIsoLanguageName"); } private static bool BetweenWithoutFraction(this decimal value, decimal min, decimal max) { if (value % 1m == 0m && value >= min) { return value <= max; } return false; } } public static class SystemTime { public static Func<DateTime> Now { get; private set; } = () => DateTime.Now; public static Func<DateTimeOffset> OffsetNow { get; private set; } = () => DateTimeOffset.Now; public static void SetDateTime(DateTime dateTimeNow) { Now = () => dateTimeNow; } public static void SetDateTimeOffset(DateTimeOffset dateTimeOffset) { OffsetNow = () => dateTimeOffset; } public static void ResetDateTime() { Now = () => DateTime.Now; OffsetNow = () => DateTimeOffset.Now; } } public static class TupleExtensions { private static readonly HashSet<Type> ValueTupleTypes = new HashSet<Type>(new Type[8] { typeof(ValueTuple<>), typeof(ValueTuple<, >), typeof(ValueTuple<, , >), typeof(ValueTuple<, , , >), typeof(ValueTuple<, , , , >), typeof(ValueTuple<, , , , , >), typeof(ValueTuple<, , , , , , >), typeof(ValueTuple<, , , , , , , >) }); public static bool IsValueTuple(this object obj) { return obj.GetType().IsValueTupleType(); } public static bool IsValueTupleType(this Type type) { if (type.GetTypeInfo().IsGenericType) { return ValueTupleTypes.Contains(type.GetGenericTypeDefinition()); } return false; } public static IEnumerable<object?> GetValueTupleItemObjects(this object tuple) { object tuple2 = tuple; return from f in tuple2.GetType().GetValueTupleItemFields() select f.GetValue(tuple2); } public static List<FieldInfo> GetValueTupleItemFields(this Type tupleType) { List<FieldInfo> list = new List<FieldInfo>(); int num = 1; FieldInfo runtimeField; while ((runtimeField = tupleType.GetRuntimeField($"Item{num}")) != null) { num++; list.Add(runtimeField); } return list; } public static IEnumerable<object?> GetValueTupleItemObjectsFlattened(this object tuple) { foreach (object valueTupleItemObject in tuple.GetValueTupleItemObjects()) { if (valueTupleItemObject != null && valueTupleItemObject.IsValueTuple()) { foreach (object item in valueTupleItemObject.GetValueTupleItemObjectsFlattened()) { yield return item; } } else if (valueTupleItemObject == null) { yield return null; } else { yield return valueTupleItemObject; } } } } internal static class Validation { private static readonly char[] Valid = new char[3] { '|', ',', '~' }; public static char GetValidSplitCharOrThrow(char toCheck) { if (toCheck != Valid[0] && toCheck != Valid[1] && toCheck != Valid[2]) { throw new ArgumentException($"Only '{Valid[0]}', '{Valid[1]}' and '{Valid[2]}' are valid split chars."); } return toCheck; } } } namespace SmartFormat.Pooling { [Serializable] public class PoolingException : InvalidOperationException { public Type PoolType { get; } public PoolingException(string message, Type poolType) : base(message) { PoolType = poolType; } [Obsolete("This API supports obsolete formatter-based serialization. It will be removed in version 4.")] protected PoolingException(SerializationInfo info, StreamingContext context) : base(info, context) { PoolType = typeof(object); } } internal static class PoolRegistry { public static readonly ConcurrentDictionary<Type, object> Items = new ConcurrentDictionary<Type, object>(); public static T GetOrAdd<T>(T pool) where T : class { return (T)Items.GetOrAdd(typeof(T), pool); } public static void TryRemove<T>(T pool) where T : class { Items.TryRemove(typeof(T), out object _); } public static T? Get<T>() where T : class { return (T)Items[typeof(T)]; } } } namespace SmartFormat.Pooling.SpecializedPools { internal class CollectionPool<TCollection, TItem> : SpecializedPoolAbstract<TCollection> where TCollection : class, ICollection<TItem>, new() { private static readonly Lazy<CollectionPool<TCollection, TItem>> Lazy = new Lazy<CollectionPool<TCollection, TItem>>(() => new CollectionPool<TCollection, TItem>(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static CollectionPool<TCollection, TItem> Instance => PoolRegistry.GetOrAdd(Lazy.Value); protected CollectionPool() { Policy.FunctionOnCreate = () => new TCollection(); Policy.ActionOnReturn = delegate(TCollection coll) { coll.Clear(); }; } } internal sealed class DictionaryPool<TKey, TValue> : CollectionPool<Dictionary<TKey, TValue>, KeyValuePair<TKey, TValue>> where TKey : notnull { private static readonly Lazy<DictionaryPool<TKey, TValue>> Lazy = new Lazy<DictionaryPool<TKey, TValue>>(() => new DictionaryPool<TKey, TValue>(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public new static DictionaryPool<TKey, TValue> Instance => PoolRegistry.GetOrAdd(Lazy.Value); private DictionaryPool() { } } internal sealed class HashSetPool<T> : CollectionPool<HashSet<T>, T> { private static readonly Lazy<HashSetPool<T>> Lazy = new Lazy<HashSetPool<T>>(() => new HashSetPool<T>(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public new static HashSetPool<T> Instance => PoolRegistry.GetOrAdd(Lazy.Value); private HashSetPool() { } } internal sealed class ListPool<T> : CollectionPool<List<T>, T> { private static readonly Lazy<ListPool<T>> Lazy = new Lazy<ListPool<T>>(() => new ListPool<T>(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public new static ListPool<T> Instance => PoolRegistry.GetOrAdd(Lazy.Value); private ListPool() { } } internal abstract class SpecializedPoolAbstract<T> : IDisposable where T : class { private bool _isThreadSafeMode = SmartSettings.IsThreadSafeMode; protected readonly PoolPolicy<T> Policy = new PoolPolicy<T>(); internal ObjectPool<T> Pool { get; set; } public bool IsThreadSafeMode => _isThreadSafeMode; protected SpecializedPoolAbstract() { Pool = LazyCreateObjectPool(); } internal void Reset(bool? isThreadSafeMode) { _isThreadSafeMode = isThreadSafeMode ?? SmartSettings.IsThreadSafeMode; PoolRegistry.TryRemove(this); Pool.Dispose(); Pool = LazyCreateObjectPool(); } private ObjectPool<T> LazyCreateObjectPool() { if (!_isThreadSafeMode) { return new Lazy<ObjectPoolSingleThread<T>>(() => new ObjectPoolSingleThread<T>(Policy), LazyThreadSafetyMode.None).Value; } return new Lazy<ObjectPoolConcurrent<T>>(() => new ObjectPoolConcurrent<T>(Policy), LazyThreadSafetyMode.PublicationOnly).Value; } public virtual T Get() { if (!PoolSettings.IsPoolingEnabled) { return Policy.FunctionOnCreate(); } return Pool.Get(); } public virtual PooledObject<T> Get(out T instance) { if (!PoolSettings.IsPoolingEnabled) { instance = Policy.FunctionOnCreate(); return new PooledObject<T>(instance, Pool); } instance = Get(); return new PooledObject<T>(instance, Pool); } public virtual void Return(T toReturn) { if (PoolSettings.IsPoolingEnabled) { Pool.Return(toReturn); } } public virtual void Clear() { Pool.Clear(); } protected virtual void Dispose(bool disposing) { if (disposing) { Reset(null); } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } internal sealed class StringBuilderPool : SpecializedPoolAbstract<StringBuilder> { private static readonly Lazy<StringBuilderPool> Lazy = new Lazy<StringBuilderPool>(() => new StringBuilderPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public int DefaultStringBuilderCapacity { get; set; } = 1024; public static StringBuilderPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private StringBuilderPool() { Policy.FunctionOnCreate = () => new StringBuilder(DefaultStringBuilderCapacity); Policy.ActionOnReturn = delegate(StringBuilder sb) { sb.Clear(); sb.Capacity = DefaultStringBuilderCapacity; }; } } } namespace SmartFormat.Pooling.SmartPools { internal sealed class FormatDetailsPool : SmartPoolAbstract<FormatDetails> { private static readonly Lazy<FormatDetailsPool> Lazy = new Lazy<FormatDetailsPool>(() => new FormatDetailsPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static FormatDetailsPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private FormatDetailsPool() { Policy.FunctionOnCreate = () => new FormatDetails(); Policy.ActionOnReturn = delegate(FormatDetails fd) { fd.Clear(); }; } public override void Return(FormatDetails toReturn) { if (toReturn == InitializationObject.FormatDetails) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class FormatPool : SmartPoolAbstract<Format> { private static readonly Lazy<FormatPool> Lazy = new Lazy<FormatPool>(() => new FormatPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static FormatPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private FormatPool() { Policy.FunctionOnCreate = () => new Format(); Policy.ActionOnReturn = delegate(Format fmt) { fmt.ReturnToPool(); }; } public override void Return(Format toReturn) { if (toReturn == InitializationObject.Format) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class FormattingInfoPool : SmartPoolAbstract<FormattingInfo> { private static readonly Lazy<FormattingInfoPool> Lazy = new Lazy<FormattingInfoPool>(() => new FormattingInfoPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static FormattingInfoPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private FormattingInfoPool() { Policy.FunctionOnCreate = () => new FormattingInfo(); Policy.ActionOnReturn = delegate(FormattingInfo fi) { fi.ReturnToPool(); }; } public override void Return(FormattingInfo toReturn) { if (toReturn == InitializationObject.FormattingInfo) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal static class InitializationObject { public static readonly IList<object?> ObjectList = new List<object>(1); public static readonly List<int> IntegerList = new List<int>(1); public static readonly SmartSettings SmartSettings = new SmartSettings(); public static readonly SmartFormatter SmartFormatter = new SmartFormatter(SmartSettings); public static readonly Format Format = new Format().Initialize(SmartSettings, "init"); public static readonly LiteralText LiteralText = new LiteralText().Initialize(SmartSettings, Format, string.Empty, 0, 0); public static readonly Placeholder Placeholder = new Placeholder().Initialize(Format, 0, 0); public static readonly Selector Selector = new Selector().Initialize(SmartSettings, Placeholder, string.Empty, 0, 0, 0, 0); public static readonly IOutput Output = new NullOutput(); public static readonly FormatDetails FormatDetails = new FormatDetails().Initialize(SmartFormatter, Format, ObjectList, null, Output); public static readonly FormattingInfo FormattingInfo = new FormattingInfo().Initialize(FormatDetails, Format, null); public static readonly ParsingErrors ParsingErrors = new ParsingErrors().Initialize(Format); public static readonly SplitList SplitList = new SplitList().Initialize(Format, IntegerList); } internal sealed class LiteralTextPool : SmartPoolAbstract<LiteralText> { private static readonly Lazy<LiteralTextPool> Lazy = new Lazy<LiteralTextPool>(() => new LiteralTextPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static LiteralTextPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private LiteralTextPool() { Policy.FunctionOnCreate = () => new LiteralText(); Policy.ActionOnReturn = delegate(LiteralText lt) { lt.Clear(); }; } public override void Return(LiteralText toReturn) { if (toReturn == InitializationObject.LiteralText) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class ParsingErrorsPool : SmartPoolAbstract<ParsingErrors> { private static readonly Lazy<ParsingErrorsPool> Lazy = new Lazy<ParsingErrorsPool>(() => new ParsingErrorsPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static ParsingErrorsPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private ParsingErrorsPool() { Policy.FunctionOnCreate = () => new ParsingErrors(); Policy.ActionOnReturn = delegate(ParsingErrors pe) { pe.Clear(); }; } public override void Return(ParsingErrors toReturn) { if (toReturn == InitializationObject.ParsingErrors) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class PlaceholderPool : SmartPoolAbstract<Placeholder> { private static readonly Lazy<PlaceholderPool> Lazy = new Lazy<PlaceholderPool>(() => new PlaceholderPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static PlaceholderPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private PlaceholderPool() { Policy.FunctionOnCreate = () => new Placeholder(); Policy.ActionOnReturn = delegate(Placeholder ph) { ph.ReturnToPool(); }; } public override void Return(Placeholder toReturn) { if (toReturn == InitializationObject.Placeholder) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class SelectorPool : SmartPoolAbstract<Selector> { private static readonly Lazy<SelectorPool> Lazy = new Lazy<SelectorPool>(() => new SelectorPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static SelectorPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private SelectorPool() { Policy.FunctionOnCreate = () => new Selector(); Policy.ActionOnReturn = delegate(Selector selector) { selector.Clear(); }; } public override void Return(Selector toReturn) { if (toReturn == InitializationObject.Selector) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal abstract class SmartPoolAbstract<T> : SpecializedPoolAbstract<T> where T : class { public override T Get() { return base.Get(); } public override PooledObject<T> Get(out T instance) { return base.Get(out instance); } } internal sealed class SplitListPool : SmartPoolAbstract<SplitList> { private static readonly Lazy<SplitListPool> Lazy = new Lazy<SplitListPool>(() => new SplitListPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static SplitListPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private SplitListPool() { Policy.FunctionOnCreate = () => new SplitList(); Policy.ActionOnReturn = delegate(SplitList sl) { sl.Clear(); }; } public override void Return(SplitList toReturn) { if (toReturn == InitializationObject.SplitList) { throw new PoolingException("InitializationObjects cannot be returned to the pool.", GetType()); } base.Return(toReturn); } } internal sealed class StringOutputPool : SmartPoolAbstract<StringOutput> { private static readonly Lazy<StringOutputPool> Lazy = new Lazy<StringOutputPool>(() => new StringOutputPool(), SmartSettings.IsThreadSafeMode ? LazyThreadSafetyMode.PublicationOnly : LazyThreadSafetyMode.None); public static StringOutputPool Instance => PoolRegistry.GetOrAdd(Lazy.Value); private StringOutputPool() { Policy.FunctionOnCreate = () => new StringOutput(); Policy.ActionOnReturn = delegate(StringOutput so) { so.Clear(); }; } } } namespace SmartFormat.Pooling.ObjectPools { internal interface IObjectPool<T> : IDisposable, IPoolCounters where T : class { IReadOnlyList<T> PoolItems { get; } T Get(); PooledObject<T> Get(out T instance); void Return(T element); void Clear(); } internal interface IPoolCounters { int CountAll { get; } int CountActive { get; } int CountInactive { get; } } internal class LinkedPool<T> : ObjectPool<T> where T : class { internal class LinkedPoolItem { internal LinkedPoolItem? PoolNext; internal T? Value; } internal LinkedPoolItem? PoolFirst; internal LinkedPoolItem? NextAvailableListItem; private int _countAll; private int _countInactive; public override bool IsThreadSafeMode => false; public override int CountAll => _countAll; public override IReadOnlyList<T> PoolItems => (from i in GetAllPoolItems() where i.Value != null select i.Value).ToList().AsReadOnly(); public override int CountInactive => _countInactive; public LinkedPool(PoolPolicy<T> poolPolicy) : base(poolPolicy) { } public override T Get() { if (!PoolSettings.IsPoolingEnabled) { return base.PoolPolicy.FunctionOnCreate(); } T result; if (PoolFirst == null) { result = base.PoolPolicy.FunctionOnCreate(); _countAll++; return result; } LinkedPoolItem poolFirst = PoolFirst; result = poolFirst.Value; PoolFirst = poolFirst.PoolNext; poolFirst.PoolNext = NextAvailableListItem; NextAvailableListItem = poolFirst; NextAvailableListItem.Value = null; _countInactive--; base.PoolPolicy.ActionOnGet?.Invoke(result); return result; } public override void Return(T element) { if (!PoolSettings.IsPoolingEnabled) { return; } for (LinkedPoolItem linkedPoolItem = PoolFirst; linkedPoolItem != null; linkedPoolItem = linkedPoolItem.PoolNext) { if (PoolSettings.CheckReturnedObjectsExistInPool && linkedPoolItem.Value == element) { throw new PoolingException("Trying to return an object that has already been returned to the pool.", GetType()); } } base.PoolPolicy.ActionOnReturn?.Invoke(element); if (CountInactive < base.PoolPolicy.MaximumPoolSize) { LinkedPoolItem linkedPoolItem2 = NextAvailableListItem; if (linkedPoolItem2 == null) { linkedPoolItem2 = new LinkedPoolItem(); } else { NextAvailableListItem = linkedPoolItem2.PoolNext; } linkedPoolItem2.Value = element; linkedPoolItem2.PoolNext = PoolFirst; PoolFirst = linkedPoolItem2; _countInactive++; } else { base.PoolPolicy.ActionOnDestroy?.Invoke(element); } } public override void Clear() { if (base.PoolPolicy.ActionOnDestroy != null) { foreach (T item in from item in GetAllPoolItems() select item.Value) { if (item != null) { base.PoolPolicy.ActionOnDestroy(item); } } } PoolFirst = null; NextAvailableListItem = null; _countInactive = 0; _countAll = 0; } private IEnumerable<LinkedPoolItem> GetAllPoolItems() { for (LinkedPoolItem item = PoolFirst; item != null; item = item.PoolNext) { if (item.Value != null) { yield return item; } } } } internal abstract class ObjectPool<T> : IObjectPool<T>, IDisposable, IPoolCounters where T : class { public abstract bool IsThreadSafeMode { get; } [Obsolete("Use PoolSettings.IsPoolingEnabled instead.")] public bool IsPoolingEnabled { get { return PoolSettings.IsPoolingEnabled; } internal set { PoolSettings.IsPoolingEnabled = value; } } protected PoolPolicy<T> PoolPolicy { get; } public abstract int CountAll { get; } public abstract IReadOnlyList<T> PoolItems { get; } public int CountActive => CountAll - CountInactive; public abstract int CountInactive { get; } protected ObjectPool(PoolPolicy<T> poolPolicy) { PoolPolicy = poolPolicy; } public abstract T Get(); public PooledObject<T> Get(out T instance) { instance = Get(); return new PooledObject<T>(instance, this); } public abstract void Return(T element); public abstract void Clear(); protected virtual void Dispose(bool disposing) { if (disposing) { Clear(); } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } internal class ObjectPoolConcurrent<T> : ObjectPool<T> where T : class { private readonly ConcurrentStack<T> _stack; private int _countAll; public override bool IsThreadSafeMode => true; public override int CountAll => _countAll; public override IReadOnlyList<T> PoolItems => _stack.ToList().AsReadOnly(); public override int CountInactive => _stack.Count; public ObjectPoolConcurrent(PoolPolicy<T> poolPolicy) : base(poolPolicy) { _stack = new ConcurrentStack<T>(); } public override T Get() { if (!PoolSettings.IsPoolingEnabled) { return base.PoolPolicy.FunctionOnCreate(); } if (!_stack.TryPop(out var result)) { result = base.PoolPolicy.FunctionOnCreate(); Interlocked.Increment(ref _countAll); return result; } base.PoolPolicy.ActionOnGet?.Invoke(result); return result; } public override void Return(T element) { if (PoolSettings.IsPoolingEnabled) { if (PoolSettings.CheckReturnedObjectsExistInPool && !_stack.IsEmpty && _stack.Contains(element)) { throw new PoolingException($"Trying to return an object of type '{element.GetType()}', that has already been returned to the pool.", GetType()); } base.PoolPolicy.ActionOnReturn?.Invoke(element); if (CountInactive < base.PoolPolicy.MaximumPoolSize) { _stack.Push(element); } else { base.PoolPolicy.ActionOnDestroy?.Invoke(element); } } } public override void Clear() { if (base.PoolPolicy.ActionOnDestroy != null) { foreach (T item in _stack) { base.PoolPolicy.ActionOnDestroy(item); } } _stack.Clear(); _countAll = 0; } } internal class ObjectPoolSingleThread<T> : ObjectPool<T> where T : class { private readonly Stack<T> _stack; private int _countAll; public override bool IsThreadSafeMode => false; public override int CountAll => _countAll; public override IReadOnlyList<T> PoolItems => _stack.ToList().AsReadOnly(); public override int CountInactive => _stack.Count; public ObjectPoolSingleThread(PoolPolicy<T> poolPolicy) : base(poolPolicy) { _stack = new Stack<T>(poolPolicy.InitialPoolSize); } public override T Get() { if (!PoolSettings.IsPoolingEnabled) { return base.PoolPolicy.FunctionOnCreate(); } T result; if (_stack.Count == 0) { result = base.PoolPolicy.FunctionOnCreate(); _countAll++; return result; } try { result = _stack.Pop(); } catch { result = base.PoolPolicy.FunctionOnCreate(); Interlocked.Increment(ref _countAll); return result; } base.PoolPolicy.ActionOnGet?.Invoke(result); return result; } public override void Return(T element) { if (PoolSettings.IsPoolingEnabled) { if (PoolSettings.CheckReturnedObjectsExistInPool && _stack.Count > 0 && _stack.Contains(element)) { throw new PoolingException($"Trying to return an object of type '{element.GetType()}', that has already been returned to the pool.", GetType()); } base.PoolPolicy.ActionOnReturn?.Invoke(element); if (CountInactive < base.PoolPolicy.MaximumPoolSize) { _stack.Push(element); } else { base.PoolPolicy.ActionOnDestroy?.Invoke(element); } } } public override void Clear() { if (base.PoolPolicy.ActionOnDestroy != null) { foreach (T item in _stack) { base.PoolPolicy.ActionOnDestroy(item); } } _stack.Clear(); _countAll = 0; } } internal readonly struct PooledObject<T> : IDisposable where T : class { private readonly T _value; private readonly IObjectPool<T> _pool; internal PooledObject(T value, IObjectPool<T> pool) { _value = value; _pool = pool; } void IDisposable.Dispose() { _pool.Return(_value); } } internal class PoolPolicy<T> where T : class { private uint _maximumPoolSize = 10000u; public uint MaximumPoolSize { get { return _maximumPoolSize; } set { if (value == 0) { throw new PoolingException("Policy for MaximumPoolSize size must be greater than 0", typeof(T)); } _maximumPoolSize = value; } } public int InitialPoolSize { get; set; } = 10; public Func<T> FunctionOnCreate { get; set; } = delegate { throw new PoolingException("'FunctionOnCreate' is not set in PoolPolicy.", typeof(T)); }; public Action<T>? ActionOnDestroy { get; set; } public Action<T>? ActionOnGet { get; set; } public Action<T>? ActionOnReturn { get; set; } } } namespace SmartFormat.Extensions { public class ChooseFormatter : SmartFormat.Core.Extensions.IFormatter { private CultureInfo? _cultureInfo; private char _splitChar = '|'; public char SplitChar { get { return _splitChar; } set { _splitChar = Validation.GetValidSplitCharOrThrow(value); } } [Obsolete("Use property \"Name\" instead", true)] public string[] Names { get; set; } = new string[2] { "choose", "c" }; public string Name { get; set; } = "choose"; public bool CanAutoDetect { get; set; } public CaseSensitivityType CaseSensitivity { get; set; } public bool TryEvaluateFormat(IFormattingInfo formattingInfo) { string[] chooseOptions = formattingInfo.FormatterOptions.Split(SplitChar); IList<Format> list = formattingInfo.Format?.Split(SplitChar); if (list == null || list.Count < 2) { if (string.IsNullOrEmpty(formattingInfo.Placeholder?.FormatterName)) { return false; } throw new FormatException("Formatter named '" + formattingInfo.Placeholder?.FormatterName + "' requires at least 2 format options."); } _cultureInfo = (formattingInfo.FormatDetails.Provider as CultureInfo) ?? CultureInfo.CurrentUICulture; Format format = DetermineChosenFormat(formattingInfo, list, chooseOptions); formattingInfo.FormatAsChild(format, formattingInfo.CurrentValue); return true; } private Format DetermineChosenFormat(IFormattingInfo formattingInfo, IList<Format> choiceFormats, string[] chooseOptions) { string currentValueString; int num = GetChosenIndex(formattingInfo, chooseOptions, out currentValueString); if (choiceFormats.Count < chooseOptions.Length) { throw formattingInfo.FormattingException("You must specify at least " + chooseOptions.Length + " choices"); } if (choiceFormats.Count > chooseOptions.Length + 1) { throw formattingInfo.FormattingException("You cannot specify more than " + (chooseOptions.Length + 1) + " choices"); } if (num == -1 && choiceFormats.Count == chooseOptions.Length) { throw formattingInfo.FormattingException("\"" + currentValueString + "\" is not a valid choice, and a \"default\" choice was not supplied"); } if (num == -1) { num = choiceFormats.Count - 1; } return choiceFormats[num]; } private int GetChosenIndex(IFormattingInfo formattingInfo, string[] chooseOptions, out string currentValueString) { IFormattingInfo formattingInfo2 = formattingInfo; object currentValue = formattingInfo2.CurrentValue; string valAsString; if (currentValue != null) { if (currentValue is bool flag) { valAsString = (currentValueString = flag.ToString()); return Array.FindIndex(chooseOptions, (string t) => t.Equals(valAsString, StringComparison.OrdinalIgnoreCase)); } valAsString = (currentValueString = formattingInfo2.CurrentValue.ToString()); return Array.FindIndex(chooseOptions, (string t) => AreEqual(t, valAsString, formattingInfo2.FormatDetails.Settings.CaseSensitivity)); } valAsString = (currentValueString = "null"); return Array.FindIndex(chooseOptions, (string t) => t.Equals(valAsString, StringComparison.OrdinalIgnoreCase)); } private bool AreEqual(string s1, string s2, CaseSensitivityType caseSensitivityFromSettings) { CultureInfo cultureInfo = _cultureInfo; if (((caseSensitivityFromSettings == CaseSensitivity) ? caseSensitivityFromSettings : CaseSensitivity) != 0) { return cultureInfo.CompareInfo.Compare(s1, s2, CompareOptions.IgnoreCase) == 0; } return cultureInfo.CompareInfo.Compare(s1, s2, CompareOptions.None) == 0; } } public class ConditionalFormatter : SmartFormat.Core.Extensions.IFormatter { private static readonly Regex _complexConditionPattern = new Regex("^ (?: ([&/]?) ([<>=!]=?) ([0-9.-]+) )+ \\?", RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace, TimeSpan.FromMilliseconds(500.0)); private char _splitChar = '|'; [Obsolete("Use property \"Name\" instead", true)] public string[] Names { get; set; } = new string[3] { "conditional", "cond", string.Empty }; public string Name { get; set; } = "cond"; public bool CanAutoDetect { get; set; } = true; public char SplitChar { get { return _splitChar; } set { _splitChar = Validation.GetValidSplitCharOrThrow(value); } } public bool TryEvaluateFormat(IFormattingInfo formattingInfo) { Format format = formattingInfo.Format; object currentValue = formattingInfo.CurrentValue; IList<Format> list2; if (format == null) { IList<Format> list = new List<Format>(0); list2 = list; } else { list2 = format.Split(SplitChar); } IList<Format> list3 = list2; if (format == null || list3.Count == 1) { if (string.IsNullOrEmpty(formattingInfo.Placeholder?.FormatterName)) { return false; } throw new FormatException("Formatter named '" + formattingInfo.Placeholder?.FormatterName + "' requires at least 2 format parameters."); } bool flag = currentValue is IConvertible; if (flag) { bool flag2 = ((currentValue is DateTime || currentValue is string || currentValue is bool) ? true : false); flag = !flag2; } bool flag3 = flag; decimal num = (flag3 ? Convert.ToDecimal(currentValue) : 0m); int num2; if (flag3) { num2 = -1; while (num2++ < list3.Count) { if (!TryEvaluateCondition(list3[num2], num, out bool conditionResult, out Format outputItem)) { if (num2 == 0) { break; } conditionResult = true; } if (conditionResult) { formattingInfo.FormatAsChild(outputItem, currentValue); return true; } } } int count = list3.Count; if (flag3) { num2 = ((!(num < 0m)) ? Math.Min((int)Math.Floor(num), count - 1) : (count - 1)); } else { object obj = currentValue; if (!(obj is bool flag4)) { if (!(obj is DateTime dateTime)) { if (!(obj is DateTimeOffset dateTimeOffset)) { if (!(obj is TimeSpan timeSpan)) { num2 = (((!(obj is string value)) ? (currentValue == null) : string.IsNullOrEmpty(value)) ? 1 : 0); } else if (count == 3 && timeSpan == TimeSpan.Zero) { num2 = 1; } else { TimeSpan timeSpan2 = timeSpan; num2 = ((timeSpan2.CompareTo(TimeSpan.Zero) > 0) ? (count - 1) : 0); } } else if (count == 3 && dateTimeOffset.UtcDateTime.Date == SystemTime.OffsetNow().UtcDateTime.Date) { num2 = 1; } else { DateTimeOffset dateTimeOffset2 = dateTimeOffset; num2 = ((!(dateTimeOffset2.UtcDateTime <= SystemTime.OffsetNow().UtcDateTime)) ? (count - 1) : 0); } } else if (count == 3 && dateTime.ToUniversalTime().Date == SystemTime.Now().ToUniversalTime().Date) { num2 = 1; } else { DateTime dateTime2 = dateTime; num2 = ((!(dateTime2.ToUniversalTime() <= SystemTime.Now().ToUniversalTime())) ? (count - 1) : 0); } } else { num2 = ((!flag4) ? 1 : 0); } } Format format2 = list3[num2]; formattingInfo.FormatAsChild(format2, currentValue); return true; } private static bool TryEvaluateCondition(Format parameter, decimal value, out bool conditionResult, out Format outputItem) { conditionResult = false; Match match = _complexConditionPattern.Match(parameter.BaseString, parameter.StartIndex, parameter.EndIndex - parameter.StartIndex); if (!match.Success) { outputItem = parameter; return false; } CaptureCollection captures = match.Groups[1].Captures; CaptureCollection captures2 = match.Groups[2].Captures; CaptureCollection captures3 = match.Groups[3].Captures; int num = 0; while (num < captures.Count) { decimal num2 = decimal.Parse(captures3[num].Value); bool flag = false; string value2 = captures2[num].Value; if (value2 != null) { int length = value2.Length; if (length == 1) { switch (value2[0]) { case '>': flag = value > num2; goto IL_0196; case '<': flag = value < num2; goto IL_0196; case '=': break; case '!': goto IL_018c; default: goto IL_0196; } goto IL_0168; } if (length == 2) { switch (value2[0]) { case '=': break; case '<': if (value2 == "<=") { flag = value <= num2; } goto IL_0196; case '>': if (value2 == ">=") { flag = value >= num2; } goto IL_0196; case '!': goto IL_0140; default: goto IL_0196; } if (value2 == "==") { goto IL_0168; } } } goto IL_0196; IL_0140: if (value2 == "!=") { goto IL_018c; } goto IL_0196; IL_0196: if (num == 0) { conditionResult = flag; } else if (captures[num].Value == "/") { conditionResult |= flag; } else { conditionResult &= flag; } num++; continue; IL_018c: flag = value != num2; goto IL_0196; IL_0168: flag = value == num2; goto IL_0196; } int start = match.Index + match.Length - parameter.StartIndex; outputItem = parameter.Substring(start); return true; } } public class CustomPluralRuleProvider : IFormatProvider { private readonly PluralRules.PluralRuleDelegate _pluralRule; public CustomPluralRuleProvider(PluralRules.PluralRuleDelegate pluralRule) { _pluralRule = pluralRule; } public object? GetFormat(Type? formatType) { if (!(formatType == typeof(CustomPluralRuleProvider))) { return null; } return this; } public PluralRules.PluralRuleDelegate GetPluralRule() { return _pluralRule; } } public class DefaultFormatter : SmartFormat.Core.Extensions.IFormatter { [Obsolete("Use property \"Name\" instead", true)] public string[] Names { get; set; } = new string[3] { "default", "d", string.Empty }; public string Name { get; set; } = "d"; public bool CanAutoDetect { get; set; } = true; public bool TryEvaluateFormat(IFormattingInfo formattingInfo) { Format format = formattingInfo.Format; object currentValue = formattingInfo.CurrentValue; if (format != null && format.HasNested) { formattingInfo.FormatAsChild(format, currentValue); return true; } IFormatProvider provider = formattingInfo.FormatDetails.Provider; if (provider?.GetFormat(typeof(ICustomFormatter)) is ICustomFormatter customFormatter) { string format2 = format?.GetLiteralText(); formattingInfo.Write(customFormatter.Format(format2, currentValue, provider).AsSpan()); return true; } if (currentValue is IFormattable formattable) { string text = format?.ToString(); formattingInfo.Write(formattable.ToString(text, provider).AsSpan()); return true; } ReadOnlySpan<char> text2 = currentValue?.ToString().AsSpan() ?? ((ReadOnlySpan<char>)Span<char>.Empty); formattingInfo.Write(text2); return true; } } public class DefaultSource : Source { public override bool TryEvaluateSelector(ISelectorInfo selectorInfo) { string selectorText = selectorInfo.SelectorText; FormatDetails formatDetails = selectorInfo.FormatDetails; if (int.TryParse(selectorText, out var result) && selectorInfo.SelectorIndex