Decompiled source of SmartFormat Extensions Xml v3.4.0

BepInEx/core/SmartFormat.Extensions.Xml/netstandard2.1/SmartFormat.Extensions.Xml.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using SmartFormat.Core.Extensions;
using SmartFormat.Core.Parsing;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SmartFormat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2011-2024 SmartFormat Project")]
[assembly: AssemblyDescription("This package is a SmartFormat extension for reading and formatting System.Xml.Linq.XElement\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.4.0.775")]
[assembly: AssemblyInformationalVersion("3.4.0+44165bb215406f71e3efd5dbc3bbbc6e20570fbd")]
[assembly: AssemblyProduct("SmartFormat")]
[assembly: AssemblyTitle("SmartFormat.Extensions.Xml")]
[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.Extensions
{
	public class XElementFormatter : IFormatter
	{
		[Obsolete("Use property \"Name\" instead", true)]
		public string[] Names { get; set; } = new string[4]
		{
			"xelement",
			"xml",
			"x",
			string.Empty
		};


		public string Name { get; set; } = "xml";


		public bool CanAutoDetect { get; set; } = true;


		public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
		{
			Format format = formattingInfo.Format;
			object currentValue = formattingInfo.CurrentValue;
			if (format != null && format.HasNested)
			{
				Placeholder placeholder = formattingInfo.Placeholder;
				if (string.IsNullOrEmpty((placeholder != null) ? placeholder.FormatterName : null))
				{
					return false;
				}
				Placeholder placeholder2 = formattingInfo.Placeholder;
				throw new FormatException("Formatter named '" + ((placeholder2 != null) ? placeholder2.FormatterName : null) + "' cannot process nested formats.");
			}
			XElement xElement = null;
			if (currentValue is IList<XElement> list && list.Count > 0)
			{
				xElement = list[0];
			}
			XElement xElement2 = xElement ?? (currentValue as XElement);
			if (xElement2 != null)
			{
				formattingInfo.Write(xElement2.Value);
				return true;
			}
			return false;
		}
	}
	public class XmlSource : Source
	{
		public override bool TryEvaluateSelector(ISelectorInfo selectorInfo)
		{
			if (!(selectorInfo.CurrentValue is XElement xElement))
			{
				return false;
			}
			string selector = selectorInfo.SelectorText;
			List<XElement> list = (from x in xElement.Elements()
				where x.Name.LocalName == selector
				select x).ToList();
			if (list.Count == 0)
			{
				return false;
			}
			selectorInfo.Result = list;
			return true;
		}
	}
}