Decompiled source of BonerBuzzer v1.0.0

plugins/BonerBuzzer.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using Buttplug.Client;
using Buttplug.Client.Connectors.WebsocketConnector;
using Buttplug.Core;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BonerBuzzer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Buttplug.io support for Trombone Champ")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BonerBuzzer")]
[assembly: AssemblyTitle("BonerBuzzer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BonerBuzzer
{
	[BepInPlugin("BonerBuzzer", "BonerBuzzer", "1.0.0")]
	public class BonerBuzzerPlugin : BaseUnityPlugin
	{
		private static ButtplugClient buttplugClient;

		public static BonerBuzzerPlugin Instance;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				buttplugClient = new ButtplugClient("Tromboner");
				buttplugClient.DeviceAdded += DeviceAdded;
				buttplugClient.DeviceRemoved += DeviceRemoved;
				buttplugClient.PingTimeout += PingTimeout;
				buttplugClient.ErrorReceived += ErrorReceived;
				Connect();
				Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BonerBuzzer is loaded!");
			}
		}

		private void DeviceAdded(object sender, DeviceAddedEventArgs args)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Device " + args.Device.DisplayName + " added"));
		}

		private void DeviceRemoved(object sender, DeviceRemovedEventArgs args)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Device " + args.Device.DisplayName + " removed"));
		}

		private void PingTimeout(object sender, EventArgs args)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Client timed out");
		}

		private void ErrorReceived(object sender, ButtplugExceptionEventArgs args)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)$"{args.Exception}");
		}

		private void Connect()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			try
			{
				ButtplugWebsocketConnector val = new ButtplugWebsocketConnector(new Uri("ws://localhost:12345"));
				buttplugClient.ConnectAsync((IButtplugClientConnector)(object)val, default(CancellationToken)).Wait();
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Exception occured during connection: {arg}");
			}
		}

		public void SendVibrations(float strength)
		{
			LogInfo($"Sending vibrations of strength {strength} to devices...");
			ButtplugClientDevice[] devices = buttplugClient.Devices;
			foreach (ButtplugClientDevice val in devices)
			{
				val.VibrateAsync((double)strength);
			}
		}

		public void LogInfo(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		public void LogDebug(string message)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)message);
		}
	}
	public class Patches
	{
		[HarmonyPatch(typeof(GameController), "Update")]
		[HarmonyPostfix]
		public static void VibrateOnToot(GameController __instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.notebuttonpressed && !__instance.outofbreath)
			{
				float y = __instance.pointer.transform.localPosition.y;
				BonerBuzzerPlugin.Instance.LogInfo($"Pointer Location: {y}");
				BonerBuzzerPlugin.Instance.SendVibrations((y + 180f) / 360f);
			}
			else
			{
				BonerBuzzerPlugin.Instance.SendVibrations(0f);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BonerBuzzer";

		public const string PLUGIN_NAME = "BonerBuzzer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}

plugins/Buttplug.Client.Connectors.WebsocketConnector.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Buttplug.Core;
using Buttplug.Core.Messages;
using vtortola.WebSockets;
using vtortola.WebSockets.Rfc6455;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Nonpolynomial Labs, LLC")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright Nonpolynomial Labs, LLC")]
[assembly: AssemblyDescription("Websocket Connection Capabilities for Buttplug Clients. (.Net Standard 2.0+)")]
[assembly: AssemblyFileVersion("3.0.1.0")]
[assembly: AssemblyInformationalVersion("3.0.1")]
[assembly: AssemblyProduct("Buttplug.Client.Connectors.WebsocketConnector")]
[assembly: AssemblyTitle("Buttplug.Client.Connectors.WebsocketConnector")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/buttplugio/buttplug-csharp")]
[assembly: AssemblyVersion("3.0.1.0")]
namespace Buttplug.Client.Connectors.WebsocketConnector;

public class ButtplugWebsocketConnector : ButtplugRemoteJSONConnector, IButtplugClientConnector
{
	private WebSocketClient _wsClient;

	private WebSocket _ws;

	private readonly SynchronizationContext _owningDispatcher = SynchronizationContext.Current ?? new SynchronizationContext();

	private readonly Uri _uri;

	private Channel<string> _channel = Channel.CreateBounded<string>(256);

	private Task _readTask;

	public bool Connected
	{
		get
		{
			WebSocket ws = _ws;
			if (ws == null)
			{
				return false;
			}
			return ws.IsConnected;
		}
	}

	public event EventHandler Disconnected;

	public ButtplugWebsocketConnector(Uri uri)
	{
		_uri = uri;
	}

	public async Task ConnectAsync(CancellationToken token = default(CancellationToken))
	{
		if (_ws != null)
		{
			throw new ButtplugHandshakeException("Websocket connector is already connected.", 0u, (Exception)null);
		}
		WebSocketListenerOptions val = new WebSocketListenerOptions
		{
			SendBufferSize = 8192,
			BufferManager = BufferManager.CreateBufferManager(819200L, 8192),
			PingTimeout = Timeout.InfiniteTimeSpan,
			PingMode = (PingMode)0
		};
		WebSocketFactoryCollectionExtensions.RegisterRfc6455(val.Standards, (Action<WebSocketFactoryRfc6455>)null);
		_wsClient = new WebSocketClient(val);
		try
		{
			_ws = await _wsClient.ConnectAsync(_uri, token).ConfigureAwait(continueOnCapturedContext: false);
		}
		catch (Exception ex)
		{
			throw new ButtplugClientConnectorException("Websocket Connection Exception! See Inner Exception", ex);
		}
		_readTask = Task.Run(async delegate
		{
			await RunClientLoop(token).ConfigureAwait(continueOnCapturedContext: false);
		}, token);
	}

	public async Task DisconnectAsync(CancellationToken token = default(CancellationToken))
	{
		try
		{
			WebSocket ws = _ws;
			if (ws != null && ws.IsConnected)
			{
				await _ws.CloseAsync().ConfigureAwait(continueOnCapturedContext: false);
			}
		}
		catch
		{
		}
		await _readTask.ConfigureAwait(continueOnCapturedContext: false);
	}

	public async Task<ButtplugMessage> SendAsync(ButtplugMessage msg, CancellationToken token)
	{
		var (item, msgPromise) = ((ButtplugRemoteJSONConnector)this).PrepareMessage(msg);
		await _channel.Writer.WriteAsync(item);
		return await msgPromise.ConfigureAwait(continueOnCapturedContext: false);
	}

	private async Task RunClientLoop(CancellationToken token)
	{
		_ = 4;
		try
		{
			UTF8Encoding utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false);
			Task<WebSocketMessageReadStream> readTask = _ws.ReadMessageAsync(token);
			Task<string> writeTask = _channel.Reader.ReadAsync(token).AsTask();
			while (_ws.IsConnected && !token.IsCancellationRequested)
			{
				await Task.WhenAny(new Task[2] { readTask, writeTask });
				if (readTask.IsCompleted)
				{
					WebSocketMessageReadStream val = await readTask.ConfigureAwait(continueOnCapturedContext: false);
					if (val == null)
					{
						break;
					}
					if ((int)val.MessageType == 1)
					{
						string text = string.Empty;
						using (StreamReader reader = new StreamReader((Stream)(object)val, utf8NoBom))
						{
							text = await reader.ReadToEndAsync();
						}
						((ButtplugRemoteJSONConnector)this).ReceiveMessages(text);
					}
					readTask = _ws.ReadMessageAsync(token);
					continue;
				}
				if (readTask.IsCanceled)
				{
					break;
				}
				if (writeTask.IsCompleted)
				{
					try
					{
						string text2 = await writeTask.ConfigureAwait(continueOnCapturedContext: false);
						if (text2 != null)
						{
							WebSocket ws = _ws;
							if (ws != null && ws.IsConnected)
							{
								await WebSocketStringExtensions.WriteStringAsync(_ws, text2, token).ConfigureAwait(continueOnCapturedContext: false);
								writeTask = _channel.Reader.ReadAsync(token).AsTask();
								continue;
							}
						}
					}
					catch (WebSocketException val2)
					{
						WebSocketException val3 = val2;
						throw new ButtplugClientConnectorException("Websocket Client Read Error", (Exception)(object)val3);
					}
					break;
				}
				if (writeTask.IsCanceled)
				{
					Console.WriteLine("Write cancelled");
				}
			}
		}
		catch (Exception)
		{
		}
		finally
		{
			_ws.CloseAsync().Dispose();
			_ws = null;
			_owningDispatcher.Send(delegate
			{
				((ButtplugRemoteJSONConnector)this).Dispose();
			}, null);
			_owningDispatcher.Send(delegate
			{
				this.Disconnected?.Invoke(this, EventArgs.Empty);
			}, null);
		}
	}

	void IButtplugClientConnector.add_MessageReceived(EventHandler<MessageReceivedEventArgs> value)
	{
		((ButtplugRemoteJSONConnector)this).MessageReceived += value;
	}

	void IButtplugClientConnector.remove_MessageReceived(EventHandler<MessageReceivedEventArgs> value)
	{
		((ButtplugRemoteJSONConnector)this).MessageReceived -= value;
	}

	void IButtplugClientConnector.add_InvalidMessageReceived(EventHandler<ButtplugExceptionEventArgs> value)
	{
		((ButtplugRemoteJSONConnector)this).InvalidMessageReceived += value;
	}

	void IButtplugClientConnector.remove_InvalidMessageReceived(EventHandler<ButtplugExceptionEventArgs> value)
	{
		((ButtplugRemoteJSONConnector)this).InvalidMessageReceived -= value;
	}
}

plugins/Buttplug.dll

Decompiled 2 years ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using Buttplug.Core;
using Buttplug.Core.Messages;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Buttplug.Test")]
[assembly: InternalsVisibleTo("Buttplug.Client.Test")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Nonpolynomial Labs, LLC")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright Nonpolynomial Labs, LLC")]
[assembly: AssemblyDescription("Buttplug Sex Toy Control Library. Contains Core (messages, errors, etc), and Client components. Server can be found in Buttplug.FFI.Server (.Net Standard 2.0+)")]
[assembly: AssemblyFileVersion("3.0.1.0")]
[assembly: AssemblyInformationalVersion("3.0.1")]
[assembly: AssemblyProduct("Buttplug")]
[assembly: AssemblyTitle("Buttplug")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/buttplugio/buttplug-csharp")]
[assembly: AssemblyVersion("3.0.1.0")]
namespace Buttplug.Core
{
	public static class ButtplugConsts
	{
		public const uint SystemMsgId = 0u;

		public const uint DefaultMsgId = 1u;

		public const uint CurrentSpecVersion = 3u;
	}
	public class ButtplugDeviceException : ButtplugException
	{
		public ButtplugDeviceException(string message, uint id = 0u, Exception inner = null)
			: base(message, Error.ErrorClass.ERROR_DEVICE, id, inner)
		{
		}
	}
	public class ButtplugException : Exception
	{
		public Error ButtplugErrorMessage { get; }

		public static ButtplugException FromError(Error msg)
		{
			return msg.ErrorCode switch
			{
				Error.ErrorClass.ERROR_DEVICE => new ButtplugDeviceException(msg.ErrorMessage, msg.Id), 
				Error.ErrorClass.ERROR_INIT => new ButtplugHandshakeException(msg.ErrorMessage, msg.Id), 
				Error.ErrorClass.ERROR_MSG => new ButtplugMessageException(msg.ErrorMessage, msg.Id), 
				Error.ErrorClass.ERROR_PING => new ButtplugPingException(msg.ErrorMessage, msg.Id), 
				Error.ErrorClass.ERROR_UNKNOWN => new ButtplugException(msg.ErrorMessage, msg.Id), 
				_ => new ButtplugException(msg.ErrorMessage, msg.Id), 
			};
		}

		public ButtplugException(string message, uint id = 0u, Exception inner = null)
			: this(message, Error.ErrorClass.ERROR_UNKNOWN, id, inner)
		{
		}

		public ButtplugException(string message, Error.ErrorClass err = Error.ErrorClass.ERROR_UNKNOWN, uint id = 0u, Exception inner = null)
			: base(message, inner)
		{
			ButtplugErrorMessage = new Error(message, err, id);
		}
	}
	public class ButtplugExceptionEventArgs : EventArgs
	{
		public ButtplugException Exception { get; }

		public ButtplugExceptionEventArgs(ButtplugException ex)
		{
			Exception = ex;
		}
	}
	public class ButtplugHandshakeException : ButtplugException
	{
		public ButtplugHandshakeException(string message, uint id = 0u, Exception inner = null)
			: base(message, Error.ErrorClass.ERROR_INIT, id, inner)
		{
		}
	}
	public class ButtplugJsonMessageParser
	{
		private readonly Dictionary<string, Type> _messageTypes;

		private readonly JsonSerializer _serializer;

		public ButtplugJsonMessageParser()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			_serializer = new JsonSerializer
			{
				MissingMemberHandling = (MissingMemberHandling)1
			};
			_messageTypes = new Dictionary<string, Type>();
			foreach (Type allMessageType in ButtplugUtils.GetAllMessageTypes())
			{
				_messageTypes.Add(allMessageType.Name, allMessageType);
			}
			if (!_messageTypes.Any())
			{
				throw new ButtplugMessageException("No message types available.");
			}
		}

		public IEnumerable<ButtplugMessage> Deserialize(string jsonMsg)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0031: Expected O, but got Unknown
			//IL_005b: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			JsonTextReader val = new JsonTextReader((TextReader)new StringReader(jsonMsg))
			{
				CloseInput = false,
				SupportMultipleContent = true
			};
			List<ButtplugMessage> list = new List<ButtplugMessage>();
			while (true)
			{
				try
				{
					if (!((JsonReader)val).Read())
					{
						return list;
					}
				}
				catch (JsonReaderException val2)
				{
					JsonReaderException val3 = val2;
					throw new ButtplugMessageException("Not valid JSON: " + jsonMsg + " - " + ((Exception)(object)val3).Message);
				}
				JArray val4;
				try
				{
					val4 = JArray.Load((JsonReader)(object)val);
				}
				catch (JsonReaderException val5)
				{
					JsonReaderException val6 = val5;
					throw new ButtplugMessageException("Not valid JSON: " + jsonMsg + " - " + ((Exception)(object)val6).Message);
				}
				foreach (JObject item in ((JToken)val4).Children<JObject>())
				{
					string name = item.Properties().First().Name;
					if (!_messageTypes.ContainsKey(name))
					{
						throw new ButtplugMessageException(name + " is not a valid message class");
					}
					list.Add(DeserializeAs(item, _messageTypes[name]));
				}
			}
		}

		private ButtplugMessage DeserializeAs(JObject obj, Type msgType)
		{
			//IL_00c0: Expected O, but got Unknown
			if (!msgType.IsSubclassOf(typeof(ButtplugMessage)))
			{
				throw new ButtplugMessageException("Type " + msgType.Name + " is not a subclass of ButtplugMessage");
			}
			if (msgType.Namespace != "Buttplug.Core.Messages")
			{
				throw new ButtplugMessageException("Type " + msgType.Name + " (" + msgType.Namespace + ") is not in the namespace of Buttplug.Core.Messages");
			}
			string name = ButtplugMessage.GetName(msgType);
			try
			{
				return (ButtplugMessage)((JToken)Extensions.Value<JObject>((IEnumerable<JToken>)obj[name])).ToObject(msgType, _serializer);
			}
			catch (InvalidCastException ex)
			{
				throw new ButtplugMessageException($"Could not create message for JSON {obj}: {ex.Message}");
			}
			catch (JsonSerializationException val)
			{
				JsonSerializationException val2 = val;
				throw new ButtplugMessageException($"Could not create message for JSON {obj}: {((Exception)(object)val2).Message}");
			}
		}

		public string Serialize(ButtplugMessage msg)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (msg.GetType().Namespace != "Buttplug.Core.Messages")
			{
				throw new ButtplugMessageException("Type " + msg.GetType().Name + " (" + msg.GetType().Namespace + ") is not in the namespace of Buttplug.Core.Messages");
			}
			JObject val = ButtplugMessageToJObject(msg);
			if (val == null)
			{
				throw new ButtplugMessageException("Message cannot be converted to JSON.", msg.Id);
			}
			JArray val2 = new JArray();
			val2.Add((JToken)(object)val);
			return ((JToken)val2).ToString((Formatting)0, Array.Empty<JsonConverter>());
		}

		public string Serialize(IEnumerable<ButtplugMessage> msgs)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			JArray val = new JArray();
			foreach (ButtplugMessage msg in msgs)
			{
				JObject val2 = ButtplugMessageToJObject(msg);
				if (val2 != null)
				{
					val.Add((JToken)(object)val2);
				}
			}
			if (!((IEnumerable<JToken>)val).Any())
			{
				throw new ButtplugMessageException("No messages serialized.");
			}
			return ((JToken)val).ToString((Formatting)0, Array.Empty<JsonConverter>());
		}

		private JObject ButtplugMessageToJObject(ButtplugMessage msg)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return new JObject((object)new JProperty(msg.Name, (object)JObject.FromObject((object)msg)));
		}
	}
	public class ButtplugMessageException : ButtplugException
	{
		public ButtplugMessageException(string message, uint id = 0u, Exception inner = null)
			: base(message, Error.ErrorClass.ERROR_MSG, id, inner)
		{
		}
	}
	public class ButtplugPingException : ButtplugException
	{
		public ButtplugPingException(string message, uint id = 0u, Exception inner = null)
			: base(message, Error.ErrorClass.ERROR_PING, id, inner)
		{
		}
	}
	public static class ButtplugUtils
	{
		public static IEnumerable<Type> GetAllMessageTypes()
		{
			IEnumerable<Type> enumerable;
			try
			{
				enumerable = Assembly.GetAssembly(typeof(ButtplugMessage))?.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				enumerable = ex.Types;
			}
			return (enumerable ?? throw new InvalidOperationException()).Where((Type type) => type != null && type.IsClass && type.IsSubclassOf(typeof(ButtplugMessage)) && type != typeof(ButtplugDeviceMessage));
		}

		[DebuggerStepThrough]
		public static void ArgumentNotNull(object argument, string argumentName)
		{
			if (argument == null)
			{
				throw new ArgumentNullException(argumentName);
			}
		}

		public static Type GetMessageType(string messageName)
		{
			return Type.GetType("Buttplug.Core.Messages." + messageName);
		}
	}
}
namespace Buttplug.Core.Messages
{
	public class ButtplugDeviceMessage : ButtplugMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint DeviceIndex { get; set; }

		public ButtplugDeviceMessage(uint id = 1u, uint deviceIndex = uint.MaxValue)
			: base(id)
		{
			DeviceIndex = deviceIndex;
		}
	}
	public abstract class ButtplugMessage
	{
		private static readonly Dictionary<Type, ButtplugMessageMetadata> _metadataCache = new Dictionary<Type, ButtplugMessageMetadata>();

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint Id { get; set; }

		[JsonIgnore]
		public string Name => GetName(GetType());

		protected ButtplugMessage(uint id)
		{
			Id = id;
		}

		private static T GetMessageAttribute<T>(Type msgType, Func<ButtplugMessageMetadata, T> func)
		{
			ButtplugUtils.ArgumentNotNull(msgType, "msgType");
			ButtplugUtils.ArgumentNotNull(func, "func");
			if (!msgType.IsSubclassOf(typeof(ButtplugMessage)))
			{
				throw new ArgumentException("Argument " + msgType.Name + " must be a subclass of ButtplugMessage");
			}
			if (_metadataCache.ContainsKey(msgType))
			{
				return func(_metadataCache[msgType]);
			}
			Attribute[] customAttributes = Attribute.GetCustomAttributes(msgType);
			for (int i = 0; i < customAttributes.Length; i++)
			{
				if (customAttributes[i] is ButtplugMessageMetadata buttplugMessageMetadata)
				{
					_metadataCache[msgType] = buttplugMessageMetadata;
					return func(buttplugMessageMetadata);
				}
			}
			throw new ArgumentException($"Type {msgType} does not have ButtplugMessageMetadata Attributes");
		}

		public static string GetName(Type msgType)
		{
			return GetMessageAttribute(msgType, (ButtplugMessageMetadata md) => md.Name);
		}
	}
	public interface IButtplugMessageOutgoingOnly
	{
	}
	public interface IButtplugDeviceInfoMessage
	{
		string DeviceName { get; }

		uint DeviceIndex { get; }

		DeviceMessageAttributes DeviceMessages { get; }

		string DeviceDisplayName { get; }

		uint DeviceMessageTimingGap { get; }
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class ButtplugMessageMetadata : Attribute
	{
		public string Name { get; }

		public ButtplugMessageMetadata(string name)
		{
			Name = name;
		}
	}
	[JsonConverter(typeof(StringEnumConverter))]
	public enum ActuatorType
	{
		[EnumMember(Value = "Unknown")]
		Unknown,
		[EnumMember(Value = "Vibrate")]
		Vibrate,
		[EnumMember(Value = "Rotate")]
		Rotate,
		[EnumMember(Value = "Oscillate")]
		Oscillate,
		[EnumMember(Value = "Constrict")]
		Constrict,
		[EnumMember(Value = "Inflate")]
		Inflate,
		[EnumMember(Value = "Position")]
		Position
	}
	[JsonConverter(typeof(StringEnumConverter))]
	public enum SensorType
	{
		[EnumMember(Value = "Unknown")]
		Unknown,
		[EnumMember(Value = "Battery")]
		Battery,
		[EnumMember(Value = "RSSI")]
		RSSI,
		[EnumMember(Value = "Button")]
		Button,
		[EnumMember(Value = "Pressure")]
		Pressure
	}
	public class GenericDeviceMessageAttributes
	{
		[JsonIgnore]
		internal uint _index;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly string FeatureDescriptor;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		[JsonConverter(typeof(StringEnumConverter))]
		public readonly ActuatorType ActuatorType;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint StepCount;

		[JsonIgnore]
		public uint Index => _index;
	}
	public class SensorDeviceMessageAttributes
	{
		[JsonIgnore]
		internal uint _index;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly string FeatureDescriptor;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		[JsonConverter(typeof(StringEnumConverter))]
		public readonly SensorType SensorType;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint[][] SensorRange;

		[JsonIgnore]
		public uint Index => _index;
	}
	public class RawDeviceMessageAttributes
	{
		public readonly string[] Endpoints;
	}
	public class NullDeviceMessageAttributes
	{
	}
	public class DeviceMessageAttributes
	{
		public GenericDeviceMessageAttributes[] ScalarCmd;

		public GenericDeviceMessageAttributes[] RotateCmd;

		public GenericDeviceMessageAttributes[] LinearCmd;

		public SensorDeviceMessageAttributes[] SensorReadCmd;

		public SensorDeviceMessageAttributes[] SensorSubscribeCmd;

		public readonly RawDeviceMessageAttributes[] RawReadCmd;

		public readonly RawDeviceMessageAttributes[] RawWriteCmd;

		public readonly RawDeviceMessageAttributes[] RawSubscribeCmd;

		public readonly NullDeviceMessageAttributes StopDeviceCmd;

		[OnDeserialized]
		internal void OnDeserializedMethod(StreamingContext context)
		{
			ScalarCmd?.Select((GenericDeviceMessageAttributes x, int i) => (x, i)).ToList().ForEach(delegate((GenericDeviceMessageAttributes x, int i) x)
			{
				x.x._index = (uint)x.i;
			});
			RotateCmd?.Select((GenericDeviceMessageAttributes x, int i) => (x, i)).ToList().ForEach(delegate((GenericDeviceMessageAttributes x, int i) x)
			{
				x.x._index = (uint)x.i;
			});
			LinearCmd?.Select((GenericDeviceMessageAttributes x, int i) => (x, i)).ToList().ForEach(delegate((GenericDeviceMessageAttributes x, int i) x)
			{
				x.x._index = (uint)x.i;
			});
			SensorReadCmd?.Select((SensorDeviceMessageAttributes x, int i) => (x, i)).ToList().ForEach(delegate((SensorDeviceMessageAttributes x, int i) x)
			{
				x.x._index = (uint)x.i;
			});
			SensorSubscribeCmd?.Select((SensorDeviceMessageAttributes x, int i) => (x, i)).ToList().ForEach(delegate((SensorDeviceMessageAttributes x, int i) x)
			{
				x.x._index = (uint)x.i;
			});
		}
	}
	public class MessageReceivedEventArgs : EventArgs
	{
		public ButtplugMessage Message { get; }

		public MessageReceivedEventArgs(ButtplugMessage message)
		{
			Message = message;
		}
	}
	[ButtplugMessageMetadata("Ok")]
	public class Ok : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		public Ok(uint id)
			: base(id)
		{
		}
	}
	[ButtplugMessageMetadata("Test")]
	public class Test : ButtplugMessage
	{
		private string _testStringImpl;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public string TestString
		{
			get
			{
				return _testStringImpl;
			}
			set
			{
				if (value == "Error")
				{
					throw new ArgumentException("Got an Error Message");
				}
				_testStringImpl = value;
			}
		}

		public Test(string str, uint id = 1u)
			: base(id)
		{
			TestString = str;
		}
	}
	[ButtplugMessageMetadata("Error")]
	public class Error : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		public enum ErrorClass
		{
			ERROR_UNKNOWN,
			ERROR_INIT,
			ERROR_PING,
			ERROR_MSG,
			ERROR_DEVICE
		}

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public ErrorClass ErrorCode;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public string ErrorMessage;

		public Error(string errorMessage, ErrorClass errorCode, uint id)
			: base(id)
		{
			ErrorMessage = errorMessage;
			ErrorCode = errorCode;
		}
	}
	public class MessageAttributes : IEquatable<MessageAttributes>
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint? FeatureCount;

		public MessageAttributes()
		{
		}

		public MessageAttributes(uint featureCount)
		{
			FeatureCount = featureCount;
		}

		public bool Equals(MessageAttributes attrs)
		{
			return FeatureCount == attrs.FeatureCount;
		}
	}
	public class DeviceMessageInfo : IButtplugDeviceInfoMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly string DeviceName;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint DeviceIndex;

		public readonly string DeviceDisplayName;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint DeviceMessageTimingGap;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly DeviceMessageAttributes DeviceMessages;

		string IButtplugDeviceInfoMessage.DeviceName => DeviceName;

		uint IButtplugDeviceInfoMessage.DeviceIndex => DeviceIndex;

		DeviceMessageAttributes IButtplugDeviceInfoMessage.DeviceMessages => DeviceMessages;

		string IButtplugDeviceInfoMessage.DeviceDisplayName => DeviceDisplayName;

		uint IButtplugDeviceInfoMessage.DeviceMessageTimingGap => DeviceMessageTimingGap;

		public DeviceMessageInfo(uint index, string name, DeviceMessageAttributes messages)
		{
			DeviceName = name;
			DeviceIndex = index;
			DeviceMessages = messages;
		}
	}
	[ButtplugMessageMetadata("DeviceList")]
	public class DeviceList : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly DeviceMessageInfo[] Devices = new DeviceMessageInfo[0];

		public DeviceList(DeviceMessageInfo[] deviceList, uint id)
			: base(id)
		{
			Devices = deviceList;
		}

		internal DeviceList()
			: base(0u)
		{
		}
	}
	[ButtplugMessageMetadata("DeviceAdded")]
	public class DeviceAdded : ButtplugDeviceMessage, IButtplugMessageOutgoingOnly, IButtplugDeviceInfoMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public string DeviceName;

		public readonly string DeviceDisplayName;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint DeviceMessageTimingGap;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly DeviceMessageAttributes DeviceMessages;

		string IButtplugDeviceInfoMessage.DeviceName => DeviceName;

		uint IButtplugDeviceInfoMessage.DeviceIndex => base.DeviceIndex;

		DeviceMessageAttributes IButtplugDeviceInfoMessage.DeviceMessages => DeviceMessages;

		string IButtplugDeviceInfoMessage.DeviceDisplayName => DeviceDisplayName;

		uint IButtplugDeviceInfoMessage.DeviceMessageTimingGap => DeviceMessageTimingGap;

		public DeviceAdded(uint index, string name, DeviceMessageAttributes messages)
			: base(0u, index)
		{
			DeviceName = name;
			DeviceMessages = messages;
		}

		internal DeviceAdded()
			: base(0u)
		{
		}
	}
	[ButtplugMessageMetadata("DeviceRemoved")]
	public class DeviceRemoved : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint DeviceIndex;

		public DeviceRemoved(uint index)
			: base(0u)
		{
			DeviceIndex = index;
		}
	}
	[ButtplugMessageMetadata("RequestDeviceList")]
	public class RequestDeviceList : ButtplugMessage
	{
		public RequestDeviceList(uint id = 1u)
			: base(id)
		{
		}
	}
	[ButtplugMessageMetadata("StartScanning")]
	public class StartScanning : ButtplugMessage
	{
		public StartScanning(uint id = 1u)
			: base(id)
		{
		}
	}
	[ButtplugMessageMetadata("StopScanning")]
	public class StopScanning : ButtplugMessage
	{
		public StopScanning(uint id = 1u)
			: base(id)
		{
		}
	}
	[ButtplugMessageMetadata("ScanningFinished")]
	public class ScanningFinished : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		public ScanningFinished()
			: base(0u)
		{
		}
	}
	[ButtplugMessageMetadata("RequestServerInfo")]
	public class RequestServerInfo : ButtplugMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public string ClientName;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint MessageVersion;

		public RequestServerInfo(string clientName, uint id = 1u, uint schemversion = 3u)
			: base(id)
		{
			ClientName = clientName;
			MessageVersion = schemversion;
		}
	}
	[ButtplugMessageMetadata("ServerInfo")]
	public class ServerInfo : ButtplugMessage, IButtplugMessageOutgoingOnly
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint MessageVersion;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint MaxPingTime;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public string ServerName;

		public ServerInfo(string serverName, uint messageVersion, uint maxPingTime, uint id = 1u)
			: base(id)
		{
			ServerName = serverName;
			MessageVersion = messageVersion;
			MaxPingTime = maxPingTime;
		}
	}
	[ButtplugMessageMetadata("Ping")]
	public class Ping : ButtplugMessage
	{
		public Ping(uint id = 1u)
			: base(id)
		{
		}
	}
	public class GenericMessageSubcommand
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint Index;

		protected GenericMessageSubcommand(uint index)
		{
			Index = index;
		}
	}
	[ButtplugMessageMetadata("ScalarCmd")]
	public class ScalarCmd : ButtplugDeviceMessage
	{
		public class ScalarSubcommand : GenericMessageSubcommand
		{
			private double _scalarImpl;

			public readonly ActuatorType ActuatorType;

			[JsonProperty(/*Could not decode attribute arguments.*/)]
			public double Scalar
			{
				get
				{
					return _scalarImpl;
				}
				set
				{
					if (value < 0.0)
					{
						throw new ArgumentException("ScalarCmd value cannot be less than 0!");
					}
					if (value > 1.0)
					{
						throw new ArgumentException("ScalarCmd value cannot be greater than 1!");
					}
					_scalarImpl = value;
				}
			}

			public ScalarSubcommand(uint index, double scalar, ActuatorType actuatorType)
				: base(index)
			{
				Scalar = scalar;
				ActuatorType = actuatorType;
			}
		}

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public List<ScalarSubcommand> Scalars;

		[JsonConstructor]
		public ScalarCmd(uint deviceIndex, List<ScalarSubcommand> scalars, uint id = 1u)
			: base(id, deviceIndex)
		{
			Scalars = scalars;
		}

		public ScalarCmd(List<ScalarSubcommand> scalars)
			: this(uint.MaxValue, scalars)
		{
		}
	}
	[ButtplugMessageMetadata("RotateCmd")]
	public class RotateCmd : ButtplugDeviceMessage
	{
		public class RotateSubcommand : GenericMessageSubcommand
		{
			private double _speedImpl;

			[JsonProperty(/*Could not decode attribute arguments.*/)]
			public bool Clockwise;

			[JsonProperty(/*Could not decode attribute arguments.*/)]
			public double Speed
			{
				get
				{
					return _speedImpl;
				}
				set
				{
					if (value < 0.0)
					{
						throw new ArgumentException("RotateCmd Speed cannot be less than 0!");
					}
					if (value > 1.0)
					{
						throw new ArgumentException("RotateCmd Speed cannot be greater than 1!");
					}
					_speedImpl = value;
				}
			}

			public RotateSubcommand(uint index, double speed, bool clockwise)
				: base(index)
			{
				Speed = speed;
				Clockwise = clockwise;
			}
		}

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public List<RotateSubcommand> Rotations;

		public static RotateCmd Create(double speed, bool clockwise, uint cmdCount)
		{
			return Create(uint.MaxValue, 1u, Enumerable.Repeat((speed, clockwise), (int)cmdCount));
		}

		public static RotateCmd Create(IEnumerable<(double speed, bool clockwise)> cmds)
		{
			return Create(uint.MaxValue, 1u, cmds);
		}

		public static RotateCmd Create(uint deviceIndex, uint msgId, double speed, bool clockwise, uint cmdCount)
		{
			return Create(deviceIndex, msgId, Enumerable.Repeat((speed, clockwise), (int)cmdCount));
		}

		public static RotateCmd Create(uint deviceIndex, uint msgId, IEnumerable<(double speed, bool clockwise)> cmds)
		{
			List<RotateSubcommand> list = new List<RotateSubcommand>(cmds.Count());
			uint num = 0u;
			foreach (var (speed, clockwise) in cmds)
			{
				list.Add(new RotateSubcommand(num, speed, clockwise));
				num++;
			}
			return new RotateCmd(deviceIndex, list, msgId);
		}

		[JsonConstructor]
		public RotateCmd(uint deviceIndex, List<RotateSubcommand> rotations, uint id = 1u)
			: base(id, deviceIndex)
		{
			Rotations = rotations;
		}

		public RotateCmd(List<RotateSubcommand> rotations)
			: this(uint.MaxValue, rotations)
		{
		}
	}
	[ButtplugMessageMetadata("LinearCmd")]
	public class LinearCmd : ButtplugDeviceMessage
	{
		public class VectorSubcommand : GenericMessageSubcommand
		{
			private double _positionImpl;

			[JsonProperty(/*Could not decode attribute arguments.*/)]
			public uint Duration;

			[JsonProperty(/*Could not decode attribute arguments.*/)]
			public double Position
			{
				get
				{
					return _positionImpl;
				}
				set
				{
					if (value < 0.0)
					{
						throw new ArgumentException("LinearCmd Speed cannot be less than 0!");
					}
					if (value > 1.0)
					{
						throw new ArgumentException("LinearCmd Speed cannot be greater than 1!");
					}
					_positionImpl = value;
				}
			}

			public VectorSubcommand(uint index, uint duration, double position)
				: base(index)
			{
				Duration = duration;
				Position = position;
			}
		}

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public List<VectorSubcommand> Vectors;

		public static LinearCmd Create(uint duration, double position, uint cmdCount)
		{
			return Create(uint.MaxValue, 1u, Enumerable.Repeat((duration, position), (int)cmdCount));
		}

		public static LinearCmd Create(uint deviceIndex, uint msgId, uint duration, double position, uint cmdCount)
		{
			return Create(deviceIndex, msgId, Enumerable.Repeat((duration, position), (int)cmdCount));
		}

		public static LinearCmd Create(IEnumerable<(uint duration, double position)> cmds)
		{
			return Create(uint.MaxValue, 1u, cmds);
		}

		public static LinearCmd Create(uint deviceIndex, uint msgId, IEnumerable<(uint duration, double position)> cmds)
		{
			List<VectorSubcommand> list = new List<VectorSubcommand>(cmds.Count());
			uint num = 0u;
			foreach (var (duration, position) in cmds)
			{
				list.Add(new VectorSubcommand(num, duration, position));
				num++;
			}
			return new LinearCmd(deviceIndex, list, msgId);
		}

		[JsonConstructor]
		public LinearCmd(uint deviceIndex, List<VectorSubcommand> vectors, uint id = 1u)
			: base(id, deviceIndex)
		{
			Vectors = vectors;
		}

		public LinearCmd(List<VectorSubcommand> vectors)
			: this(uint.MaxValue, vectors)
		{
		}
	}
	[ButtplugMessageMetadata("StopDeviceCmd")]
	public class StopDeviceCmd : ButtplugDeviceMessage
	{
		public StopDeviceCmd(uint deviceIndex = uint.MaxValue, uint id = 1u)
			: base(id, deviceIndex)
		{
		}
	}
	[ButtplugMessageMetadata("StopAllDevices")]
	public class StopAllDevices : ButtplugMessage
	{
		public StopAllDevices(uint id = 1u)
			: base(id)
		{
		}
	}
	[ButtplugMessageMetadata("SensorReadCmd")]
	public class SensorReadCmd : ButtplugDeviceMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public uint SensorIndex;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public SensorType SensorType;

		[JsonConstructor]
		public SensorReadCmd(uint deviceIndex, uint sensorIndex, SensorType sensorType, uint id = 1u)
			: base(id, deviceIndex)
		{
			SensorIndex = sensorIndex;
			SensorType = sensorType;
		}

		public SensorReadCmd(uint sensorIndex, SensorType sensorType)
			: this(uint.MaxValue, sensorIndex, sensorType)
		{
		}
	}
	[ButtplugMessageMetadata("SensorReading")]
	public class SensorReading : ButtplugDeviceMessage
	{
		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly uint SensorIndex;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly SensorType SensorType;

		[JsonProperty(/*Could not decode attribute arguments.*/)]
		public readonly List<int> data;
	}
}
namespace Buttplug.Client
{
	public class ButtplugClient : IDisposable
	{
		protected Timer _pingTimer;

		internal ButtplugClientMessageHandler _handler;

		private readonly ConcurrentDictionary<uint, ButtplugClientDevice> _devices = new ConcurrentDictionary<uint, ButtplugClientDevice>();

		private IButtplugClientConnector _connector;

		public string Name { get; }

		public ButtplugClientDevice[] Devices => _devices.Values.ToArray();

		public bool Connected => _connector?.Connected ?? false;

		public event EventHandler<DeviceAddedEventArgs> DeviceAdded;

		public event EventHandler<DeviceRemovedEventArgs> DeviceRemoved;

		public event EventHandler<ButtplugExceptionEventArgs> ErrorReceived;

		public event EventHandler ScanningFinished;

		public event EventHandler PingTimeout;

		public event EventHandler ServerDisconnect;

		public ButtplugClient(string clientName)
		{
			Name = clientName;
		}

		public async Task ConnectAsync(IButtplugClientConnector connector, CancellationToken token = default(CancellationToken))
		{
			if (Connected)
			{
				throw new ButtplugHandshakeException("Client already connected to a server.");
			}
			ButtplugUtils.ArgumentNotNull(connector, "connector");
			_connector = connector;
			_connector.Disconnected += delegate(object obj, EventArgs eventArgs)
			{
				this.ServerDisconnect?.Invoke(obj, eventArgs);
			};
			_connector.InvalidMessageReceived += ConnectorErrorHandler;
			_connector.MessageReceived += MessageReceivedHandler;
			_devices.Clear();
			_handler = new ButtplugClientMessageHandler(connector);
			await _connector.ConnectAsync(token).ConfigureAwait(continueOnCapturedContext: false);
			ButtplugMessage res = await _handler.SendMessageAsync(new RequestServerInfo(Name), token).ConfigureAwait(continueOnCapturedContext: false);
			if (!(res is ServerInfo si))
			{
				if (res is Error e)
				{
					await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
					throw ButtplugException.FromError(e);
				}
				await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
				throw new ButtplugHandshakeException("Unrecognized message " + res.Name + " during handshake", res.Id);
			}
			if (si.MaxPingTime != 0)
			{
				_pingTimer?.Dispose();
				_pingTimer = new Timer(OnPingTimer, null, 0, Convert.ToInt32(Math.Round((double)si.MaxPingTime / 2.0, 0)));
			}
			if (si.MessageVersion < 3)
			{
				await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
				throw new ButtplugHandshakeException($"Buttplug Server's schema version ({si.MessageVersion}) is less than the client's ({3u}). A newer server is required.", res.Id);
			}
			ButtplugMessage resp = await _handler.SendMessageAsync(new RequestDeviceList()).ConfigureAwait(continueOnCapturedContext: false);
			if (resp is DeviceList deviceList)
			{
				DeviceMessageInfo[] devices = deviceList.Devices;
				foreach (DeviceMessageInfo deviceMessageInfo in devices)
				{
					if (!_devices.ContainsKey(deviceMessageInfo.DeviceIndex))
					{
						ButtplugClientDevice buttplugClientDevice = new ButtplugClientDevice(_handler, deviceMessageInfo);
						_devices[deviceMessageInfo.DeviceIndex] = buttplugClientDevice;
						this.DeviceAdded?.Invoke(this, new DeviceAddedEventArgs(buttplugClientDevice));
					}
				}
				return;
			}
			await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
			if (resp is Error msg)
			{
				throw ButtplugException.FromError(msg);
			}
			throw new ButtplugHandshakeException("Received unknown response to DeviceList handshake query");
		}

		public async Task DisconnectAsync()
		{
			if (Connected)
			{
				_connector.MessageReceived -= MessageReceivedHandler;
				await _connector.DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
				this.ServerDisconnect?.Invoke(this, EventArgs.Empty);
			}
		}

		public async Task StartScanningAsync(CancellationToken token = default(CancellationToken))
		{
			await _handler.SendMessageExpectOk(new StartScanning(), token).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task StopScanningAsync(CancellationToken token = default(CancellationToken))
		{
			await _handler.SendMessageExpectOk(new StopScanning(), token).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task StopAllDevicesAsync(CancellationToken token = default(CancellationToken))
		{
			await _handler.SendMessageExpectOk(new StopAllDevices(), token).ConfigureAwait(continueOnCapturedContext: false);
		}

		private void ConnectorErrorHandler(object sender, ButtplugExceptionEventArgs exception)
		{
			this.ErrorReceived?.Invoke(this, exception);
		}

		private async void MessageReceivedHandler(object sender, MessageReceivedEventArgs args)
		{
			ButtplugMessage message = args.Message;
			if (!(message is DeviceAdded deviceAdded))
			{
				ButtplugClientDevice value;
				if (!(message is DeviceRemoved deviceRemoved))
				{
					if (!(message is ScanningFinished))
					{
						if (message is Error error)
						{
							this.ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(ButtplugException.FromError(error)));
							if (error.ErrorCode == Error.ErrorClass.ERROR_PING)
							{
								this.PingTimeout?.Invoke(this, EventArgs.Empty);
								await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
							}
						}
						else
						{
							this.ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(new ButtplugMessageException($"Got unhandled message: {message}", message.Id)));
						}
					}
					else
					{
						this.ScanningFinished?.Invoke(this, EventArgs.Empty);
					}
				}
				else if (!_devices.ContainsKey(deviceRemoved.DeviceIndex))
				{
					this.ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(new ButtplugDeviceException("Got device removed message for unknown device.", message.Id)));
				}
				else if (_devices.TryRemove(deviceRemoved.DeviceIndex, out value))
				{
					this.DeviceRemoved?.Invoke(this, new DeviceRemovedEventArgs(value));
				}
			}
			else
			{
				ButtplugClientDevice dev = new ButtplugClientDevice(_handler, deviceAdded);
				_devices.AddOrUpdate(deviceAdded.DeviceIndex, dev, (uint u, ButtplugClientDevice device) => dev);
				this.DeviceAdded?.Invoke(this, new DeviceAddedEventArgs(dev));
			}
		}

		private async void OnPingTimer(object state)
		{
			try
			{
				await _handler.SendMessageExpectOk(new Ping()).ConfigureAwait(continueOnCapturedContext: false);
			}
			catch (Exception inner)
			{
				this.ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(new ButtplugPingException("Exception thrown during ping update", 0u, inner)));
				await DisconnectAsync().ConfigureAwait(continueOnCapturedContext: false);
			}
		}

		protected virtual void Dispose(bool disposing)
		{
			DisconnectAsync().GetAwaiter().GetResult();
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	public class ButtplugClientConnectorException : ButtplugException
	{
		public ButtplugClientConnectorException(string message, Exception inner = null)
			: base(message, Error.ErrorClass.ERROR_UNKNOWN, 0u, inner)
		{
		}
	}
	public class ButtplugClientDevice
	{
		private readonly ButtplugClientMessageHandler _handler;

		public uint Index { get; }

		public string Name { get; }

		public string DisplayName { get; }

		public uint MessageTimingGap { get; }

		public DeviceMessageAttributes MessageAttributes { get; }

		public List<GenericDeviceMessageAttributes> VibrateAttributes => GenericAcutatorAttributes(ActuatorType.Vibrate);

		public List<GenericDeviceMessageAttributes> OscillateAttributes => GenericAcutatorAttributes(ActuatorType.Oscillate);

		public List<GenericDeviceMessageAttributes> RotateAttributes
		{
			get
			{
				if (MessageAttributes.RotateCmd != null)
				{
					return MessageAttributes.RotateCmd.ToList();
				}
				return Enumerable.Empty<GenericDeviceMessageAttributes>().ToList();
			}
		}

		public List<GenericDeviceMessageAttributes> LinearAttributes
		{
			get
			{
				if (MessageAttributes.LinearCmd != null)
				{
					return MessageAttributes.LinearCmd.ToList();
				}
				return Enumerable.Empty<GenericDeviceMessageAttributes>().ToList();
			}
		}

		public bool HasBattery => SensorReadAttributes(SensorType.Battery).Any();

		internal ButtplugClientDevice(ButtplugClientMessageHandler handler, IButtplugDeviceInfoMessage devInfo)
			: this(handler, devInfo.DeviceIndex, devInfo.DeviceName, devInfo.DeviceMessages, devInfo.DeviceDisplayName, devInfo.DeviceMessageTimingGap)
		{
			ButtplugUtils.ArgumentNotNull(devInfo, "devInfo");
		}

		internal ButtplugClientDevice(ButtplugClientMessageHandler handler, uint index, string name, DeviceMessageAttributes messages, string displayName, uint messageTimingGap)
		{
			ButtplugUtils.ArgumentNotNull(handler, "handler");
			_handler = handler;
			Index = index;
			Name = name;
			MessageAttributes = messages;
			DisplayName = displayName;
			MessageTimingGap = messageTimingGap;
		}

		public List<GenericDeviceMessageAttributes> GenericAcutatorAttributes(ActuatorType actuator)
		{
			if (MessageAttributes.ScalarCmd != null)
			{
				return MessageAttributes.ScalarCmd.Where((GenericDeviceMessageAttributes x) => x.ActuatorType == actuator).ToList();
			}
			return Enumerable.Empty<GenericDeviceMessageAttributes>().ToList();
		}

		public async Task ScalarAsync(ScalarCmd.ScalarSubcommand command)
		{
			List<ScalarCmd.ScalarSubcommand> scalars = new List<ScalarCmd.ScalarSubcommand>();
			GenericAcutatorAttributes(command.ActuatorType).ForEach(delegate(GenericDeviceMessageAttributes x)
			{
				scalars.Add(new ScalarCmd.ScalarSubcommand(x.Index, command.Scalar, command.ActuatorType));
			});
			if (!scalars.Any())
			{
				throw new ButtplugDeviceException("Scalar command for device " + Name + " did not generate any commands. Are you sure the device supports the ActuatorType sent?");
			}
			await _handler.SendMessageExpectOk(new ScalarCmd(Index, scalars)).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task ScalarAsync(List<ScalarCmd.ScalarSubcommand> command)
		{
			if (!command.Any())
			{
				throw new ArgumentException("Command List for ScalarAsync must have at least 1 command.");
			}
			await _handler.SendMessageExpectOk(new ScalarCmd(Index, command)).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task VibrateAsync(double speed)
		{
			await ScalarAsync(new ScalarCmd.ScalarSubcommand(uint.MaxValue, speed, ActuatorType.Vibrate));
		}

		public async Task VibrateAsync(IEnumerable<double> cmds)
		{
			List<GenericDeviceMessageAttributes> vibrateAttributes = VibrateAttributes;
			if (cmds.Count() > vibrateAttributes.Count())
			{
				throw new ButtplugDeviceException($"Device {Name} only has {vibrateAttributes.Count()} vibrators, but {cmds.Count()} commands given.");
			}
			await ScalarAsync(vibrateAttributes.Select((GenericDeviceMessageAttributes x, int i) => new ScalarCmd.ScalarSubcommand(x.Index, cmds.ElementAt(i), ActuatorType.Vibrate)).ToList()).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task VibrateAsync(IEnumerable<(uint, double)> cmds)
		{
			await ScalarAsync(cmds.Select(((uint, double) x) => new ScalarCmd.ScalarSubcommand(x.Item1, x.Item2, ActuatorType.Vibrate)).ToList()).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task OscillateAsync(double speed)
		{
			await ScalarAsync(new ScalarCmd.ScalarSubcommand(uint.MaxValue, speed, ActuatorType.Oscillate));
		}

		public async Task OscillateAsync(IEnumerable<double> cmds)
		{
			List<GenericDeviceMessageAttributes> oscillateAttributes = OscillateAttributes;
			if (cmds.Count() > oscillateAttributes.Count())
			{
				throw new ButtplugDeviceException($"Device {Name} only has {oscillateAttributes.Count()} vibrators, but {cmds.Count()} commands given.");
			}
			await ScalarAsync(oscillateAttributes.Select((GenericDeviceMessageAttributes x, int i) => new ScalarCmd.ScalarSubcommand(x.Index, cmds.ElementAt(i), ActuatorType.Oscillate)).ToList()).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task OscillateAsync(IEnumerable<(uint, double)> cmds)
		{
			await ScalarAsync(cmds.Select(((uint, double) x) => new ScalarCmd.ScalarSubcommand(x.Item1, x.Item2, ActuatorType.Oscillate)).ToList()).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task RotateAsync(double speed, bool clockwise)
		{
			if (!RotateAttributes.Any())
			{
				throw new ButtplugDeviceException("Device " + Name + " does not support rotation");
			}
			RotateCmd rotateCmd = RotateCmd.Create(speed, clockwise, (uint)RotateAttributes.Count);
			rotateCmd.DeviceIndex = Index;
			await _handler.SendMessageExpectOk(rotateCmd).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task RotateAsync(IEnumerable<(double, bool)> cmds)
		{
			if (!RotateAttributes.Any())
			{
				throw new ButtplugDeviceException("Device " + Name + " does not support rotation");
			}
			RotateCmd rotateCmd = RotateCmd.Create(cmds);
			rotateCmd.DeviceIndex = Index;
			await _handler.SendMessageExpectOk(rotateCmd).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task LinearAsync(uint duration, double position)
		{
			if (!LinearAttributes.Any())
			{
				throw new ButtplugDeviceException("Device " + Name + " does not support linear position");
			}
			LinearCmd linearCmd = LinearCmd.Create(duration, position, (uint)LinearAttributes.Count);
			linearCmd.DeviceIndex = Index;
			await _handler.SendMessageExpectOk(linearCmd).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task LinearAsync(IEnumerable<(uint, double)> cmds)
		{
			if (!LinearAttributes.Any())
			{
				throw new ButtplugDeviceException("Device " + Name + " does not support linear position");
			}
			LinearCmd linearCmd = LinearCmd.Create(cmds);
			linearCmd.DeviceIndex = Index;
			await _handler.SendMessageExpectOk(linearCmd).ConfigureAwait(continueOnCapturedContext: false);
		}

		public List<SensorDeviceMessageAttributes> SensorReadAttributes(SensorType sensor)
		{
			if (MessageAttributes.SensorReadCmd != null)
			{
				return MessageAttributes.SensorReadCmd.Where((SensorDeviceMessageAttributes x) => x.SensorType == sensor).ToList();
			}
			return Enumerable.Empty<SensorDeviceMessageAttributes>().ToList();
		}

		public async Task<double> BatteryAsync()
		{
			if (!HasBattery)
			{
				throw new ButtplugDeviceException("Device " + Name + " does not have battery capabilities.");
			}
			ButtplugMessage buttplugMessage = await _handler.SendMessageAsync(new SensorReadCmd(Index, SensorReadAttributes(SensorType.Battery).ElementAt(0).Index, SensorType.Battery)).ConfigureAwait(continueOnCapturedContext: false);
			if (!(buttplugMessage is SensorReading sensorReading))
			{
				if (buttplugMessage is Error msg)
				{
					throw ButtplugException.FromError(msg);
				}
				throw new ButtplugMessageException("Message type " + buttplugMessage.Name + " not handled by BatteryAsync", buttplugMessage.Id);
			}
			return (double)sensorReading.data[0] / 100.0;
		}

		public async Task Stop()
		{
			await _handler.SendMessageExpectOk(new StopDeviceCmd(Index)).ConfigureAwait(continueOnCapturedContext: false);
		}
	}
	internal class ButtplugClientMessageHandler
	{
		private IButtplugClientConnector _connector;

		internal ButtplugClientMessageHandler(IButtplugClientConnector connector)
		{
			_connector = connector;
		}

		public async Task<ButtplugMessage> SendMessageAsync(ButtplugMessage msg, CancellationToken token = default(CancellationToken))
		{
			if (!_connector.Connected)
			{
				throw new ButtplugClientConnectorException("Client not connected.");
			}
			return await _connector.SendAsync(msg, token).ConfigureAwait(continueOnCapturedContext: false);
		}

		public async Task SendMessageExpectOk(ButtplugMessage msg, CancellationToken token = default(CancellationToken))
		{
			ButtplugMessage buttplugMessage = await SendMessageAsync(msg, token).ConfigureAwait(continueOnCapturedContext: false);
			if (!(buttplugMessage is Ok))
			{
				if (buttplugMessage is Error msg2)
				{
					throw ButtplugException.FromError(msg2);
				}
				throw new ButtplugMessageException("Message type " + msg.Name + " not handled by SendMessageExpectOk", msg.Id);
			}
		}
	}
	public class ButtplugConnectorJSONParser
	{
		private readonly ButtplugJsonMessageParser _parser = new ButtplugJsonMessageParser();

		public string Serialize(ButtplugMessage msg)
		{
			return _parser.Serialize(msg);
		}

		public string Serialize(ButtplugMessage[] msgs)
		{
			return _parser.Serialize(msgs);
		}

		public IEnumerable<ButtplugMessage> Deserialize(string msg)
		{
			return _parser.Deserialize(msg);
		}
	}
	public class ButtplugConnectorMessageSorter : IDisposable
	{
		private int _counter;

		private readonly ConcurrentDictionary<uint, TaskCompletionSource<ButtplugMessage>> _waitingMsgs = new ConcurrentDictionary<uint, TaskCompletionSource<ButtplugMessage>>();

		public uint NextMsgId => Convert.ToUInt32(Interlocked.Increment(ref _counter));

		public Task<ButtplugMessage> PrepareMessage(ButtplugMessage msg)
		{
			msg.Id = NextMsgId;
			TaskCompletionSource<ButtplugMessage> taskCompletionSource = new TaskCompletionSource<ButtplugMessage>();
			_waitingMsgs.TryAdd(msg.Id, taskCompletionSource);
			return taskCompletionSource.Task;
		}

		public void CheckMessage(ButtplugMessage msg)
		{
			if (msg.Id == 0)
			{
				throw new ButtplugMessageException("Cannot sort message with System ID", msg.Id);
			}
			if (!_waitingMsgs.TryRemove(msg.Id, out var value))
			{
				throw new ButtplugMessageException("Message with non-matching ID received.", msg.Id);
			}
			if (msg is Error msg2)
			{
				value.SetException(ButtplugException.FromError(msg2));
			}
			else
			{
				value.SetResult(msg);
			}
		}

		protected virtual void Dispose(bool disposing)
		{
			foreach (TaskCompletionSource<ButtplugMessage> value in _waitingMsgs.Values)
			{
				value.TrySetException(new Exception("Sorter has been destroyed with live tasks still in queue."));
			}
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	public class ButtplugRemoteJSONConnector : IDisposable
	{
		private readonly ButtplugConnectorJSONParser _jsonSerializer = new ButtplugConnectorJSONParser();

		private readonly ButtplugConnectorMessageSorter _msgSorter = new ButtplugConnectorMessageSorter();

		public event EventHandler<MessageReceivedEventArgs> MessageReceived;

		public event EventHandler<ButtplugExceptionEventArgs> InvalidMessageReceived;

		protected Tuple<string, Task<ButtplugMessage>> PrepareMessage(ButtplugMessage msg)
		{
			Task<ButtplugMessage> item = _msgSorter.PrepareMessage(msg);
			return new Tuple<string, Task<ButtplugMessage>>(_jsonSerializer.Serialize(msg), item);
		}

		protected void ReceiveMessages(string jSONMsg)
		{
			IEnumerable<ButtplugMessage> enumerable;
			try
			{
				enumerable = _jsonSerializer.Deserialize(jSONMsg);
			}
			catch (ButtplugMessageException ex)
			{
				this.InvalidMessageReceived?.Invoke(this, new ButtplugExceptionEventArgs(ex));
				return;
			}
			foreach (ButtplugMessage item in enumerable)
			{
				if (item.Id == 0)
				{
					this.MessageReceived?.Invoke(this, new MessageReceivedEventArgs(item));
					continue;
				}
				try
				{
					_msgSorter.CheckMessage(item);
				}
				catch (ButtplugMessageException ex2)
				{
					this.InvalidMessageReceived?.Invoke(this, new ButtplugExceptionEventArgs(ex2));
				}
			}
		}

		protected virtual void Dispose(bool disposing)
		{
			_msgSorter.Dispose();
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}
	}
	public class DeviceAddedEventArgs
	{
		public readonly ButtplugClientDevice Device;

		public DeviceAddedEventArgs(ButtplugClientDevice device)
		{
			Device = device;
		}
	}
	public class DeviceRemovedEventArgs
	{
		public readonly ButtplugClientDevice Device;

		public DeviceRemovedEventArgs(ButtplugClientDevice device)
		{
			Device = device;
		}
	}
	public interface IButtplugClientConnector
	{
		bool Connected { get; }

		event EventHandler<MessageReceivedEventArgs> MessageReceived;

		event EventHandler<ButtplugExceptionEventArgs> InvalidMessageReceived;

		event EventHandler Disconnected;

		Task ConnectAsync(CancellationToken token = default(CancellationToken));

		Task DisconnectAsync(CancellationToken token = default(CancellationToken));

		Task<ButtplugMessage> SendAsync(ButtplugMessage msg, CancellationToken token = default(CancellationToken));
	}
}

plugins/deniszykov.WebSocketListener.dll

Decompiled 2 years ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using vtortola.WebSockets.Async;
using vtortola.WebSockets.Extensibility;
using vtortola.WebSockets.Http;
using vtortola.WebSockets.Rfc6455.Header;
using vtortola.WebSockets.Tools;
using vtortola.WebSockets.Transports;
using vtortola.WebSockets.Transports.NamedPipes;
using vtortola.WebSockets.Transports.Sockets;
using vtortola.WebSockets.Transports.Tcp;
using vtortola.WebSockets.Transports.UnixSockets;

[assembly: AssemblyCompany("deniszykov")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A lightweight and highly scalable asynchronous WebSocket listener for .NET Core, .NET and Mono.\r\nhttps://github.com/deniszykov/WebSocketListener")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/deniszykov/WebSocketListener")]
[assembly: AssemblyTitle("deniszykov.WebSocketListener")]
[assembly: AssemblyInformationalVersion("4.2.16")]
[assembly: AssemblyProduct("deniszykov.WebSocketListener")]
[assembly: AssemblyFileVersion("4.2.16.0")]
[assembly: AssemblyVersion("4.2.16.0")]
namespace vtortola.WebSockets.Deflate
{
	public sealed class WebSocketDeflateContext : IWebSocketMessageExtensionContext
	{
		public WebSocketMessageReadStream ExtendReader(WebSocketMessageReadStream message)
		{
			if (message == null)
			{
				throw new ArgumentNullException("message");
			}
			if (message.Flags.Rsv1)
			{
				return new WebSocketDeflateReadStream(message);
			}
			return message;
		}

		public WebSocketMessageWriteStream ExtendWriter(WebSocketMessageWriteStream message)
		{
			if (message == null)
			{
				throw new ArgumentNullException("message");
			}
			message.ExtensionFlags.Rsv1 = true;
			return new WebSocketDeflateWriteStream(message);
		}
	}
	public sealed class WebSocketDeflateExtension : IWebSocketMessageExtension
	{
		public const string EXTENSION_NAME = "permessage-deflate";

		private static readonly ReadOnlyCollection<WebSocketExtensionOption> DefaultOptions = new ReadOnlyCollection<WebSocketExtensionOption>(new WebSocketExtensionOption[1]
		{
			new WebSocketExtensionOption("client_no_context_takeover")
		});

		private static readonly WebSocketExtension DefaultResponse = new WebSocketExtension("permessage-deflate", DefaultOptions);

		public string Name => "permessage-deflate";

		public bool TryNegotiate(WebSocketHttpRequest request, out WebSocketExtension extensionResponse, out IWebSocketMessageExtensionContext context)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			extensionResponse = DefaultResponse;
			context = new WebSocketDeflateContext();
			return true;
		}

		public IWebSocketMessageExtension Clone()
		{
			return (WebSocketDeflateExtension)MemberwiseClone();
		}

		public override string ToString()
		{
			return DefaultResponse.ToString();
		}
	}
	public sealed class WebSocketDeflateReadStream : WebSocketMessageReadStream
	{
		private const int STATE_OPEN = 0;

		private const int STATE_CLOSED = 1;

		private const int STATE_DISPOSED = 2;

		private readonly WebSocketMessageReadStream innerStream;

		private readonly DeflateStream deflateStream;

		private volatile int state;

		public override WebSocketMessageType MessageType => innerStream.MessageType;

		public override WebSocketExtensionFlags Flags => innerStream.Flags;

		internal override WebSocketListenerOptions Options => innerStream.Options;

		public WebSocketDeflateReadStream([NotNull] WebSocketMessageReadStream innerStream)
		{
			if (innerStream == null)
			{
				throw new ArgumentNullException("innerStream");
			}
			this.innerStream = innerStream;
			deflateStream = new DeflateStream(innerStream, CompressionMode.Decompress, leaveOpen: true);
		}

		public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			return deflateStream.ReadAsync(buffer, offset, count, cancellationToken);
		}

		public override Task CloseAsync()
		{
			if (Interlocked.CompareExchange(ref state, 1, 0) != 0)
			{
				return TaskHelper.CompletedTask;
			}
			return innerStream.CloseAsync();
		}

		protected override void Dispose(bool disposing)
		{
			if (Interlocked.Exchange(ref state, 2) != 2)
			{
				SafeEnd.Dispose(deflateStream);
				SafeEnd.Dispose(innerStream);
			}
		}
	}
	public sealed class WebSocketDeflateWriteStream : WebSocketMessageWriteStream
	{
		private static readonly byte[] FINAL_BYTE = new byte[1];

		private const int STATE_OPEN = 0;

		private const int STATE_CLOSED = 1;

		private const int STATE_DISPOSED = 2;

		private readonly WebSocketMessageWriteStream innerStream;

		private readonly DeflateStream deflateStream;

		private volatile int state;

		internal override WebSocketListenerOptions Options => innerStream.Options;

		public WebSocketDeflateWriteStream([NotNull] WebSocketMessageWriteStream innerStream)
		{
			if (innerStream == null)
			{
				throw new ArgumentNullException("innerStream");
			}
			this.innerStream = innerStream;
			deflateStream = new DeflateStream(innerStream, CompressionLevel.Optimal, leaveOpen: true);
		}

		public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0 || offset > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0 || offset + count > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			if (count == 0)
			{
				return Task.FromResult(0);
			}
			return deflateStream.WriteAsync(buffer, offset, count, cancellationToken);
		}

		public override async Task WriteAndCloseAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0 || offset > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0 || offset + count > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			if (count > 0)
			{
				await deflateStream.WriteAsync(buffer, offset, count, cancellationToken);
			}
			await CloseAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		public override async Task CloseAsync()
		{
			if (Interlocked.CompareExchange(ref state, 1, 0) == 0)
			{
				await deflateStream.FlushAsync(CancellationToken.None);
				deflateStream.Dispose();
				await innerStream.WriteAndCloseAsync(FINAL_BYTE, 0, 1, CancellationToken.None).ConfigureAwait(continueOnCapturedContext: false);
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (Interlocked.Exchange(ref state, 2) != 2)
			{
				SafeEnd.Dispose(deflateStream);
				SafeEnd.Dispose(innerStream);
				base.Dispose(disposing);
			}
		}
	}
	public static class WebSocketMessageExtensionCollectionExtensions
	{
		public static WebSocketMessageExtensionCollection RegisterDeflateCompression(this WebSocketMessageExtensionCollection collection)
		{
			if (collection == null)
			{
				throw new ArgumentNullException("collection");
			}
			collection.Add(new WebSocketDeflateExtension());
			return collection;
		}
	}
}
namespace JetBrains.Annotations
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.GenericParameter)]
	internal sealed class CanBeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.GenericParameter)]
	internal sealed class NotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Delegate)]
	internal sealed class ItemNotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Delegate)]
	internal sealed class ItemCanBeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate)]
	internal sealed class StringFormatMethodAttribute : Attribute
	{
		[NotNull]
		public string FormatParameterName { get; private set; }

		public StringFormatMethodAttribute([NotNull] string formatParameterName)
		{
			FormatParameterName = formatParameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
	internal sealed class ValueProviderAttribute : Attribute
	{
		[NotNull]
		public string Name { get; private set; }

		public ValueProviderAttribute([NotNull] string name)
		{
			Name = name;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class InvokerParameterNameAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class NotifyPropertyChangedInvocatorAttribute : Attribute
	{
		[CanBeNull]
		public string ParameterName { get; private set; }

		public NotifyPropertyChangedInvocatorAttribute()
		{
		}

		public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
	internal sealed class ContractAnnotationAttribute : Attribute
	{
		[NotNull]
		public string Contract { get; private set; }

		public bool ForceFullStates { get; private set; }

		public ContractAnnotationAttribute([NotNull] string contract)
			: this(contract, forceFullStates: false)
		{
		}

		public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates)
		{
			Contract = contract;
			ForceFullStates = forceFullStates;
		}
	}
	[AttributeUsage(AttributeTargets.All)]
	internal sealed class LocalizationRequiredAttribute : Attribute
	{
		public bool Required { get; private set; }

		public LocalizationRequiredAttribute()
			: this(required: true)
		{
		}

		public LocalizationRequiredAttribute(bool required)
		{
			Required = required;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
	internal sealed class CannotApplyEqualityOperatorAttribute : Attribute
	{
	}
	[BaseTypeRequired(typeof(Attribute))]
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	internal sealed class BaseTypeRequiredAttribute : Attribute
	{
		[NotNull]
		public Type BaseType { get; private set; }

		public BaseTypeRequiredAttribute([NotNull] Type baseType)
		{
			BaseType = baseType;
		}
	}
	[AttributeUsage(AttributeTargets.All)]
	internal sealed class UsedImplicitlyAttribute : Attribute
	{
		public ImplicitUseKindFlags UseKindFlags { get; private set; }

		public ImplicitUseTargetFlags TargetFlags { get; private set; }

		public UsedImplicitlyAttribute()
			: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags)
			: this(useKindFlags, ImplicitUseTargetFlags.Default)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags)
			: this(ImplicitUseKindFlags.Default, targetFlags)
		{
		}

		public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
		{
			UseKindFlags = useKindFlags;
			TargetFlags = targetFlags;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)]
	internal sealed class MeansImplicitUseAttribute : Attribute
	{
		[UsedImplicitly]
		public ImplicitUseKindFlags UseKindFlags { get; private set; }

		[UsedImplicitly]
		public ImplicitUseTargetFlags TargetFlags { get; private set; }

		public MeansImplicitUseAttribute()
			: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags)
			: this(useKindFlags, ImplicitUseTargetFlags.Default)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags)
			: this(ImplicitUseKindFlags.Default, targetFlags)
		{
		}

		public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
		{
			UseKindFlags = useKindFlags;
			TargetFlags = targetFlags;
		}
	}
	[Flags]
	internal enum ImplicitUseKindFlags
	{
		Default = 7,
		Access = 1,
		Assign = 2,
		InstantiatedWithFixedConstructorSignature = 4,
		InstantiatedNoFixedConstructorSignature = 8
	}
	[Flags]
	internal enum ImplicitUseTargetFlags
	{
		Default = 1,
		Itself = 1,
		Members = 2,
		WithMembers = 3
	}
	[MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)]
	internal sealed class PublicAPIAttribute : Attribute
	{
		[CanBeNull]
		public string Comment { get; private set; }

		public PublicAPIAttribute()
		{
		}

		public PublicAPIAttribute([NotNull] string comment)
		{
			Comment = comment;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class InstantHandleAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class PureAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class MustUseReturnValueAttribute : Attribute
	{
		[CanBeNull]
		public string Justification { get; private set; }

		public MustUseReturnValueAttribute()
		{
		}

		public MustUseReturnValueAttribute([NotNull] string justification)
		{
			Justification = justification;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
	internal sealed class ProvidesContextAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class PathReferenceAttribute : Attribute
	{
		[CanBeNull]
		public string BasePath { get; private set; }

		public PathReferenceAttribute()
		{
		}

		public PathReferenceAttribute([NotNull][PathReference] string basePath)
		{
			BasePath = basePath;
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class SourceTemplateAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = true)]
	internal sealed class MacroAttribute : Attribute
	{
		[CanBeNull]
		public string Expression { get; set; }

		public int Editable { get; set; }

		[CanBeNull]
		public string Target { get; set; }
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcAreaViewLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcAreaViewLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcMasterLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcMasterLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcPartialViewLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcPartialViewLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
	internal sealed class AspMvcViewLocationFormatAttribute : Attribute
	{
		[NotNull]
		public string Format { get; private set; }

		public AspMvcViewLocationFormatAttribute([NotNull] string format)
		{
			Format = format;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class AspMvcActionAttribute : Attribute
	{
		[CanBeNull]
		public string AnonymousProperty { get; private set; }

		public AspMvcActionAttribute()
		{
		}

		public AspMvcActionAttribute([NotNull] string anonymousProperty)
		{
			AnonymousProperty = anonymousProperty;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcAreaAttribute : Attribute
	{
		[CanBeNull]
		public string AnonymousProperty { get; private set; }

		public AspMvcAreaAttribute()
		{
		}

		public AspMvcAreaAttribute([NotNull] string anonymousProperty)
		{
			AnonymousProperty = anonymousProperty;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class AspMvcControllerAttribute : Attribute
	{
		[CanBeNull]
		public string AnonymousProperty { get; private set; }

		public AspMvcControllerAttribute()
		{
		}

		public AspMvcControllerAttribute([NotNull] string anonymousProperty)
		{
			AnonymousProperty = anonymousProperty;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcMasterAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcModelTypeAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class AspMvcPartialViewAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	internal sealed class AspMvcSuppressViewErrorAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcDisplayTemplateAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcEditorTemplateAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcTemplateAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class AspMvcViewAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AspMvcViewComponentAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class AspMvcViewComponentViewAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]
	internal sealed class AspMvcActionSelectorAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
	internal sealed class HtmlElementAttributesAttribute : Attribute
	{
		[CanBeNull]
		public string Name { get; private set; }

		public HtmlElementAttributesAttribute()
		{
		}

		public HtmlElementAttributesAttribute([NotNull] string name)
		{
			Name = name;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
	internal sealed class HtmlAttributeValueAttribute : Attribute
	{
		[NotNull]
		public string Name { get; private set; }

		public HtmlAttributeValueAttribute([NotNull] string name)
		{
			Name = name;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
	internal sealed class RazorSectionAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)]
	internal sealed class CollectionAccessAttribute : Attribute
	{
		public CollectionAccessType CollectionAccessType { get; private set; }

		public CollectionAccessAttribute(CollectionAccessType collectionAccessType)
		{
			CollectionAccessType = collectionAccessType;
		}
	}
	[Flags]
	internal enum CollectionAccessType
	{
		None = 0,
		Read = 1,
		ModifyExistingContent = 2,
		UpdatedContent = 6
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class AssertionMethodAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class AssertionConditionAttribute : Attribute
	{
		public AssertionConditionType ConditionType { get; private set; }

		public AssertionConditionAttribute(AssertionConditionType conditionType)
		{
			ConditionType = conditionType;
		}
	}
	internal enum AssertionConditionType
	{
		IS_TRUE,
		IS_FALSE,
		IS_NULL,
		IS_NOT_NULL
	}
	[Obsolete("Use [ContractAnnotation('=> halt')] instead")]
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class TerminatesProgramAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class LinqTunnelAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class NoEnumerationAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class RegexPatternAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface)]
	internal sealed class NoReorderAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class)]
	internal sealed class XamlItemsControlAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property)]
	internal sealed class XamlItemBindingOfItemsControlAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	internal sealed class AspChildControlTypeAttribute : Attribute
	{
		[NotNull]
		public string TagName { get; private set; }

		[NotNull]
		public Type ControlType { get; private set; }

		public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType)
		{
			TagName = tagName;
			ControlType = controlType;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
	internal sealed class AspDataFieldAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
	internal sealed class AspDataFieldsAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property)]
	internal sealed class AspMethodPropertyAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	internal sealed class AspRequiredAttributeAttribute : Attribute
	{
		[NotNull]
		public string Attribute { get; private set; }

		public AspRequiredAttributeAttribute([NotNull] string attribute)
		{
			Attribute = attribute;
		}
	}
	[AttributeUsage(AttributeTargets.Property)]
	internal sealed class AspTypePropertyAttribute : Attribute
	{
		public bool CreateConstructorReferences { get; private set; }

		public AspTypePropertyAttribute(bool createConstructorReferences)
		{
			CreateConstructorReferences = createConstructorReferences;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class RazorImportNamespaceAttribute : Attribute
	{
		[NotNull]
		public string Name { get; private set; }

		public RazorImportNamespaceAttribute([NotNull] string name)
		{
			Name = name;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class RazorInjectionAttribute : Attribute
	{
		[NotNull]
		public string Type { get; private set; }

		[NotNull]
		public string FieldName { get; private set; }

		public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName)
		{
			Type = type;
			FieldName = fieldName;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class RazorDirectiveAttribute : Attribute
	{
		[NotNull]
		public string Directive { get; private set; }

		public RazorDirectiveAttribute([NotNull] string directive)
		{
			Directive = directive;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class RazorPageBaseTypeAttribute : Attribute
	{
		[NotNull]
		public string BaseType { get; private set; }

		[CanBeNull]
		public string PageName { get; private set; }

		public RazorPageBaseTypeAttribute([NotNull] string baseType)
		{
			BaseType = baseType;
		}

		public RazorPageBaseTypeAttribute([NotNull] string baseType, string pageName)
		{
			BaseType = baseType;
			PageName = pageName;
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class RazorHelperCommonAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property)]
	internal sealed class RazorLayoutAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class RazorWriteLiteralMethodAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method)]
	internal sealed class RazorWriteMethodAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter)]
	internal sealed class RazorWriteMethodParameterAttribute : Attribute
	{
	}
}
namespace vtortola.WebSockets
{
	public abstract class BufferManager
	{
		[Obsolete("Is not used")]
		public abstract int SmallBufferSize { get; }

		public abstract int LargeBufferSize { get; }

		public static BufferManager CreateBufferManager(long maxBufferPoolSize, int maxBufferSize)
		{
			if (maxBufferPoolSize < 0)
			{
				throw new ArgumentOutOfRangeException("maxBufferPoolSize");
			}
			if (maxBufferSize < 0)
			{
				throw new ArgumentOutOfRangeException("maxBufferSize");
			}
			if (maxBufferSize < 256)
			{
				maxBufferSize = 256;
			}
			if (maxBufferPoolSize < maxBufferSize)
			{
				maxBufferPoolSize = maxBufferSize * 10;
			}
			int num = (int)Math.Pow(2.0, Math.Ceiling(Math.Log(maxBufferSize) / Math.Log(2.0)));
			int num2 = (int)Math.Max(2.0, Math.Ceiling((float)maxBufferPoolSize / 2f / (float)num));
			int num3 = Math.Max(32, num / 256);
			int smallPoolSizeLimit = (int)Math.Max(2L, (maxBufferPoolSize - num2 * num) / num3);
			return new DefaultBufferManager(num3, smallPoolSizeLimit, num, num2);
		}

		[NotNull]
		public static BufferManager CreateBufferManager(int smallBufferSize, int smallBufferPoolSize, int largeBufferSize, int largeBufferPoolSize)
		{
			if (smallBufferSize < 0)
			{
				throw new ArgumentOutOfRangeException("smallBufferSize");
			}
			if (largeBufferSize < 0)
			{
				throw new ArgumentOutOfRangeException("largeBufferSize");
			}
			if (smallBufferPoolSize < 0)
			{
				throw new ArgumentOutOfRangeException("smallBufferPoolSize");
			}
			if (largeBufferPoolSize < 0)
			{
				throw new ArgumentOutOfRangeException("largeBufferPoolSize");
			}
			return new DefaultBufferManager(smallBufferSize, smallBufferPoolSize, largeBufferSize, largeBufferPoolSize);
		}

		[Obsolete("Is not used")]
		public abstract void Clear();

		public abstract void ReturnBuffer(byte[] buffer);

		public abstract byte[] TakeBuffer(int bufferSize);
	}
	public sealed class ConsoleLogger : ILogger
	{
		public static ConsoleLogger Instance = new ConsoleLogger();

		public bool IsDebugEnabled { get; set; }

		public bool IsWarningEnabled { get; set; }

		public bool IsErrorEnabled { get; set; }

		public ConsoleLogger()
		{
			IsDebugEnabled = true;
			IsWarningEnabled = true;
			IsErrorEnabled = true;
		}

		public void Debug(string message, Exception error = null)
		{
			if (IsDebugEnabled)
			{
				if (!string.IsNullOrEmpty(message))
				{
					Console.WriteLine(message);
				}
				if (error != null)
				{
					Console.WriteLine(error);
				}
			}
		}

		public void Warning(string message, Exception error = null)
		{
			if (IsWarningEnabled)
			{
				string.IsNullOrEmpty(message);
				if (error != null)
				{
					Console.WriteLine(error);
				}
			}
		}

		public void Error(string message, Exception error = null)
		{
			if (IsErrorEnabled)
			{
				string.IsNullOrEmpty(message);
				if (error != null)
				{
					Console.WriteLine(error);
				}
			}
		}
	}
	public sealed class DebugLogger : ILogger
	{
		public static DebugLogger Instance = new DebugLogger();

		public bool IsDebugEnabled { get; set; }

		public bool IsWarningEnabled { get; set; }

		public bool IsErrorEnabled { get; set; }

		public DebugLogger()
		{
			IsDebugEnabled = true;
			IsWarningEnabled = true;
			IsErrorEnabled = true;
		}

		public void Debug(string message, Exception error = null)
		{
			if (IsDebugEnabled)
			{
				string.IsNullOrEmpty(message);
			}
		}

		public void Warning(string message, Exception error = null)
		{
			if (IsWarningEnabled)
			{
				string.IsNullOrEmpty(message);
			}
		}

		public void Error(string message, Exception error = null)
		{
			if (IsErrorEnabled)
			{
				string.IsNullOrEmpty(message);
			}
		}
	}
	internal sealed class DefaultBufferManager : BufferManager
	{
		private readonly ObjectPool<byte[]> smallPool;

		private readonly ObjectPool<byte[]> largePool;

		public override int SmallBufferSize { get; }

		public override int LargeBufferSize { get; }

		public DefaultBufferManager(int smallBufferSize, int smallPoolSizeLimit, int largeBufferSize, int largePoolSizeLimit)
		{
			SmallBufferSize = smallBufferSize;
			LargeBufferSize = largeBufferSize;
			smallPool = new ObjectPool<byte[]>(() => new byte[smallBufferSize], smallPoolSizeLimit);
			largePool = new ObjectPool<byte[]>(() => new byte[largeBufferSize], largePoolSizeLimit);
		}

		public override void Clear()
		{
			smallPool.Clear();
			largePool.Clear();
		}

		public override void ReturnBuffer(byte[] buffer)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (buffer.Length >= LargeBufferSize)
			{
				largePool.Return(buffer);
				return;
			}
			if (buffer.Length >= SmallBufferSize)
			{
				smallPool.Return(buffer);
				return;
			}
			throw new ArgumentException("Length of buffer does not match the pool's buffer length property.", "buffer");
		}

		public override byte[] TakeBuffer(int bufferSize)
		{
			if (bufferSize < 0 || bufferSize > LargeBufferSize)
			{
				throw new ArgumentOutOfRangeException("bufferSize");
			}
			if (bufferSize >= SmallBufferSize)
			{
				return largePool.Take();
			}
			return smallPool.Take();
		}
	}
	[PublicAPI]
	public interface IHttpFallback
	{
		void Post([NotNull] IHttpRequest request, [NotNull] NetworkConnection networkConnection);
	}
	[PublicAPI]
	public interface IHttpRequest
	{
		EndPoint LocalEndPoint { get; }

		EndPoint RemoteEndPoint { get; }

		Uri RequestUri { get; }

		Version HttpVersion { get; }

		bool IsSecure { get; }

		CookieCollection Cookies { get; }

		Headers<RequestHeader> Headers { get; }

		IDictionary<string, object> Items { get; }
	}
	public interface IWebSocketConnectionExtension
	{
		[ItemNotNull]
		[NotNull]
		Task<NetworkConnection> ExtendConnectionAsync([NotNull] NetworkConnection networkConnection);

		[NotNull]
		IWebSocketConnectionExtension Clone();
	}
	public interface IWebSocketMessageExtension
	{
		string Name { get; }

		bool TryNegotiate(WebSocketHttpRequest request, out WebSocketExtension extensionResponse, out IWebSocketMessageExtensionContext context);

		IWebSocketMessageExtension Clone();

		new string ToString();
	}
	public interface IWebSocketMessageExtensionContext
	{
		[NotNull]
		WebSocketMessageReadStream ExtendReader([NotNull] WebSocketMessageReadStream message);

		[NotNull]
		WebSocketMessageWriteStream ExtendWriter([NotNull] WebSocketMessageWriteStream message);
	}
	[PublicAPI]
	public sealed class WebSocketConnectionExtensionCollection : IReadOnlyCollection<IWebSocketConnectionExtension>, IEnumerable<IWebSocketConnectionExtension>, IEnumerable
	{
		private readonly List<IWebSocketConnectionExtension> extensions;

		private volatile int useCounter;

		public int Count => extensions.Count;

		public bool IsReadOnly => useCounter > 0;

		public WebSocketConnectionExtensionCollection()
		{
			extensions = new List<IWebSocketConnectionExtension>();
		}

		public void Add(IWebSocketConnectionExtension extension)
		{
			if (extension == null)
			{
				throw new ArgumentNullException("extension");
			}
			if (IsReadOnly)
			{
				throw new WebSocketException("New entries cannot be added because this collection is used in running WebSocketClient or WebSocketListener.");
			}
			if (extensions.Any((IWebSocketConnectionExtension ext) => ext.GetType() == extension.GetType()))
			{
				throw new WebSocketException($"Can't add extension '{extension}' because another extension of type '{extension.GetType().Name}' is already exists in collection.");
			}
			extensions.Add(extension);
		}

		public WebSocketConnectionExtensionCollection RegisterSecureConnection(X509Certificate2 certificate, RemoteCertificateValidationCallback validation = null, SslProtocols supportedSslProtocols = SslProtocols.Tls12)
		{
			if (certificate == null)
			{
				throw new ArgumentNullException("certificate");
			}
			WebSocketSecureConnectionExtension extension = new WebSocketSecureConnectionExtension(certificate, validation, supportedSslProtocols);
			Add(extension);
			return this;
		}

		IEnumerator<IWebSocketConnectionExtension> IEnumerable<IWebSocketConnectionExtension>.GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		public List<IWebSocketConnectionExtension>.Enumerator GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		internal WebSocketConnectionExtensionCollection Clone()
		{
			WebSocketConnectionExtensionCollection webSocketConnectionExtensionCollection = new WebSocketConnectionExtensionCollection();
			foreach (IWebSocketConnectionExtension extension in extensions)
			{
				webSocketConnectionExtensionCollection.extensions.Add(extension.Clone());
			}
			return webSocketConnectionExtensionCollection;
		}

		internal void SetUsed(bool isUsed)
		{
			int num = 0;
			num = ((!isUsed) ? Interlocked.Decrement(ref useCounter) : Interlocked.Increment(ref useCounter));
			if (num < 0)
			{
				throw new InvalidOperationException("The collection is released more than once.");
			}
		}

		public override string ToString()
		{
			return string.Join(", ", extensions);
		}
	}
	public sealed class WebSocketFactoryCollection : IReadOnlyCollection<WebSocketFactory>, IEnumerable<WebSocketFactory>, IEnumerable
	{
		private readonly Dictionary<short, WebSocketFactory> factoryByVersion;

		private volatile int useCounter;

		public IEnumerable<short> SupportedVersions => factoryByVersion.Keys;

		public int Count => factoryByVersion.Count;

		public bool IsReadOnly => useCounter > 0;

		public WebSocketFactoryCollection()
		{
			factoryByVersion = new Dictionary<short, WebSocketFactory>();
		}

		public void Add(WebSocketFactory factory)
		{
			if (factory == null)
			{
				throw new ArgumentNullException("factory");
			}
			if (IsReadOnly)
			{
				throw new WebSocketException("New entries cannot be added because this collection is used in running WebSocketClient or WebSocketListener.");
			}
			if (factoryByVersion.ContainsKey(factory.Version))
			{
				throw new WebSocketException(string.Format("Can't add {0} '{1}' because another {2} with ", "WebSocketFactory", factory, "WebSocketFactory") + $"version '{factory.Version}' is already exists in collection.");
			}
			factoryByVersion.Add(factory.Version, factory);
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return factoryByVersion.Values.GetEnumerator();
		}

		IEnumerator<WebSocketFactory> IEnumerable<WebSocketFactory>.GetEnumerator()
		{
			return factoryByVersion.Values.GetEnumerator();
		}

		public Dictionary<short, WebSocketFactory>.ValueCollection.Enumerator GetEnumerator()
		{
			return factoryByVersion.Values.GetEnumerator();
		}

		internal WebSocketFactoryCollection Clone()
		{
			WebSocketFactoryCollection webSocketFactoryCollection = new WebSocketFactoryCollection();
			foreach (KeyValuePair<short, WebSocketFactory> item in factoryByVersion)
			{
				webSocketFactoryCollection.factoryByVersion[item.Key] = item.Value.Clone();
			}
			return webSocketFactoryCollection;
		}

		internal void SetUsed(bool isUsed)
		{
			int num = 0;
			num = ((!isUsed) ? Interlocked.Decrement(ref useCounter) : Interlocked.Increment(ref useCounter));
			if (num < 0)
			{
				throw new InvalidOperationException("The collection is released more than once.");
			}
		}

		internal WebSocketFactory GetLast()
		{
			return factoryByVersion[factoryByVersion.Keys.Max()];
		}

		public bool TryGetWebSocketFactory(WebSocketHttpRequest request, out WebSocketFactory factory)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			factory = null;
			short result = 0;
			if (short.TryParse(request.Headers[RequestHeader.WebSocketVersion], out result) && factoryByVersion.TryGetValue(result, out factory))
			{
				return true;
			}
			return false;
		}
	}
	public sealed class WebSocketMessageExtensionCollection : IReadOnlyCollection<IWebSocketMessageExtension>, IEnumerable<IWebSocketMessageExtension>, IEnumerable
	{
		private readonly List<IWebSocketMessageExtension> extensions;

		private volatile int useCounter;

		public int Count => extensions.Count;

		public bool IsReadOnly => useCounter > 0;

		public WebSocketMessageExtensionCollection()
		{
			extensions = new List<IWebSocketMessageExtension>();
		}

		public void Add(IWebSocketMessageExtension extension)
		{
			if (extension == null)
			{
				throw new ArgumentNullException("extension");
			}
			if (IsReadOnly)
			{
				throw new WebSocketException("New entries cannot be added because this collection is used in running WebSocketClient or WebSocketListener.");
			}
			if (extensions.Any((IWebSocketMessageExtension ext) => ext.GetType() == extension.GetType()))
			{
				throw new WebSocketException($"Can't add extension '{extension}' because another extension of type '{extension.GetType().Name}' is already exists in collection.");
			}
			extensions.Add(extension);
		}

		IEnumerator<IWebSocketMessageExtension> IEnumerable<IWebSocketMessageExtension>.GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		public List<IWebSocketMessageExtension>.Enumerator GetEnumerator()
		{
			return extensions.GetEnumerator();
		}

		internal WebSocketMessageExtensionCollection Clone()
		{
			WebSocketMessageExtensionCollection webSocketMessageExtensionCollection = new WebSocketMessageExtensionCollection();
			foreach (IWebSocketMessageExtension extension in extensions)
			{
				webSocketMessageExtensionCollection.extensions.Add(extension.Clone());
			}
			return webSocketMessageExtensionCollection;
		}

		internal void SetUsed(bool isUsed)
		{
			int num = 0;
			num = ((!isUsed) ? Interlocked.Decrement(ref useCounter) : Interlocked.Increment(ref useCounter));
			if (num < 0)
			{
				throw new InvalidOperationException("The collection is released more than once.");
			}
		}

		public override string ToString()
		{
			return string.Join(", ", extensions);
		}
	}
	public sealed class WebSocketSecureConnectionExtension : IWebSocketConnectionExtension
	{
		private readonly X509Certificate2 _certificate;

		private readonly RemoteCertificateValidationCallback _validation;

		private readonly SslProtocols _protocols;

		public WebSocketSecureConnectionExtension(X509Certificate2 certificate)
		{
			if (certificate == null)
			{
				throw new ArgumentNullException("certificate");
			}
			_certificate = certificate;
			_protocols = SslProtocols.Tls12;
		}

		public WebSocketSecureConnectionExtension(X509Certificate2 certificate, RemoteCertificateValidationCallback validation)
		{
			if (certificate == null)
			{
				throw new ArgumentNullException("certificate");
			}
			_certificate = certificate;
			_validation = validation;
			_protocols = SslProtocols.Tls12;
		}

		public WebSocketSecureConnectionExtension(X509Certificate2 certificate, RemoteCertificateValidationCallback validation, SslProtocols supportedSslProtocols)
		{
			if (certificate == null)
			{
				throw new ArgumentNullException("certificate");
			}
			_certificate = certificate;
			_validation = validation;
			_protocols = supportedSslProtocols;
		}

		public async Task<NetworkConnection> ExtendConnectionAsync(NetworkConnection networkConnection)
		{
			if (networkConnection == null)
			{
				throw new ArgumentNullException("networkConnection");
			}
			SslStream ssl = new SslStream(networkConnection.AsStream(), leaveInnerStreamOpen: false, _validation);
			try
			{
				await ssl.AuthenticateAsServerAsync(_certificate, _validation != null, _protocols, checkCertificateRevocation: false).ConfigureAwait(continueOnCapturedContext: false);
				return new SslNetworkConnection(ssl, networkConnection);
			}
			catch
			{
				SafeEnd.Dispose(ssl);
				throw;
			}
		}

		public IWebSocketConnectionExtension Clone()
		{
			return (IWebSocketConnectionExtension)MemberwiseClone();
		}

		public override string ToString()
		{
			return $"Secure Connection: protocols: {_protocols}, certificate: {_certificate.SubjectName}";
		}
	}
	public sealed class WebSocketExtensionFlags
	{
		private bool _rsv1;

		private bool _rsv2;

		private bool _rsv3;

		private readonly bool _none;

		public static readonly WebSocketExtensionFlags None = new WebSocketExtensionFlags(none: true);

		public bool Rsv1
		{
			get
			{
				return _rsv1;
			}
			set
			{
				_rsv1 = value && !_none;
			}
		}

		public bool Rsv2
		{
			get
			{
				return _rsv2;
			}
			set
			{
				_rsv2 = value && !_none;
			}
		}

		public bool Rsv3
		{
			get
			{
				return _rsv3;
			}
			set
			{
				_rsv3 = value && !_none;
			}
		}

		public WebSocketExtensionFlags()
		{
			_none = false;
		}

		private WebSocketExtensionFlags(bool none)
		{
			_none = true;
		}
	}
	public enum WebSocketMessageType
	{
		Text = 1,
		Binary
	}
	public delegate Task<bool> HttpAuthenticationCallback(WebSocketHttpRequest request, WebSocketHttpResponse response);
	public static class CookieParser
	{
		public static IEnumerable<Cookie> Parse([CanBeNull] string cookieString)
		{
			if (string.IsNullOrWhiteSpace(cookieString))
			{
				yield break;
			}
			string text = string.Empty;
			string text2 = string.Empty;
			for (int i = 0; i < cookieString.Length; i++)
			{
				char c = cookieString[i];
				if (c == '=' && string.IsNullOrWhiteSpace(text2))
				{
					text2 = text;
					text = string.Empty;
				}
				else if (c == ';')
				{
					if (!string.IsNullOrWhiteSpace(text2))
					{
						yield return CreateCookie(text2, text);
					}
					else
					{
						yield return CreateCookie(text, string.Empty);
					}
					text2 = string.Empty;
					text = string.Empty;
				}
				else
				{
					text += c;
				}
			}
			if (!string.IsNullOrWhiteSpace(text2) && !string.IsNullOrWhiteSpace(text))
			{
				yield return CreateCookie(text2, text);
			}
		}

		private static Cookie CreateCookie(string key, string value)
		{
			return new Cookie(key.Trim(), WebUtility.UrlDecode(value.Trim()));
		}
	}
	public sealed class WebSocketExtension
	{
		public static readonly ReadOnlyCollection<WebSocketExtensionOption> Empty = new ReadOnlyCollection<WebSocketExtensionOption>(new List<WebSocketExtensionOption>());

		private readonly string extensionString;

		public readonly string Name;

		public readonly ReadOnlyCollection<WebSocketExtensionOption> Options;

		public WebSocketExtension(string name, IList<WebSocketExtensionOption> options)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			Name = name;
			Options = (options as ReadOnlyCollection<WebSocketExtensionOption>) ?? new ReadOnlyCollection<WebSocketExtensionOption>(options);
			extensionString = ((Options.Count > 0) ? (Name + ";" + string.Join(";", Options)) : Name);
		}

		public WebSocketExtension(string name)
		{
			Name = name;
			Options = Empty;
		}

		public override string ToString()
		{
			return extensionString;
		}
	}
	public class WebSocketExtensionOption
	{
		public readonly string Name;

		public readonly string Value;

		public readonly bool ClientAvailableOption;

		public WebSocketExtensionOption(string name)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			Name = name;
		}

		public WebSocketExtensionOption(string name, bool clientAvailableOption)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			Name = name;
			ClientAvailableOption = clientAvailableOption;
		}

		public WebSocketExtensionOption(string name, string value)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			Name = name;
			Value = value;
		}

		public override string ToString()
		{
			if (string.IsNullOrEmpty(Value))
			{
				return Name;
			}
			return Name + "=" + Value;
		}
	}
	internal class WebSocketHandshake : IComparable<WebSocketHandshake>, IEquatable<WebSocketHandshake>
	{
		private static long LastId = 1L;

		private bool _invalidated;

		public readonly long Id;

		[NotNull]
		public readonly WebSocketHttpRequest Request;

		public readonly WebSocketHttpResponse Response;

		public readonly List<IWebSocketMessageExtensionContext> NegotiatedMessageExtensions;

		public bool IsWebSocketRequest { get; internal set; }

		public bool IsVersionSupported { get; internal set; }

		public bool IsResponseSent { get; internal set; }

		public WebSocketFactory Factory { get; internal set; }

		public ExceptionDispatchInfo Error { get; internal set; }

		public bool IsValidWebSocketRequest
		{
			get
			{
				if (!_invalidated && Error == null && IsWebSocketRequest && IsVersionSupported)
				{
					return Response.Status == HttpStatusCode.SwitchingProtocols;
				}
				return false;
			}
			set
			{
				_invalidated = !value;
			}
		}

		public bool IsValidHttpRequest
		{
			get
			{
				if (!_invalidated)
				{
					return Error == null;
				}
				return false;
			}
			set
			{
				_invalidated = !value;
			}
		}

		public WebSocketHandshake([NotNull] WebSocketHttpRequest request)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			Id = Interlocked.Increment(ref LastId);
			Request = request;
			Response = new WebSocketHttpResponse();
			NegotiatedMessageExtensions = new List<IWebSocketMessageExtensionContext>();
		}

		public string ComputeHandshake()
		{
			string text = Request.Headers[RequestHeader.WebSocketKey];
			if (string.IsNullOrEmpty(text))
			{
				throw new InvalidOperationException("Missing or wrong " + Headers<RequestHeader>.GetHeaderName(RequestHeader.WebSocketKey) + " header in request.");
			}
			using SHA1 sHA = SHA1.Create();
			return Convert.ToBase64String(sHA.ComputeHash(Encoding.UTF8.GetBytes(text + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")));
		}

		public string GenerateClientNonce()
		{
			return Convert.ToBase64String(Guid.NewGuid().ToByteArray());
		}

		public int CompareTo(WebSocketHandshake other)
		{
			if (other == null)
			{
				return 1;
			}
			long id = Id;
			return id.CompareTo(other.Id);
		}

		public bool Equals(WebSocketHandshake other)
		{
			if (other == null)
			{
				return false;
			}
			if (this == other)
			{
				return true;
			}
			return Id == other.Id;
		}

		public override bool Equals(object obj)
		{
			return Equals(obj as WebSocketHandshake);
		}

		public override int GetHashCode()
		{
			long id = Id;
			return id.GetHashCode();
		}

		public override string ToString()
		{
			return $"Handshake, id: {Id}, request: {Request}, response: {Response}";
		}
	}
	internal class WebSocketHandshaker
	{
		private static readonly Version HttpVersion11 = new Version(1, 1);

		private static readonly Version HttpVersion10 = new Version(1, 0);

		private readonly ILogger log;

		private readonly WebSocketListenerOptions options;

		private readonly WebSocketFactoryCollection factories;

		public WebSocketHandshaker(WebSocketFactoryCollection factories, WebSocketListenerOptions options)
		{
			if (factories == null)
			{
				throw new ArgumentNullException("factories");
			}
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			log = options.Logger;
			this.factories = factories;
			this.options = options;
		}

		public async Task<WebSocketHandshake> HandshakeAsync(NetworkConnection networkConnection)
		{
			if (networkConnection == null)
			{
				throw new ArgumentNullException("networkConnection");
			}
			WebSocketHttpRequest request = new WebSocketHttpRequest(HttpRequestDirection.Incoming)
			{
				LocalEndPoint = (networkConnection.LocalEndPoint ?? WebSocketHttpRequest.NoAddress),
				RemoteEndPoint = (networkConnection.RemoteEndPoint ?? WebSocketHttpRequest.NoAddress),
				IsSecure = (networkConnection is SslNetworkConnection)
			};
			WebSocketHandshake handshake = new WebSocketHandshake(request);
			try
			{
				await ReadHttpRequestAsync(networkConnection, handshake).ConfigureAwait(continueOnCapturedContext: false);
				if (!IsWebSocketRequestValid(handshake))
				{
					await WriteHttpResponseAsync(handshake, networkConnection).ConfigureAwait(continueOnCapturedContext: false);
					return handshake;
				}
				handshake.IsWebSocketRequest = true;
				WebSocketFactory factory = null;
				if (!factories.TryGetWebSocketFactory(handshake.Request, out factory))
				{
					await WriteHttpResponseAsync(handshake, networkConnection).ConfigureAwait(continueOnCapturedContext: false);
					return handshake;
				}
				handshake.Factory = factory;
				handshake.IsVersionSupported = true;
				ConsolidateObjectModel(handshake);
				SelectExtensions(handshake);
				if (!(await RunHttpNegotiationHandlerAsync(handshake).ConfigureAwait(continueOnCapturedContext: false)))
				{
					throw new WebSocketException("HTTP authentication failed.");
				}
				await WriteHttpResponseAsync(handshake, networkConnection).ConfigureAwait(continueOnCapturedContext: false);
			}
			catch (Exception ex)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("Failed to handshake request.", ex);
				}
				handshake.Error = ExceptionDispatchInfo.Capture(ex);
				if (!handshake.IsResponseSent)
				{
					try
					{
						await WriteHttpResponseAsync(handshake, networkConnection).ConfigureAwait(continueOnCapturedContext: false);
					}
					catch (Exception error)
					{
						if (log.IsDebugEnabled)
						{
							log.Debug("Failed to write error response.", error);
						}
					}
				}
			}
			return handshake;
		}

		private static bool IsWebSocketRequestValid(WebSocketHandshake handShake)
		{
			if (handShake == null)
			{
				throw new ArgumentNullException("handShake");
			}
			Headers<RequestHeader> headers = handShake.Request.Headers;
			if (headers.Contains(RequestHeader.Host) && headers.Contains(RequestHeader.Upgrade) && headers.GetValues(RequestHeader.Upgrade).Contains("websocket", StringComparison.OrdinalIgnoreCase) && headers.Contains(RequestHeader.Connection) && !string.IsNullOrWhiteSpace(headers.Get(RequestHeader.WebSocketKey)))
			{
				return headers.Contains(RequestHeader.WebSocketVersion);
			}
			return false;
		}

		private async Task<bool> RunHttpNegotiationHandlerAsync(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (options.HttpAuthenticationHandler != null)
			{
				try
				{
					return await options.HttpAuthenticationHandler(handshake.Request, handshake.Response).ConfigureAwait(continueOnCapturedContext: false);
				}
				catch (Exception source)
				{
					handshake.Response.Status = HttpStatusCode.InternalServerError;
					handshake.Error = ExceptionDispatchInfo.Capture(source);
					return false;
				}
			}
			return true;
		}

		private void SelectExtensions(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			foreach (WebSocketExtension extRequest in handshake.Request.WebSocketExtensions)
			{
				IWebSocketMessageExtension webSocketMessageExtension = handshake.Factory.MessageExtensions.SingleOrDefault((IWebSocketMessageExtension x) => x.Name.Equals(extRequest.Name, StringComparison.OrdinalIgnoreCase));
				if (webSocketMessageExtension != null && webSocketMessageExtension.TryNegotiate(handshake.Request, out var extensionResponse, out var context))
				{
					handshake.NegotiatedMessageExtensions.Add(context);
					handshake.Response.WebSocketExtensions.Add(extensionResponse);
				}
			}
		}

		private async Task WriteHttpResponseAsync(WebSocketHandshake handshake, NetworkConnection networkConnection)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (networkConnection == null)
			{
				throw new ArgumentNullException("networkConnection");
			}
			if (handshake.IsWebSocketRequest || !handshake.IsValidHttpRequest || options.HttpFallback == null)
			{
				handshake.IsResponseSent = true;
				using StreamWriter writer = new StreamWriter(networkConnection.AsStream(), Encoding.ASCII, 1024, leaveOpen: true);
				await WriteResponseInternal(handshake, writer).ConfigureAwait(continueOnCapturedContext: false);
				await writer.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
			}
		}

		private async Task WriteResponseInternal(WebSocketHandshake handshake, StreamWriter writer)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (writer == null)
			{
				throw new ArgumentNullException("writer");
			}
			if (!handshake.IsWebSocketRequest)
			{
				handshake.Response.Status = HttpStatusCode.BadRequest;
				await SendNegotiationErrorResponseAsync(writer, handshake.Response.Status);
			}
			else if (!handshake.IsVersionSupported)
			{
				handshake.Response.Status = HttpStatusCode.UpgradeRequired;
				await SendVersionNegotiationErrorResponse(writer);
			}
			else if (handshake.IsValidWebSocketRequest)
			{
				await SendNegotiationResponse(handshake, writer);
			}
			else
			{
				handshake.Response.Status = ((handshake.Response.Status != HttpStatusCode.SwitchingProtocols) ? handshake.Response.Status : HttpStatusCode.BadRequest);
				await SendNegotiationErrorResponseAsync(writer, handshake.Response.Status);
			}
		}

		private async Task ReadHttpRequestAsync(NetworkConnection clientStream, WebSocketHandshake handshake)
		{
			if (clientStream == null)
			{
				throw new ArgumentNullException("clientStream");
			}
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			using StreamReader sr = new StreamReader(clientStream.AsStream(), Encoding.ASCII, detectEncodingFromByteOrderMarks: false, 1024, leaveOpen: true);
			ParseGET(await sr.ReadLineAsync(), handshake);
			string header;
			while (!string.IsNullOrWhiteSpace(header = await sr.ReadLineAsync()))
			{
				handshake.Request.Headers.TryParseAndAdd(header);
			}
			ParseCookies(handshake);
		}

		private void ParseGET(string line, WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (string.IsNullOrWhiteSpace(line))
			{
				throw new WebSocketException("Empty request line is received. Probably connection is closed.");
			}
			string[] array = line.Split(new char[1] { ' ' });
			if (!line.StartsWith("GET", StringComparison.Ordinal))
			{
				throw new WebSocketException($"Invalid request method '{array.FirstOrDefault() ?? line}' while 'GET' is expected.");
			}
			handshake.Request.RequestUri = new Uri(array[1], UriKind.Relative);
			string text = array[2];
			handshake.Request.HttpVersion = (text.EndsWith("1.1") ? HttpVersion11 : HttpVersion10);
		}

		private async Task SendNegotiationResponse(WebSocketHandshake handshake, StreamWriter writer)
		{
			await writer.WriteAsync("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n");
			if (handshake.Response.Cookies.Count > 0)
			{
				foreach (object cookie in handshake.Response.Cookies)
				{
					await writer.WriteAsync("Set-Cookie: ");
					await writer.WriteAsync(cookie.ToString());
					await writer.WriteAsync("\r\n");
				}
			}
			await writer.WriteAsync("Sec-WebSocket-Accept: ");
			await writer.WriteAsync(handshake.ComputeHandshake());
			if (handshake.Response.Headers.Contains(ResponseHeader.WebSocketProtocol))
			{
				await writer.WriteAsync("\r\nSec-WebSocket-Protocol: ");
				await writer.WriteAsync(handshake.Response.Headers[ResponseHeader.WebSocketProtocol]);
			}
			WriteHandshakeCookies(handshake, writer);
			await writer.WriteAsync("\r\n\r\n");
		}

		private static void WriteHandshakeCookies(WebSocketHandshake handshake, StreamWriter writer)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (writer == null)
			{
				throw new ArgumentNullException("writer");
			}
			if (!handshake.Response.WebSocketExtensions.Any())
			{
				return;
			}
			bool flag = true;
			bool flag2 = true;
			writer.Write("\r\nSec-WebSocket-Extensions: ");
			foreach (WebSocketExtension webSocketExtension in handshake.Response.WebSocketExtensions)
			{
				if (!flag)
				{
					writer.Write(",");
				}
				writer.Write(webSocketExtension.Name);
				IEnumerable<WebSocketExtensionOption> enumerable = webSocketExtension.Options.Where((WebSocketExtensionOption x) => !x.ClientAvailableOption);
				if (!webSocketExtension.Options.Any())
				{
					continue;
				}
				writer.Write(";");
				foreach (WebSocketExtensionOption item in enumerable)
				{
					if (!flag2)
					{
						writer.Write(";");
					}
					writer.Write(item.Name);
					if (item.Value != null)
					{
						writer.Write("=");
						writer.Write(item.Value);
					}
					flag2 = false;
				}
				flag = false;
			}
		}

		private async Task SendNegotiationErrorResponseAsync(StreamWriter writer, HttpStatusCode code)
		{
			if (writer == null)
			{
				throw new ArgumentNullException("writer");
			}
			await writer.WriteAsync($"HTTP/1.1 {(int)code} {HttpStatusDescription.Get(code)}\r\nConnection: close\r\n\r\n");
		}

		private async Task SendVersionNegotiationErrorResponse(StreamWriter writer)
		{
			await writer.WriteAsync("HTTP/1.1 426 Upgrade Required\r\nSec-WebSocket-Version: ");
			bool first = true;
			foreach (WebSocketFactory standard in factories)
			{
				if (!first)
				{
					await writer.WriteAsync(",");
				}
				first = false;
				await writer.WriteAsync(standard.Version.ToString());
			}
			await writer.WriteAsync("\r\n\r\n");
		}

		private void ConsolidateObjectModel(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			ParseWebSocketProtocol(handshake);
			ParseWebSocketExtensions(handshake);
		}

		private void ParseWebSocketProtocol(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (!options.SubProtocols.Any() || !handshake.Request.Headers.Contains(RequestHeader.WebSocketProtocol))
			{
				return;
			}
			foreach (string value in handshake.Request.Headers.GetValues(RequestHeader.WebSocketProtocol))
			{
				if (options.SubProtocols.Contains<string>(value, StringComparer.OrdinalIgnoreCase))
				{
					handshake.Response.Headers[ResponseHeader.WebSocketProtocol] = value;
					break;
				}
			}
		}

		private void ParseWebSocketExtensions(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			List<WebSocketExtension> list = new List<WebSocketExtension>();
			Headers<RequestHeader> headers = handshake.Request.Headers;
			if (headers.Contains(RequestHeader.WebSocketExtensions))
			{
				foreach (string value in headers.GetValues(RequestHeader.WebSocketExtensions))
				{
					List<WebSocketExtensionOption> list2 = new List<WebSocketExtensionOption>();
					string text = null;
					foreach (KeyValuePair<string, string> item in HeadersHelper.SplitAndTrimKeyValue(value, ';', '=', StringSplitOptions.RemoveEmptyEntries))
					{
						if (text == null)
						{
							text = item.Value;
						}
						else if (string.IsNullOrEmpty(item.Key))
						{
							list2.Add(new WebSocketExtensionOption(item.Value, clientAvailableOption: true));
						}
						else
						{
							list2.Add(new WebSocketExtensionOption(item.Key, item.Value));
						}
					}
					if (string.IsNullOrEmpty(text))
					{
						throw new WebSocketException("Wrong value '" + headers[RequestHeader.WebSocketExtensions] + "' of " + Headers<ResponseHeader>.GetHeaderName(ResponseHeader.WebSocketExtensions) + " header in request.");
					}
					list.Add(new WebSocketExtension(text, list2));
				}
			}
			handshake.Request.SetExtensions(list);
		}

		private void ParseCookies(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			string domain = handshake.Request.Headers[RequestHeader.Host];
			foreach (string value in handshake.Request.Headers.GetValues(RequestHeader.Cookie))
			{
				try
				{
					foreach (Cookie item in CookieParser.Parse(value))
					{
						item.Domain = domain;
						item.Path = string.Empty;
						handshake.Request.Cookies.Add(item);
					}
				}
				catch (Exception ex)
				{
					throw new WebSocketException("Cannot parse cookie string: '" + value + "' because: " + ex.Message);
				}
			}
		}
	}
	public sealed class WebSocketHttpRequest : IHttpRequest
	{
		public static readonly IPEndPoint NoAddress = new IPEndPoint(IPAddress.None, 0);

		public EndPoint LocalEndPoint { get; internal set; }

		public EndPoint RemoteEndPoint { get; internal set; }

		public Uri RequestUri { get; internal set; }

		public Version HttpVersion { get; internal set; }

		public bool IsSecure { get; internal set; }

		public CookieCollection Cookies { get; }

		public Headers<RequestHeader> Headers { get; }

		public IDictionary<string, object> Items { get; }

		public HttpRequestDirection Direction { get; }

		public IReadOnlyList<WebSocketExtension> WebSocketExtensions { get; private set; }

		public WebSocketHttpRequest(HttpRequestDirection direction)
		{
			Headers = new Headers<RequestHeader>();
			Cookies = new CookieCollection();
			Items = new Dictionary<string, object>();
			LocalEndPoint = NoAddress;
			RemoteEndPoint = NoAddress;
			Direction = direction;
		}

		internal void SetExtensions(List<WebSocketExtension> extensions)
		{
			if (extensions == null)
			{
				throw new ArgumentNullException("extensions");
			}
			WebSocketExtensions = new ReadOnlyCollection<WebSocketExtension>(extensions);
		}

		public override string ToString()
		{
			if (RequestUri != null)
			{
				return RequestUri.ToString();
			}
			return $"{LocalEndPoint}->{RemoteEndPoint}";
		}
	}
	public sealed class WebSocketHttpResponse
	{
		public readonly CookieCollection Cookies;

		public readonly Headers<ResponseHeader> Headers;

		public HttpStatusCode Status;

		public string StatusDescription;

		public readonly List<WebSocketExtension> WebSocketExtensions;

		public WebSocketHttpResponse()
		{
			Headers = new Headers<ResponseHeader>();
			Cookies = new CookieCollection();
			WebSocketExtensions = new List<WebSocketExtension>();
			Status = HttpStatusCode.SwitchingProtocols;
			StatusDescription = "Web Socket Protocol Handshake";
		}

		public void ThrowIfInvalid(string computedHandshake)
		{
			if (computedHandshake == null)
			{
				throw new ArgumentNullException("computedHandshake");
			}
			string b = Headers[ResponseHeader.Upgrade];
			if (!string.Equals("websocket", b, StringComparison.OrdinalIgnoreCase))
			{
				throw new WebSocketException("Missing or wrong " + Headers<ResponseHeader>.GetHeaderName(ResponseHeader.Upgrade) + " header in response.");
			}
			if (!Headers.GetValues(ResponseHeader.Connection).Contains("Upgrade", StringComparison.OrdinalIgnoreCase))
			{
				throw new WebSocketException("Missing or wrong " + Headers<ResponseHeader>.GetHeaderName(ResponseHeader.Connection) + " header in response.");
			}
			string b2 = Headers[ResponseHeader.WebSocketAccept];
			if (!string.Equals(computedHandshake, b2, StringComparison.OrdinalIgnoreCase))
			{
				throw new WebSocketException("Missing or wrong " + Headers<ResponseHeader>.GetHeaderName(ResponseHeader.WebSocketAccept) + " header in response.");
			}
		}

		public override string ToString()
		{
			return $"{Status} {StatusDescription}";
		}
	}
	public interface ILogger
	{
		bool IsDebugEnabled { get; }

		bool IsWarningEnabled { get; }

		bool IsErrorEnabled { get; }

		void Debug(string message, Exception error = null);

		void Warning(string message, Exception error = null);

		void Error(string message, Exception error = null);
	}
	public sealed class NullLogger : ILogger
	{
		public static readonly NullLogger Instance = new NullLogger();

		public bool IsDebugEnabled => false;

		public bool IsWarningEnabled => false;

		public bool IsErrorEnabled => false;

		public void Debug(string message, Exception error = null)
		{
		}

		public void Warning(string message, Exception error = null)
		{
		}

		public void Error(string message, Exception error = null)
		{
		}
	}
	public enum PingMode
	{
		Manual,
		LatencyControl,
		BandwidthSaving
	}
	public abstract class WebSocketMessageReadStream : WebSocketMessageStream
	{
		public abstract WebSocketMessageType MessageType { get; }

		public abstract WebSocketExtensionFlags Flags { get; }

		public sealed override bool CanRead => true;

		[Obsolete("Writing to the read stream is not allowed", true)]
		public sealed override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			throw new NotSupportedException();
		}
	}
	public abstract class WebSocketMessageStream : Stream
	{
		public override bool CanRead => false;

		public sealed override bool CanSeek => false;

		public override bool CanWrite => false;

		public sealed override long Length
		{
			get
			{
				throw new NotSupportedException();
			}
		}

		public sealed override long Position
		{
			get
			{
				throw new NotSupportedException();
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		internal abstract WebSocketListenerOptions Options { get; }

		public override Task FlushAsync(CancellationToken cancellationToken)
		{
			return TaskHelper.CompletedTask;
		}

		public abstract Task CloseAsync();

		public abstract override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);

		public abstract override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);

		public sealed override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0 || offset > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0 || offset + count > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			if (callback != null || state != null)
			{
				TaskCompletionSource<int> taskCompletionSource = new TaskCompletionSource<int>(state);
				ReadAsync(buffer, offset, count, CancellationToken.None).PropagateResultTo(taskCompletionSource);
				if (callback != null)
				{
					taskCompletionSource.Task.ContinueWith(delegate(Task<int> t, object s)
					{
						((AsyncCallback)s)(t);
					}, callback, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
				}
				return taskCompletionSource.Task;
			}
			return ReadAsync(buffer, offset, count, CancellationToken.None);
		}

		public sealed override int EndRead(IAsyncResult asyncResult)
		{
			return ((Task<int>)asyncResult).Result;
		}

		public sealed override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer");
			}
			if (offset < 0 || offset > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("offset");
			}
			if (count < 0 || offset + count > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("count");
			}
			if (callback != null || state != null)
			{
				TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>(state);
				WriteAsync(buffer, offset, count, CancellationToken.None).PropagateResultTo(taskCompletionSource);
				if (callback != null)
				{
					taskCompletionSource.Task.ContinueWith(delegate(Task<bool> t, object s)
					{
						((AsyncCallback)s)(t);
					}, callback, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
				}
				return taskCompletionSource.Task;
			}
			return WriteAsync(buffer, offset, count, CancellationToken.None);
		}

		public sealed override void EndWrite(IAsyncResult asyncResult)
		{
			((Task)asyncResult).Wait();
		}

		public sealed override long Seek(long offset, SeekOrigin origin)
		{
			throw new NotSupportedException();
		}

		public sealed override void SetLength(long value)
		{
			throw new NotSupportedException();
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use ReadAsync() instead.")]
		public sealed override int ReadByte()
		{
			throw new NotSupportedException();
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use ReadAsync() instead.")]
		public override int Read(byte[] buffer, int offset, int count)
		{
			return ReadAsync(buffer, offset, count, CancellationToken.None).Result;
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use WriteAsync() instead.")]
		public sealed override void WriteByte(byte value)
		{
			throw new NotSupportedException();
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use WriteAsync() instead.")]
		public override void Write(byte[] buffer, int offset, int count)
		{
			WriteAsync(buffer, offset, count).Wait();
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use FlushAsync() instead.")]
		public override void Flush()
		{
		}

		[Obsolete("Do not use synchronous IO operation on network streams. Use CloseAsync() instead.")]
		public override void Close()
		{
			base.Close();
		}
	}
	public abstract class WebSocketMessageWriteStream : WebSocketMessageStream
	{
		public sealed override bool CanWrite => true;

		[NotNull]
		public WebSocketExtensionFlags ExtensionFlags { get; }

		protected WebSocketMessageWriteStream()
		{
			ExtensionFlags = new WebSocketExtensionFlags();
		}

		[Obsolete("Reading from the write stream is not allowed", true)]
		public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
		{
			throw new NotSupportedException();
		}

		public abstract Task WriteAndCloseAsync([NotNull] byte[] buffer, int offset, int count, CancellationToken cancellationToken);
	}
	internal static class SafeEnd
	{
		public static void Dispose<T>([CanBeNull] T disposable, ILogger log = null) where T : class, IDisposable
		{
			if (log == null)
			{
				log = NullLogger.Instance;
			}
			try
			{
				disposable?.Dispose();
			}
			catch (Exception error)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug($"{typeof(T)} dispose cause error.", error);
				}
			}
		}

		public static void ReleaseSemaphore(SemaphoreSlim semaphore, ILogger log = null)
		{
			try
			{
				semaphore.Release();
			}
			catch (ObjectDisposedException)
			{
			}
			catch (Exception error)
			{
				if (log != null && log.IsDebugEnabled)
				{
					log.Debug("Semaphore release cause error.", error);
				}
			}
		}
	}
	[PublicAPI]
	public abstract class WebSocket : IDisposable
	{
		[NotNull]
		public WebSocketHttpRequest HttpRequest { get; }

		[NotNull]
		public WebSocketHttpResponse HttpResponse { get; }

		public abstract bool IsConnected { get; }

		public abstract EndPoint RemoteEndpoint { get; }

		public abstract EndPoint LocalEndpoint { get; }

		public abstract TimeSpan Latency { get; }

		public abstract string SubProtocol { get; }

		public abstract WebSocketCloseReason? CloseReason { get; }

		protected WebSocket([NotNull] WebSocketHttpRequest request, [NotNull] WebSocketHttpResponse response)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			if (response == null)
			{
				throw new ArgumentNullException("response");
			}
			HttpRequest = request;
			HttpResponse = response;
		}

		[NotNull]
		[ItemCanBeNull]
		public abstract Task<WebSocketMessageReadStream> ReadMessageAsync(CancellationToken token);

		[NotNull]
		public abstract WebSocketMessageWriteStream CreateMessageWriter(WebSocketMessageType messageType);

		public Task SendPingAsync()
		{
			return SendPingAsync(null, 0, 0);
		}

		public abstract Task SendPingAsync(byte[] data, int offset, int count);

		public abstract Task CloseAsync();

		public abstract Task CloseAsync(WebSocketCloseReason closeCode);

		public abstract void Dispose();

		public override string ToString()
		{
			return $"{GetType().Name}, remote: {RemoteEndpoint}, connected: {IsConnected}";
		}
	}
	[PublicAPI]
	public sealed class WebSocketClient
	{
		private const string WEB_SOCKET_HTTP_VERSION = "HTTP/1.1";

		private readonly ILogger log;

		private readonly AsyncConditionSource closeEvent;

		private readonly CancellationTokenSource workCancellationSource;

		private readonly WebSocketListenerOptions options;

		private readonly ConcurrentDictionary<WebSocketHandshake, Task<WebSocket>> pendingRequests;

		private readonly CancellationQueue negotiationsTimeoutQueue;

		private readonly PingQueue pingQueue;

		public bool HasPendingRequests => !pendingRequests.IsEmpty;

		public WebSocketClient([NotNull] WebSocketListenerOptions options)
		{
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			if (options.Standards.Count == 0)
			{
				throw new ArgumentException("Empty list of WebSocket standards.", "options");
			}
			options.CheckCoherence();
			this.options = options.Clone();
			this.options.SetUsed(isUsed: true);
			if (this.options.NegotiationTimeout > TimeSpan.Zero)
			{
				negotiationsTimeoutQueue = new CancellationQueue(this.options.NegotiationTimeout);
			}
			if (this.options.PingMode != 0)
			{
				pingQueue = new PingQueue(options.PingInterval);
			}
			log = this.options.Logger;
			closeEvent = new AsyncConditionSource(isSet: true)
			{
				ContinueOnCapturedContext = false
			};
			workCancellationSource = new CancellationTokenSource();
			pendingRequests = new ConcurrentDictionary<WebSocketHandshake, Task<WebSocket>>();
			if (this.options.BufferManager == null)
			{
				this.options.BufferManager = BufferManager.CreateBufferManager(this.options.SendBufferSize * 2 * 100, this.options.SendBufferSize * 2);
			}
			if (this.options.CertificateValidationHandler == null)
			{
				this.options.CertificateValidationHandler = ValidateRemoteCertificate;
			}
		}

		private bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
		{
			if (sslPolicyErrors == SslPolicyErrors.None)
			{
				return true;
			}
			if (log.IsWarningEnabled)
			{
				log.Warning($"Certificate validation error: {sslPolicyErrors}.");
			}
			return false;
		}

		public Task<WebSocket> ConnectAsync([NotNull] Uri address, CancellationToken cancellation = default(CancellationToken))
		{
			return ConnectAsync(address, null, cancellation);
		}

		public async Task<WebSocket> ConnectAsync([NotNull] Uri address, Headers<RequestHeader> requestHeaders = null, CancellationToken cancellation = default(CancellationToken))
		{
			_ = 1;
			try
			{
				cancellation.ThrowIfCancellationRequested();
				if (workCancellationSource.IsCancellationRequested)
				{
					throw new WebSocketException("Client is currently closing or closed.");
				}
				CancellationToken workCancellation = workCancellationSource.Token;
				CancellationToken negotiationCancellation = negotiationsTimeoutQueue?.GetSubscriptionList().Token ?? CancellationToken.None;
				if (cancellation.CanBeCanceled || workCancellation.CanBeCanceled || negotiationCancellation.CanBeCanceled)
				{
					cancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellation, workCancellation, negotiationCancellation).Token;
				}
				WebSocketHttpRequest webSocketHttpRequest = new WebSocketHttpRequest(HttpRequestDirection.Outgoing)
				{
					RequestUri = address
				};
				if (requestHeaders != null)
				{
					webSocketHttpRequest.Headers.AddMany(requestHeaders);
				}
				WebSocketHandshake handshake = new WebSocketHandshake(webSocketHttpRequest);
				Task<WebSocket> value = OpenConnectionAsync(handshake, cancellation);
				pendingRequests.TryAdd(handshake, value);
				WebSocket disposable = await value.IgnoreFaultOrCancellation().ConfigureAwait(continueOnCapturedContext: false);
				if (!workCancellation.IsCancellationRequested && negotiationCancellation.IsCancellationRequested)
				{
					SafeEnd.Dispose(disposable, log);
					throw new WebSocketException("Negotiation timeout.");
				}
				if (pendingRequests.TryRemove(handshake, out value) && workCancellationSource.IsCancellationRequested && pendingRequests.IsEmpty)
				{
					closeEvent.Set();
				}
				disposable = await value.ConfigureAwait(continueOnCapturedContext: false);
				pingQueue?.GetSubscriptionList().Add(disposable);
				return disposable;
			}
			catch (Exception exception) when (!(exception.Unwrap() is ThreadAbortException) && !(exception.Unwrap() is OperationCanceledException) && !(exception.Unwrap() is WebSocketException))
			{
				throw new WebSocketException($"An unknown error occurred while connection to '{address}'. More detailed information in inner exception.", exception.Unwrap());
			}
		}

		public async Task CloseAsync()
		{
			workCancellationSource.Cancel(throwOnFirstException: false);
			await closeEvent;
			SafeEnd.Dispose(pingQueue, log);
			SafeEnd.Dispose(negotiationsTimeoutQueue, log);
			SafeEnd.Dispose(workCancellationSource, log);
			options.SetUsed(isUsed: false);
		}

		private async Task<WebSocket> OpenConnectionAsync(WebSocketHandshake handshake, CancellationToken cancellation)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			NetworkConnection connection = null;
			WebSocket webSocket = null;
			try
			{
				cancellation.ThrowIfCancellationRequested();
				Uri requestUri = handshake.Request.RequestUri;
				WebSocketTransport transport = null;
				if (!options.Transports.TryGetWebSocketTransport(requestUri, out transport))
				{
					throw new WebSocketException($"Unable to find transport for '{requestUri}'. " + "Available transports are: " + string.Join(", ", options.Transports.SelectMany((WebSocketTransport t) => t.Schemes).Distinct()) + ".");
				}
				connection = await transport.ConnectAsync(requestUri, options, cancellation).ConfigureAwait(continueOnCapturedContext: false);
				handshake.Request.IsSecure = transport.ShouldUseSsl(requestUri);
				handshake.Request.LocalEndPoint = connection.LocalEndPoint ?? WebSocketHttpRequest.NoAddress;
				handshake.Request.RemoteEndPoint = connection.RemoteEndPoint ?? WebSocketHttpRequest.NoAddress;
				webSocket = await NegotiateRequestAsync(handshake, connection, cancellation).ConfigureAwait(continueOnCapturedContext: false);
				return webSocket;
			}
			finally
			{
				if (webSocket == null)
				{
					SafeEnd.Dispose(connection, log);
				}
			}
		}

		private async Task<WebSocket> NegotiateRequestAsync(WebSocketHandshake handshake, NetworkConnection connection, CancellationToken cancellation)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			if (connection == null)
			{
				throw new ArgumentNullException("connection");
			}
			cancellation.ThrowIfCancellationRequested();
			Stream stream = connection.AsStream();
			if (handshake.Request.IsSecure)
			{
				SslProtocols supportedSslProtocols = options.SupportedSslProtocols;
				string dnsSafeHost = handshake.Request.RequestUri.DnsSafeHost;
				SslStream secureStream = new SslStream(stream, leaveInnerStreamOpen: false, options.CertificateValidationHandler);
				await secureStream.AuthenticateAsClientAsync(dnsSafeHost, null, supportedSslProtocols, checkCertificateRevocation: false).ConfigureAwait(continueOnCapturedContext: false);
				connection = new SslNetworkConnection(secureStream, connection);
				stream = secureStream;
			}
			handshake.Factory = options.Standards.GetLast();
			await WriteRequestAsync(handshake, stream).ConfigureAwait(continueOnCapturedContext: false);
			cancellation.ThrowIfCancellationRequested();
			await ReadResponseAsync(handshake, stream).ConfigureAwait(continueOnCapturedContext: false);
			cancellation.ThrowIfCancellationRequested();
			if (await (options.HttpAuthenticationHandler?.Invoke(handshake.Request, handshake.Response) ?? Task.FromResult(result: false)).ConfigureAwait(continueOnCapturedContext: false))
			{
				throw new WebSocketException("HTTP authentication failed.");
			}
			return handshake.Factory.CreateWebSocket(connection, options, handshake.Request, handshake.Response, handshake.NegotiatedMessageExtensions);
		}

		private async Task WriteRequestAsync(WebSocketHandshake handshake, Stream stream)
		{
			Uri url = handshake.Request.RequestUri;
			string value2 = handshake.GenerateClientNonce();
			int largeBufferSize = options.BufferManager.LargeBufferSize;
			using StreamWriter writer = new StreamWriter(stream, Encoding.ASCII, largeBufferSize, leaveOpen: true);
			Headers<RequestHeader> requestHeaders = handshake.Request.Headers;
			requestHeaders[RequestHeader.Host] = url.DnsSafeHost;
			requestHeaders[RequestHeader.Upgrade] = "websocket";
			requestHeaders[RequestHeader.Connection] = "keep-alive, Upgrade";
			requestHeaders[RequestHeader.WebSocketKey] = value2;
			requestHeaders[RequestHeader.WebSocketVersion] = handshake.Factory.Version.ToString();
			requestHeaders[RequestHeader.CacheControl] = "no-cache";
			requestHeaders[RequestHeader.Pragma] = "no-cache";
			foreach (IWebSocketMessageExtension messageExtension in handshake.Factory.MessageExtensions)
			{
				requestHeaders.Add(RequestHeader.WebSocketExtensions, messageExtension.ToString());
			}
			string[] subProtocols = options.SubProtocols;
			foreach (string value3 in subProtocols)
			{
				requestHeaders.Add(RequestHeader.WebSocketProtocol, value3);
			}
			writer.NewLine = "\r\n";
			await writer.WriteAsync("GET ").ConfigureAwait(continueOnCapturedContext: false);
			await writer.WriteAsync(url.PathAndQuery).ConfigureAwait(continueOnCapturedContext: false);
			await writer.WriteLineAsync(" HTTP/1.1").ConfigureAwait(continueOnCapturedContext: false);
			foreach (KeyValuePair<string, Headers<RequestHeader>.ValueCollection> item in requestHeaders)
			{
				string headerName = item.Key;
				foreach (string value in item.Value)
				{
					await writer.WriteAsync(headerName).ConfigureAwait(continueOnCapturedContext: false);
					await writer.WriteAsync(": ").ConfigureAwait(continueOnCapturedContext: false);
					await writer.WriteLineAsync(value).ConfigureAwait(continueOnCapturedContext: false);
				}
			}
			await writer.WriteLineAsync().ConfigureAwait(continueOnCapturedContext: false);
			await writer.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
		}

		private async Task ReadResponseAsync(WebSocketHandshake handshake, Stream stream)
		{
			int largeBufferSize = options.BufferManager.LargeBufferSize;
			using (StreamReader reader = new StreamReader(stream, Encoding.ASCII, detectEncodingFromByteOrderMarks: false, largeBufferSize, leaveOpen: true))
			{
				Headers<ResponseHeader> responseHeaders = handshake.Response.Headers;
				string text = (await reader.ReadLineAsync().ConfigureAwait(continueOnCapturedContext: false)) ?? string.Empty;
				if (!HttpHelper.TryParseHttpResponse(text, out handshake.Response.Status, out handshake.Response.StatusDescription))
				{
					if (string.IsNullOrEmpty(text))
					{
						throw new WebSocketException("Empty response. Probably connection is closed by remote party.");
					}
					throw new WebSocketException("Invalid handshake response: " + text + ".");
				}
				if (handshake.Response.Status != HttpStatusCode.SwitchingProtocols)
				{
					throw new WebSocketException("Invalid handshake response: " + text + ".");
				}
				string text2 = await reader.ReadLineAsync().ConfigureAwait(continueOnCapturedContext: false);
				while (!string.IsNullOrEmpty(text2))
				{
					responseHeaders.TryParseAndAdd(text2);
					text2 = await reader.ReadLineAsync().ConfigureAwait(continueOnCapturedContext: false);
				}
				handshake.Response.ThrowIfInvalid(handshake.ComputeHandshake());
			}
			ParseWebSocketExtensions(handshake);
			SelectExtensions(handshake);
		}

		private void SelectExtensions(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			foreach (WebSocketExtension responseExtension in handshake.Response.WebSocketExtensions)
			{
				IWebSocketMessageExtension webSocketMessageExtension = handshake.Factory.MessageExtensions.SingleOrDefault((IWebSocketMessageExtension x) => x.Name.Equals(responseExtension.Name, StringComparison.OrdinalIgnoreCase));
				if (webSocketMessageExtension != null && webSocketMessageExtension.TryNegotiate(handshake.Request, out var _, out var context))
				{
					handshake.NegotiatedMessageExtensions.Add(context);
				}
			}
		}

		private void ParseWebSocketExtensions(WebSocketHandshake handshake)
		{
			if (handshake == null)
			{
				throw new ArgumentNullException("handshake");
			}
			Headers<ResponseHeader> headers = handshake.Response.Headers;
			if (!headers.Contains(ResponseHeader.WebSocketExtensions))
			{
				return;
			}
			foreach (string value in headers.GetValues(ResponseHeader.WebSocketExtensions))
			{
				List<WebSocketExtensionOption> list = new List<WebSocketExtensionOption>();
				string text = null;
				foreach (KeyValuePair<string, string> item in HeadersHelper.SplitAndTrimKeyValue(value, ';', '=', StringSplitOptions.RemoveEmptyEntries))
				{
					if (text == null)
					{
						text = item.Value;
					}
					else if (string.IsNullOrEmpty(item.Key))
					{
						list.Add(new WebSocketExtensionOption(item.Value, clientAvailableOption: true));
					}
					else
					{
						list.Add(new WebSocketExtensionOption(item.Key, item.Value));
					}
				}
				if (string.IsNullOrEmpty(text))
				{
					throw new WebSocketException("Wrong value '" + headers[ResponseHeader.WebSocketExtensions] + "' of " + Headers<ResponseHeader>.GetHeaderName(ResponseHeader.WebSocketExtensions) + " header in request.");
				}
				handshake.Response.WebSocketExtensions.Add(new WebSocketExtension(text, list));
			}
		}
	}
	public enum WebSocketCloseReason : short
	{
		NormalClose = 1000,
		GoingAway = 1001,
		ProtocolError = 1002,
		UnacceptableDataType = 1003,
		InvalidData = 1007,
		MessageViolatesPolicy = 1008,
		MessageToLarge = 1009,
		ExtensionRequired = 1010,
		UnexpectedCondition = 1011,
		TLSFailure = 105
	}
	public class WebSocketException : Exception
	{
		public WebSocketException(string message)
			: base(message)
		{
		}

		public WebSocketException(string message, Exception inner)
			: base(message, inner)
		{
		}
	}
	[PublicAPI]
	public abstract class WebSocketFactory
	{
		public abstract short Version { get; }

		public WebSocketMessageExtensionCollection MessageExtensions { get; private set; }

		protected WebSocketFactory()
		{
			MessageExtensions = new WebSocketMessageExtensionCollection();
		}

		public abstract WebSocket CreateWebSocket(NetworkConnection networkConnection, WebSocketListenerOptions options, WebSocketHttpRequest httpRequest, WebSocketHttpResponse httpResponse, List<IWebSocketMessageExtensionContext> negotiatedExtensions);

		public virtual WebSocketFactory Clone()
		{
			WebSocketFactory webSocketFactory = (WebSocketFactory)MemberwiseClone();
			webSocketFactory.MessageExtensions = new WebSocketMessageExtensionCollection();
			foreach (IWebSocketMessageExtension messageExtension in MessageExtensions)
			{
				webSocketFactory.MessageExtensions.Add(messageExtension.Clone());
			}
			return webSocketFactory;
		}
	}
	public sealed class WebSocketListener : IDisposable
	{
		private const int STATE_STOPPED = 0;

		private const int STATE_STARTING = 1;

		private const int STATE_STARTED = 2;

		private const int STATE_STOPPING = 3;

		private const int STATE_DISPOSED = 5;

		private static readonly Listener[] EmptyListeners = new Listener[0];

		private static readonly EndPoint[] EmptyEndPoints = new EndPoint[0];

		private readonly ILogger log;

		private readonly HttpNegotiationQueue negotiationQueue;

		private readonly WebSocketListenerOptions options;

		private readonly Uri[] listenEndPoints;

		private volatile AsyncConditionSource stopConditionSource;

		private volatile Listener[] listeners;

		private volatile EndPoint[] localEndPoints;

		private volatile int state;

		public bool IsStarted => state == 2;

		public IReadOnlyCollection<EndPoint> LocalEndpoints => (IReadOnlyCollection<EndPoint>)(object)localEndPoints;

		public WebSocketListener(IPEndPoint endpoint)
			: this(endpoint, new WebSocketListenerOptions())
		{
		}

		public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
			: this(new Uri[1]
			{
				new Uri("tcp://" + endpoint)
			}, options)
		{
		}

		public WebSocketListener(Uri[] listenEndPoints, WebSocketListenerOptions options)
		{
			if (listenEndPoints == null)
			{
				throw new ArgumentNullException("listenEndPoints");
			}
			if (listenEndPoints.Length == 0)
			{
				throw new ArgumentException("At least one prefix should be specified.", "listenEndPoints");
			}
			if (listenEndPoints.Any((Uri p) => p == null))
			{
				throw new ArgumentException("Null objects passed in array.", "listenEndPoints");
			}
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			options.CheckCoherence();
			this.options = options.Clone();
			if (this.options.BufferManager == null)
			{
				this.options.BufferManager = BufferManager.CreateBufferManager(this.options.SendBufferSize * 100, this.options.SendBufferSize);
			}
			if (this.options.Logger == null)
			{
				this.options.Logger = NullLogger.Instance;
			}
			log = this.options.Logger;
			listeners = EmptyListeners;
			localEndPoints = EmptyEndPoints;
			this.listenEndPoints = listenEndPoints;
			negotiationQueue = new HttpNegotiationQueue(options.Standards, options.ConnectionExtensions, this.options);
		}

		public async Task StartAsync()
		{
			if (options.Standards.Count <= 0)
			{
				throw new WebSocketException("There are no WebSocket standards. Please, register standards using WebSocketListenerOptions.Standards.");
			}
			if (options.Transports.Count <= 0)
			{
				throw new WebSocketException("There are no WebSocket transports. Please, register transports using WebSocketListenerOptions.Transports.");
			}
			if (Interlocked.CompareExchange(ref state, 1, 0) != 0)
			{
				throw new WebSocketException("Failed to start listener from current state. Maybe it is disposed or already started.");
			}
			options.SetUsed(isUsed: true);
			Listener[] listeners = null;
			try
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("WebSocketListener is starting.");
				}
				Tuple<Uri, WebSocketTransport>[] endPoints = new Tuple<Uri, WebSocketTransport>[listenEndPoints.Length];
				for (int j = 0; j < listenEndPoints.Length; j++)
				{
					Uri uri = listenEndPoints[j];
					WebSocketTransport transport = null;
					if (!options.Transports.TryGetWebSocketTransport(uri, out transport))
					{
						string arg = string.Join(", ", options.Transports.SelectMany((WebSocketTransport t) => t.Schemes).Distinct());
						throw new WebSocketException($"Unable to find transport for '{uri}'. Available transports are: {arg}.");
					}
					endPoints[j] = Tuple.Create(uri, transport);
				}
				listeners = new Listener[endPoints.Length];
				for (int i = 0; i < endPoints.Length; i++)
				{
					Listener[] array = listeners;
					int num = i;
					array[num] = await endPoints[i].Item2.ListenAsync(endPoints[i].Item1, options).ConfigureAwait(continueOnCapturedContext: false);
				}
				this.listeners = listeners;
				localEndPoints = this.listeners.SelectMany((Listener l) => l.LocalEndpoints).ToArray();
				stopConditionSource = new AsyncConditionSource(isSet: true)
				{
					ContinueOnCapturedContext = false
				};
				if (Interlocked.CompareExchange(ref state, 2, 1) != 1)
				{
					throw new WebSocketException("Failed to start listener from current state. Maybe it is disposed.");
				}
				AcceptConnectionsAsync().LogFault(log, null, "StartAsync", "D:\\dev\\projects\\vtortola.WebSocketListener\\vtortola.WebSockets\\WebSocketListener.cs", 117);
				if (log.IsDebugEnabled)
				{
					log.Debug("WebSocketListener is started.");
				}
				listeners = null;
			}
			catch
			{
				options.SetUsed(isUsed: false);
				throw;
			}
			finally
			{
				Interlocked.CompareExchange(ref state, 0, 1);
				if (listeners != null)
				{
					Listener[] array2 = listeners;
					for (int k = 0; k < array2.Length; k++)
					{
						SafeEnd.Dispose(array2[k]);
					}
					this.listeners = EmptyListeners;
					localEndPoints = EmptyEndPoints;
					stopConditionSource = null;
				}
			}
		}

		public async Task StopAsync()
		{
			if (Interlocked.CompareExchange(ref state, 3, 2) != 2)
			{
				throw new WebSocketException("Failed to stop listener from current state. Maybe it is disposed or not started.");
			}
			options.SetUsed(isUsed: false);
			AsyncConditionSource asyncConditionSource = stopConditionSource;
			if (log.IsDebugEnabled)
			{
				log.Debug("WebSocketListener is stopping.");
			}
			localEndPoints = EmptyEndPoints;
			Listener[] array = Interlocked.Exchange(ref listeners, EmptyListeners);
			for (int i = 0; i < array.Length; i++)
			{
				SafeEnd.Dispose(array[i], log);
			}
			if (asyncConditionSource != null)
			{
				await asyncConditionSource;
			}
			if (Interlocked.CompareExchange(ref state, 0, 3) != 3)
			{
				throw new WebSocketException("Failed to stop listener from current state. Maybe it is disposed.");
			}
			if (log.IsDebugEnabled)
			{
				log.Debug("WebSocketListener is stopped.");
			}
		}

		private async Task AcceptConnectionsAsync()
		{
			await Task.Yield();
			Listener[] listeners = this.listeners;
			Task<NetworkConnection>[] acceptTasks = new Task<NetworkConnection>[listeners.Length];
			int acceptOffset = 0;
			try
			{
				while (IsStarted)
				{
					for (int i = 0; i < acceptTasks.Length; i++)
					{
						if (acceptTasks[i] == null)
						{
							try
							{
								acceptTasks[i] = listeners[i].AcceptConnectionAsync();
							}
							catch (Exception ex) when (!(ex is ThreadAbortException))
							{
								acceptTasks[i] = TaskHelper.FailedTask<NetworkConnection>(ex);
							}
						}
					}
					await Task.WhenAny(acceptTasks).ConfigureAwait(continueOnCapturedContext: false);
					if (acceptOffset == 65535)
					{
						acceptOffset = 0;
					}
					acceptOffset++;
					for (int j = 0; j < acceptTasks.Length; j++)
					{
						int num = (acceptOffset + j) % acceptTasks.Length;
						Task<NetworkConnection> task = acceptTasks[num];
						if (task != null && task.IsCompleted)
						{
							acceptTasks[num] = null;
							AcceptNewConnection(task, listeners[num]);
						}
					}
				}
			}
			finally
			{
				CleanupPendingConnections(acceptTasks);
			}
		}

		private void CleanupPendingConnections(Task<NetworkConnection>[] acceptTasks)
		{
			if (acceptTasks == null)
			{
				throw new ArgumentNullException("acceptTasks");
			}
			for (int i = 0; i < acceptTasks.Length; i++)
			{
				acceptTasks[i]?.ContinueWith(delegate(Task<NetworkConnection> t)
				{
					SafeEnd.Dispose(t.Result, log);
				}, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Current).LogFault(log, null, "CleanupPendingConnections", "D:\\dev\\projects\\vtortola.WebSocketListener\\vtortola.WebSockets\\WebSocketListener.cs", 234);
			}
			Array.Clear(acceptTasks, 0, acceptTasks.Length);
		}

		private void AcceptNewConnection(Task<NetworkConnection> acceptTask, Listener listener)
		{
			if (acceptTask == null)
			{
				throw new ArgumentNullException("acceptTask");
			}
			if (listener == null)
			{
				throw new ArgumentNullException("listener");
			}
			Exception ex = acceptTask.Exception.Unwrap();
			if (acceptTask.Status != TaskStatus.RanToCompletion)
			{
				if (log.IsDebugEnabled && ex != null && !(ex is OperationCanceledException))
				{
					log.Debug($"Accept from '{listener}' has failed.", ex);
				}
				return;
			}
			NetworkConnection result = acceptTask.Result;
			if (log.IsDebugEnabled)
			{
				log.Debug($"New client from '{result}' is connected.");
			}
			negotiationQueue.Queue(result);
		}

		public async Task<WebSocket> AcceptWebSocketAsync(CancellationToken token)
		{
			try
			{
				WebSocketNegotiationResult webSocketNegotiationResult = await negotiationQueue.DequeueAsync(token).ConfigureAwait(continueOnCapturedContext: false);
				if (webSocketNegotiationResult.Error != null)
				{
					if (log.IsDebugEnabled && !(webSocketNegotiationResult.Error.SourceException.Unwrap() is OperationCanceledException))
					{
						log.Debug("AcceptWebSocketAsync is complete with error.", webSocketNegotiationResult.Error.SourceException);
					}
					webSocketNegotiationResult.Error.Throw();
					return null;
				}
				return webSocketNegotiationResult.Result;
			}
			catch (OperationCanceledException)
			{
				return null;
			}
		}

		public void Dispose()
		{
			if (Interlocked.Exchange(ref state, 5) != 5)
			{
				stopConditionSource?.Set();
				localEndPoints = EmptyEndPoints;
				Listener[] array = Interlocked.Exchange(ref listeners, EmptyListeners);
				for (int i = 0; i < array.Length; i++)
				{
					SafeEnd.Dispose(array[i], log);
				}
				SafeEnd.Dispose(negotiationQueue, log);
			}
		}
	}
	[PublicAPI]
	public sealed class WebSocketListenerOptions
	{
		public const int DEFAULT_SEND_BUFFER_SIZE = 8192;

		public static readonly string[] NoSubProtocols = new string[0];

		[NotNull]
		public WebSocketTransportCollection Transports { get; private set; }

		[NotNull]
		public WebSocketFactoryCollection Standards { get; private set; }

		[NotNull]
		public WebSocketConnectionExtensionCollection ConnectionExtensions { get; private set; }

		public TimeSpan PingTimeout { get; set; }

		public TimeSpan PingInterval
		{
			get
			{
				if (!(PingTimeout > TimeSpan.Zero))
				{
					return TimeSpan.FromSeconds(5.0);
				}
				return TimeSpan.FromTicks(PingTimeout.Ticks / 3);
			}
		}

		public int NegotiationQueueCapacity { get; set; }

		public int ParallelNegotiations { get; set; }

		public TimeSpan NegotiationTimeout { get; set; }

		public int SendBufferSize { get; set; }

		public string[] SubProtocols { get; set; }

		public BufferManager BufferManager { get; set; }

		public HttpAuthenticationCallback HttpAuthenticationHandler { get; set; }

		public RemoteCertificateValidationCallback CertificateValidationHandler { get; set; }

		public SslProtocols SupportedSslProtocols { get; set; }

		public PingMode PingMode { get; set; }

		public IHttpFallback HttpFallback { get; set; }

		public ILogger Logger { get; set; }

		public WebSocketListenerOptions()
		{
			PingTimeout = TimeSpan.FromSeconds(5.0);
			Transports = new WebSocketTransportCollection();
			Standards = new WebSocketFactoryCollection();
			ConnectionExtensions = new WebSocketConnectionExtensionCollection();
			NegotiationQueueCapacity = Environment.ProcessorCount * 10;
			ParallelNegotiations = Environment.ProcessorCount * 2;
			NegotiationTimeout = TimeSpan.FromSeconds(5.0);
			SendBufferSize = 8192;
			SubProtocols = NoSubProtocols;
			HttpAuthenticationHandler = null;
			CertificateValidationHandler = null;
			PingMode = PingMode.LatencyControl;
			SupportedSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
			Logger = NullLogger.Instance;
		}

		public void CheckCoherence()
		{
			if (PingTimeout <= TimeSpan.Zero)
			{
				PingTimeout = Timeout.InfiniteTimeSpan;
			}
			if (PingTimeout <= TimeSpan.FromSeconds(1.0))
			{
				PingTimeout = TimeSpan.FromSeconds(1.0);
			}
			if (NegotiationQueueCapacity < 0)
			{
				throw new WebSocketException(string.Format("{0} must be 0 or more. Actual value: {1}", "NegotiationQueueCapacity", NegotiationQueueCapacity));
			}
			if (ParallelNegotiations < 1)
			{
				throw new WebSocketException(string.Format("{0} cannot be less than 1. Actual value: {1}", "ParallelNegotiations", ParallelNegotiations));
			}
			if (NegotiationTimeout == TimeSpan.Zero)
			{
				NegotiationTimeout = Timeout.InfiniteTimeSpan;
			}
			if (SendBufferSize < 1024)
			{
				t

plugins/System.Runtime.CompilerServices.Unsafe.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.0.0.0")]
[assembly: AssemblyTitle("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyDescription("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: CLSCompliant(false)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("4.0.4.1")]
namespace System.Runtime.CompilerServices
{
	public static class Unsafe
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static T Read<T>(void* source)
		{
			return Unsafe.Read<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static T ReadUnaligned<T>(void* source)
		{
			return Unsafe.ReadUnaligned<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static T ReadUnaligned<T>(ref byte source)
		{
			return Unsafe.ReadUnaligned<T>(ref source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Write<T>(void* destination, T value)
		{
			Unsafe.Write(destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void WriteUnaligned<T>(void* destination, T value)
		{
			Unsafe.WriteUnaligned(destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void WriteUnaligned<T>(ref byte destination, T value)
		{
			Unsafe.WriteUnaligned(ref destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Copy<T>(void* destination, ref T source)
		{
			Unsafe.Write(destination, source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Copy<T>(ref T destination, void* source)
		{
			destination = Unsafe.Read<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* AsPointer<T>(ref T value)
		{
			return Unsafe.AsPointer(ref value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static int SizeOf<T>()
		{
			return Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void CopyBlock(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(destination, source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void CopyBlock(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(ref destination, ref source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void CopyBlockUnaligned(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(destination, source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void CopyBlockUnaligned(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(ref destination, ref source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void InitBlock(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void InitBlock(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(ref startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void InitBlockUnaligned(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(ref startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static T As<T>(object o) where T : class
		{
			return (T)o;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static ref T AsRef<T>(void* source)
		{
			return ref *(T*)source;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T AsRef<T>(in T source)
		{
			return ref source;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref TTo As<TFrom, TTo>(ref TFrom source)
		{
			return ref Unsafe.As<TFrom, TTo>(ref source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Add<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* Add<T>(void* source, int elementOffset)
		{
			return (byte*)source + (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Add<T>(ref T source, IntPtr elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T AddByteOffset<T>(ref T source, IntPtr byteOffset)
		{
			return ref Unsafe.AddByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Subtract<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* Subtract<T>(void* source, int elementOffset)
		{
			return (byte*)source - (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Subtract<T>(ref T source, IntPtr elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T SubtractByteOffset<T>(ref T source, IntPtr byteOffset)
		{
			return ref Unsafe.SubtractByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static IntPtr ByteOffset<T>(ref T origin, ref T target)
		{
			return Unsafe.ByteOffset(target: ref target, origin: ref origin);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool AreSame<T>(ref T left, ref T right)
		{
			return Unsafe.AreSame(ref left, ref right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool IsAddressGreaterThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressGreaterThan(ref left, ref right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool IsAddressLessThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressLessThan(ref left, ref right);
		}
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
	internal sealed class NonVersionableAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}

plugins/System.Runtime.Serialization.dll

Decompiled 2 years ago
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.XPath;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Runtime.Serialization.dll")]
[assembly: AssemblyDescription("System.Runtime.Serialization.dll")]
[assembly: AssemblyDefaultAlias("System.Runtime.Serialization.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.0.30319.17020")]
[assembly: AssemblyFileVersion("4.0.30319.17020")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../silverlight.pub")]
[assembly: CompilationRelaxations(8)]
[assembly: ComVisible(false)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.0.0")]
[module: UnverifiableCode]
internal static class SR
{
	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string GetString(string name, params object[] args)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string GetString(CultureInfo culture, string name, params object[] args)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string GetString(string name)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string GetString(CultureInfo culture, string name)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string Format(string resourceFormat, params object[] args)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string Format(string resourceFormat, object p1)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string Format(string resourceFormat, object p1, object p2)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	internal static string Format(string resourceFormat, object p1, object p2, object p3)
	{
		throw null;
	}
}
namespace System
{
	internal static class LocalAppContextSwitches
	{
		public static readonly bool DoNotUseTimeZoneInfo;

		public static readonly bool DoNotUseEcmaScriptV6EscapeControlCharacter;

		[MethodImpl(MethodImplOptions.NoInlining)]
		static LocalAppContextSwitches()
		{
			throw null;
		}
	}
}
namespace System.Xml
{
	internal abstract class ArrayHelper<TArgument, TArray>
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TArray[] ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, int maxArrayLength)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, XmlDictionaryReader reader)
		{
			throw null;
		}

		protected abstract int ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);

		protected abstract void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected ArrayHelper()
		{
			throw null;
		}
	}
	internal class BooleanArrayHelperWithString : ArrayHelper<string, bool>
	{
		public static readonly BooleanArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, bool[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, bool[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public BooleanArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static BooleanArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class BooleanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, bool>
	{
		public static readonly BooleanArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, bool[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public BooleanArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static BooleanArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class Int16ArrayHelperWithString : ArrayHelper<string, short>
	{
		public static readonly Int16ArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, short[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, short[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int16ArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int16ArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class Int16ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, short>
	{
		public static readonly Int16ArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, short[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, short[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int16ArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int16ArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class Int32ArrayHelperWithString : ArrayHelper<string, int>
	{
		public static readonly Int32ArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, int[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, int[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int32ArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int32ArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class Int32ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, int>
	{
		public static readonly Int32ArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, int[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, int[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int32ArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int32ArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class Int64ArrayHelperWithString : ArrayHelper<string, long>
	{
		public static readonly Int64ArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, long[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, long[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int64ArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int64ArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class Int64ArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, long>
	{
		public static readonly Int64ArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, long[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, long[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Int64ArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static Int64ArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class SingleArrayHelperWithString : ArrayHelper<string, float>
	{
		public static readonly SingleArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, float[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, float[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public SingleArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static SingleArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class SingleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, float>
	{
		public static readonly SingleArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, float[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public SingleArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static SingleArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class DoubleArrayHelperWithString : ArrayHelper<string, double>
	{
		public static readonly DoubleArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, double[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, double[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DoubleArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DoubleArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class DoubleArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, double>
	{
		public static readonly DoubleArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, double[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DoubleArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DoubleArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class DecimalArrayHelperWithString : ArrayHelper<string, decimal>
	{
		public static readonly DecimalArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, decimal[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, decimal[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DecimalArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DecimalArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class DecimalArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, decimal>
	{
		public static readonly DecimalArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, decimal[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DecimalArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DecimalArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class DateTimeArrayHelperWithString : ArrayHelper<string, DateTime>
	{
		public static readonly DateTimeArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, DateTime[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, DateTime[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DateTimeArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DateTimeArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class DateTimeArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, DateTime>
	{
		public static readonly DateTimeArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, DateTime[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DateTimeArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static DateTimeArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class GuidArrayHelperWithString : ArrayHelper<string, Guid>
	{
		public static readonly GuidArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, Guid[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, Guid[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public GuidArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static GuidArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class GuidArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, Guid>
	{
		public static readonly GuidArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public GuidArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static GuidArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class TimeSpanArrayHelperWithString : ArrayHelper<string, TimeSpan>
	{
		public static readonly TimeSpanArrayHelperWithString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, string localName, string namespaceUri, TimeSpan[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TimeSpanArrayHelperWithString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static TimeSpanArrayHelperWithString()
		{
			throw null;
		}
	}
	internal class TimeSpanArrayHelperWithDictionaryString : ArrayHelper<XmlDictionaryString, TimeSpan>
	{
		public static readonly TimeSpanArrayHelperWithDictionaryString Instance;

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected override void WriteArray(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, TimeSpan[] array, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TimeSpanArrayHelperWithDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static TimeSpanArrayHelperWithDictionaryString()
		{
			throw null;
		}
	}
	internal class EncodingStreamWrapper : Stream
	{
		private enum SupportedEncoding
		{
			UTF8,
			UTF16LE,
			UTF16BE,
			None
		}

		private static readonly UTF8Encoding SafeUTF8;

		private static readonly UnicodeEncoding SafeUTF16;

		private static readonly UnicodeEncoding SafeBEUTF16;

		private static readonly UTF8Encoding ValidatingUTF8;

		private static readonly UnicodeEncoding ValidatingUTF16;

		private static readonly UnicodeEncoding ValidatingBEUTF16;

		private const int BufferLength = 128;

		private static readonly byte[] encodingAttr;

		private static readonly byte[] encodingUTF8;

		private static readonly byte[] encodingUnicode;

		private static readonly byte[] encodingUnicodeLE;

		private static readonly byte[] encodingUnicodeBE;

		private SupportedEncoding encodingCode;

		private Encoding encoding;

		private Encoder enc;

		private Decoder dec;

		private bool isReading;

		private Stream stream;

		private char[] chars;

		private byte[] bytes;

		private int byteOffset;

		private int byteCount;

		private byte[] byteBuffer;

		public override bool CanRead
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool CanSeek
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool CanWrite
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override long Position
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public override bool CanTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override long Length
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override int ReadTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public override int WriteTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public EncodingStreamWrapper(Stream stream, Encoding encoding)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SetReadDocumentEncoding(SupportedEncoding e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Encoding GetEncoding(SupportedEncoding e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Encoding GetSafeEncoding(SupportedEncoding e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static string GetEncodingName(SupportedEncoding enc)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static SupportedEncoding GetSupportedEncoding(Encoding encoding)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public EncodingStreamWrapper(Stream stream, Encoding encoding, bool emitBOM)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private SupportedEncoding ReadBOMEncoding(bool notOutOfBand)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static SupportedEncoding ReadBOMEncoding(byte b1, byte b2, byte b3, byte b4, bool notOutOfBand, out int preserve)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void FillBuffer(int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void EnsureBuffers()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void EnsureByteBuffer()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void CheckUTF8DeclarationEncoding(byte[] buffer, int offset, int count, SupportedEncoding e, SupportedEncoding expectedEnc)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool CompareCaseInsensitive(byte[] key, byte[] buffer, int offset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool Compare(byte[] key, byte[] buffer, int offset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool IsWhitespace(byte ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static ArraySegment<byte> ProcessBuffer(byte[] buffer, int offset, int count, Encoding encoding)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowExpectedEncodingMismatch(SupportedEncoding expEnc, SupportedEncoding actualEnc)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowEncodingMismatch(string declEnc, SupportedEncoding enc)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void ThrowEncodingMismatch(string declEnc, string docEnc)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Close()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Flush()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadByte()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int Read(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void CleanupCharBreak()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override long Seek(long offset, SeekOrigin origin)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteByte(byte b)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Write(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void SetLength(long value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static EncodingStreamWrapper()
		{
			throw null;
		}
	}
	public interface IFragmentCapableXmlDictionaryWriter
	{
		bool CanFragment { get; }

		void StartFragment(Stream stream, bool generateSelfContainedTextFragment);

		void EndFragment();

		void WriteFragment(byte[] buffer, int offset, int count);
	}
	public interface IStreamProvider
	{
		Stream GetStream();

		void ReleaseStream(Stream stream);
	}
	public interface IXmlDictionary
	{
		bool TryLookup(string value, out XmlDictionaryString result);

		bool TryLookup(int key, out XmlDictionaryString result);

		bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result);
	}
	internal enum PrefixHandleType
	{
		Empty,
		A,
		B,
		C,
		D,
		E,
		F,
		G,
		H,
		I,
		J,
		K,
		L,
		M,
		N,
		O,
		P,
		Q,
		R,
		S,
		T,
		U,
		V,
		W,
		X,
		Y,
		Z,
		Buffer,
		Max
	}
	internal class PrefixHandle
	{
		private XmlBufferReader bufferReader;

		private PrefixHandleType type;

		private int offset;

		private int length;

		private static string[] prefixStrings;

		private static byte[] prefixBuffer;

		public bool IsEmpty
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public bool IsXmlns
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public bool IsXml
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public PrefixHandle(XmlBufferReader bufferReader)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(PrefixHandleType type)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(PrefixHandle prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(int offset, int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryGetShortPrefix(out PrefixHandleType type)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static string GetString(PrefixHandleType type)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static PrefixHandleType GetAlphaPrefix(int index)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static byte[] GetString(PrefixHandleType type, out int offset, out int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetString(XmlNameTable nameTable)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public byte[] GetString(out int offset, out int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public int CompareTo(PrefixHandle that)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(PrefixHandle prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(string prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(XmlDictionaryString prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(PrefixHandle prefix1, string prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(PrefixHandle prefix1, string prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(PrefixHandle prefix1, XmlDictionaryString prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(PrefixHandle prefix1, XmlDictionaryString prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(PrefixHandle prefix1, PrefixHandle prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(PrefixHandle prefix1, PrefixHandle prefix2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool Equals(object obj)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ToString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int GetHashCode()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static PrefixHandle()
		{
			throw null;
		}
	}
	internal enum StringHandleConstStringType
	{
		Type,
		Root,
		Item
	}
	internal class StringHandle
	{
		private enum StringHandleType
		{
			Dictionary,
			UTF8,
			EscapedUTF8,
			ConstString
		}

		private XmlBufferReader bufferReader;

		private StringHandleType type;

		private int key;

		private int offset;

		private int length;

		private static string[] constStrings;

		public bool IsEmpty
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public bool IsXmlns
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public StringHandle(XmlBufferReader bufferReader)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(int offset, int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetConstantValue(StringHandleConstStringType constStringType)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(int offset, int length, bool escaped)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(int key)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(StringHandle value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void ToPrefixHandle(PrefixHandle prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetString(XmlNameTable nameTable)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public byte[] GetString(out int offset, out int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryGetDictionaryString(out XmlDictionaryString value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ToString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(int key2, XmlBufferReader bufferReader2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(XmlDictionaryString xmlString2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(string s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals2(StringHandle s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(StringHandle s1, XmlDictionaryString xmlString2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(StringHandle s1, XmlDictionaryString xmlString2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(StringHandle s1, string s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(StringHandle s1, string s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(StringHandle s1, StringHandle s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(StringHandle s1, StringHandle s2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public int CompareTo(StringHandle that)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool Equals(object obj)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int GetHashCode()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static StringHandle()
		{
			throw null;
		}
	}
	public class UniqueId
	{
		private long idLow;

		private long idHigh;

		[SecurityCritical]
		private string s;

		private const int guidLength = 16;

		private const int uuidLength = 45;

		private static short[] char2val;

		private const string val2char = "0123456789abcdef";

		public int CharArrayLength
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			[SecuritySafeCritical]
			get
			{
				throw null;
			}
		}

		public bool IsGuid
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public UniqueId()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public UniqueId(Guid guid)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public UniqueId(byte[] guid)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public UniqueId(byte[] guid, int offset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public UniqueId(string value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public UniqueId(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe int UnsafeDecode(short* char2val, char ch1, char ch2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe void UnsafeEncode(char* val2char, byte b, char* pch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe void UnsafeParse(char* chars, int charCount)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public int ToCharArray(char[] chars, int offset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryGetGuid(out Guid guid)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public bool TryGetGuid(byte[] buffer, int offset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecuritySafeCritical]
		public override string ToString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(UniqueId id1, UniqueId id2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(UniqueId id1, UniqueId id2)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool Equals(object obj)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int GetHashCode()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe long UnsafeGetInt64(byte* pb)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe int UnsafeGetInt32(byte* pb)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe void UnsafeSetInt64(long value, byte* pb)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[SecurityCritical]
		private unsafe void UnsafeSetInt32(int value, byte* pb)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static UniqueId()
		{
			throw null;
		}
	}
	internal enum ValueHandleConstStringType
	{
		String,
		Number,
		Array,
		Object,
		Boolean,
		Null
	}
	internal static class ValueHandleLength
	{
		public const int Int8 = 1;

		public const int Int16 = 2;

		public const int Int32 = 4;

		public const int Int64 = 8;

		public const int UInt64 = 8;

		public const int Single = 4;

		public const int Double = 8;

		public const int Decimal = 16;

		public const int DateTime = 8;

		public const int TimeSpan = 8;

		public const int Guid = 16;

		public const int UniqueId = 16;
	}
	internal enum ValueHandleType
	{
		Empty,
		True,
		False,
		Zero,
		One,
		Int8,
		Int16,
		Int32,
		Int64,
		UInt64,
		Single,
		Double,
		Decimal,
		DateTime,
		TimeSpan,
		Guid,
		UniqueId,
		UTF8,
		EscapedUTF8,
		Base64,
		Dictionary,
		List,
		Char,
		Unicode,
		QName,
		ConstString
	}
	internal class ValueHandle
	{
		private XmlBufferReader bufferReader;

		private ValueHandleType type;

		private int offset;

		private int length;

		private static Base64Encoding base64Encoding;

		private static string[] constStrings;

		private static Base64Encoding Base64Encoding
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public ValueHandle(XmlBufferReader bufferReader)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetConstantValue(ValueHandleConstStringType constStringType)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(ValueHandleType type)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetDictionaryValue(int key)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetCharValue(int ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetQNameValue(int prefix, int key)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetValue(ValueHandleType type, int offset, int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool IsWhitespace()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Type ToType()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool ToBoolean()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public int ToInt()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public long ToLong()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public ulong ToULong()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public float ToSingle()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public double ToDouble()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public decimal ToDecimal()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DateTime ToDateTime()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public UniqueId ToUniqueId()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TimeSpan ToTimeSpan()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Guid ToGuid()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ToString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public byte[] ToByteArray()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool Equals2(string str, bool checkLower)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Sign(XmlSigningNodeWriter writer)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public object[] ToList()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public object ToObject()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryReadBase64(byte[] buffer, int offset, int count, out int actual)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryReadChars(char[] chars, int offset, int count, out int actual)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool TryReadUnicodeChars(char[] chars, int offset, int count, out int actual)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryGetDictionaryString(out XmlDictionaryString value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool TryGetByteArrayLength(out int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetCharsText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetUnicodeCharsText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetEscapedCharsText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetCharText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private int GetChar()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private int GetInt8()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private int GetInt16()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private int GetInt32()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private long GetInt64()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private ulong GetUInt64()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private float GetSingle()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private double GetDouble()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private decimal GetDecimal()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private UniqueId GetUniqueId()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private Guid GetGuid()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void GetBase64(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlDictionaryString GetDictionaryString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetQNameDictionaryText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static ValueHandle()
		{
			throw null;
		}
	}
	internal abstract class XmlBaseReader : XmlDictionaryReader
	{
		protected enum QNameType
		{
			Normal,
			Xmlns
		}

		protected class XmlNode
		{
			protected enum XmlNodeFlags
			{
				None = 0,
				CanGetAttribute = 1,
				CanMoveToElement = 2,
				HasValue = 4,
				AtomicValue = 8,
				SkipValue = 0x10,
				HasContent = 0x20
			}

			private XmlNodeType nodeType;

			private PrefixHandle prefix;

			private StringHandle localName;

			private ValueHandle value;

			private Namespace ns;

			private bool hasValue;

			private bool canGetAttribute;

			private bool canMoveToElement;

			private ReadState readState;

			private XmlAttributeTextNode attributeTextNode;

			private bool exitScope;

			private int depthDelta;

			private bool isAtomicValue;

			private bool skipValue;

			private QNameType qnameType;

			private bool hasContent;

			private bool isEmptyElement;

			private char quoteChar;

			public bool HasValue
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public ReadState ReadState
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public StringHandle LocalName
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public PrefixHandle Prefix
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public bool CanGetAttribute
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public bool CanMoveToElement
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public XmlAttributeTextNode AttributeText
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public bool SkipValue
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public ValueHandle Value
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public int DepthDelta
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public bool HasContent
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public XmlNodeType NodeType
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public QNameType QNameType
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public Namespace Namespace
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public bool IsAtomicValue
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public bool ExitScope
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public bool IsEmptyElement
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public char QuoteChar
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public string ValueAsString
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			protected XmlNode(XmlNodeType nodeType, PrefixHandle prefix, StringHandle localName, ValueHandle value, XmlNodeFlags nodeFlags, ReadState readState, XmlAttributeTextNode attributeTextNode, int depthDelta)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsLocalName(string localName)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsLocalName(XmlDictionaryString localName)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsNamespaceUri(string ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsNamespaceUri(XmlDictionaryString ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsLocalNameAndNamespaceUri(string localName, string ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsLocalNameAndNamespaceUri(XmlDictionaryString localName, XmlDictionaryString ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsPrefixAndLocalName(string prefix, string localName)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool TryGetLocalNameAsDictionaryString(out XmlDictionaryString localName)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool TryGetNamespaceUriAsDictionaryString(out XmlDictionaryString ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool TryGetValueAsDictionaryString(out XmlDictionaryString value)
			{
				throw null;
			}
		}

		protected class XmlElementNode : XmlNode
		{
			private XmlEndElementNode endElementNode;

			private int bufferOffset;

			public int NameOffset;

			public int NameLength;

			public XmlEndElementNode EndElement
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public int BufferOffset
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlElementNode(XmlBufferReader bufferReader)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private XmlElementNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
			{
				throw null;
			}
		}

		protected class XmlAttributeNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlAttributeNode(XmlBufferReader bufferReader)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private XmlAttributeNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
			{
				throw null;
			}
		}

		protected class XmlEndElementNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlEndElementNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
			{
				throw null;
			}
		}

		protected class XmlTextNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			protected XmlTextNode(XmlNodeType nodeType, PrefixHandle prefix, StringHandle localName, ValueHandle value, XmlNodeFlags nodeFlags, ReadState readState, XmlAttributeTextNode attributeTextNode, int depthDelta)
			{
				throw null;
			}
		}

		protected class XmlAtomicTextNode : XmlTextNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlAtomicTextNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlComplexTextNode : XmlTextNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlComplexTextNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlWhitespaceTextNode : XmlTextNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlWhitespaceTextNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlCDataNode : XmlTextNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlCDataNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlAttributeTextNode : XmlTextNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlAttributeTextNode(PrefixHandle prefix, StringHandle localName, ValueHandle value)
			{
				throw null;
			}
		}

		protected class XmlInitialNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlInitialNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlDeclarationNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlDeclarationNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlCommentNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlCommentNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlEndOfFileNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlEndOfFileNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		protected class XmlClosedNode : XmlNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlClosedNode(XmlBufferReader bufferReader)
			{
				throw null;
			}
		}

		private class AttributeSorter : IComparer
		{
			private object[] indeces;

			private XmlAttributeNode[] attributeNodes;

			private int attributeCount;

			private int attributeIndex1;

			private int attributeIndex2;

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool Sort(XmlAttributeNode[] attributeNodes, int attributeCount)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void GetIndeces(out int attributeIndex1, out int attributeIndex2)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Close()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private bool Sort()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private bool IsSorted()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public int Compare(object obj1, object obj2)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public int CompareQNameType(QNameType type1, QNameType type2)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public AttributeSorter()
			{
				throw null;
			}
		}

		private class NamespaceManager
		{
			private class XmlAttribute
			{
				private XmlSpace space;

				private string lang;

				private int depth;

				public int Depth
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public string XmlLang
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public XmlSpace XmlSpace
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				[MethodImpl(MethodImplOptions.NoInlining)]
				public XmlAttribute()
				{
					throw null;
				}
			}

			private XmlBufferReader bufferReader;

			private Namespace[] namespaces;

			private int nsCount;

			private int depth;

			private Namespace[] shortPrefixUri;

			private static Namespace emptyNamespace;

			private static Namespace xmlNamespace;

			private XmlAttribute[] attributes;

			private int attributeCount;

			private XmlSpace space;

			private string lang;

			public static Namespace XmlNamespace
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public static Namespace EmptyNamespace
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public string XmlLang
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public XmlSpace XmlSpace
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public NamespaceManager(XmlBufferReader bufferReader)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Close()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Clear()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void EnterScope()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void ExitScope()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Sign(XmlSigningNodeWriter writer)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddLangAttribute(string lang)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddSpaceAttribute(XmlSpace space)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private void AddAttribute()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Register(Namespace nameSpace)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Namespace AddNamespace()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Namespace LookupNamespace(PrefixHandleType prefix)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Namespace LookupNamespace(PrefixHandle prefix)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Namespace LookupNamespace(string prefix)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private bool TryGetShortPrefix(string s, out PrefixHandleType shortPrefix)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			static NamespaceManager()
			{
				throw null;
			}
		}

		protected class Namespace
		{
			private PrefixHandle prefix;

			private StringHandle uri;

			private int depth;

			private Namespace outerUri;

			private string uriString;

			public int Depth
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public PrefixHandle Prefix
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public StringHandle Uri
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public Namespace OuterUri
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Namespace(XmlBufferReader bufferReader)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Clear()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsUri(string s)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public bool IsUri(XmlDictionaryString s)
			{
				throw null;
			}
		}

		private class QuotaNameTable : XmlNameTable
		{
			private XmlDictionaryReader reader;

			private XmlNameTable nameTable;

			private int maxCharCount;

			private int charCount;

			[MethodImpl(MethodImplOptions.NoInlining)]
			public QuotaNameTable(XmlDictionaryReader reader, int maxCharCount)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public override string Get(char[] chars, int offset, int count)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public override string Get(string value)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private void Add(int charCount)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public override string Add(char[] chars, int offset, int count)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public override string Add(string value)
			{
				throw null;
			}
		}

		private XmlBufferReader bufferReader;

		private XmlNode node;

		private NamespaceManager nsMgr;

		private XmlElementNode[] elementNodes;

		private XmlAttributeNode[] attributeNodes;

		private XmlAtomicTextNode atomicTextNode;

		private int depth;

		private int attributeCount;

		private int attributeStart;

		private XmlDictionaryReaderQuotas quotas;

		private XmlNameTable nameTable;

		private XmlDeclarationNode declarationNode;

		private XmlComplexTextNode complexTextNode;

		private XmlWhitespaceTextNode whitespaceTextNode;

		private XmlCDataNode cdataNode;

		private XmlCommentNode commentNode;

		private XmlElementNode rootElementNode;

		private int attributeIndex;

		private char[] chars;

		private string prefix;

		private string localName;

		private string ns;

		private string value;

		private int trailCharCount;

		private int trailByteCount;

		private char[] trailChars;

		private byte[] trailBytes;

		private bool rootElement;

		private bool readingElement;

		private XmlSigningNodeWriter signingWriter;

		private bool signing;

		private AttributeSorter attributeSorter;

		private static XmlInitialNode initialNode;

		private static XmlEndOfFileNode endOfFileNode;

		private static XmlClosedNode closedNode;

		private static BinHexEncoding binhexEncoding;

		private static Base64Encoding base64Encoding;

		private const string xmlns = "xmlns";

		private const string xml = "xml";

		private const string xmlnsNamespace = "http://www.w3.org/2000/xmlns/";

		private const string xmlNamespace = "http://www.w3.org/XML/1998/namespace";

		private static BinHexEncoding BinHexEncoding
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		private static Base64Encoding Base64Encoding
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected XmlBufferReader BufferReader
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override XmlDictionaryReaderQuotas Quotas
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected XmlNode Node
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected XmlElementNode ElementNode
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected bool OutsideRootElement
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool CanReadBinaryContent
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool CanReadValueChunk
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string BaseURI
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool HasValue
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool IsDefault
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string this[int index]
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string this[string name]
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string this[string localName, string namespaceUri]
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override int AttributeCount
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public sealed override int Depth
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool EOF
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public sealed override bool IsEmptyElement
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string LocalName
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string NamespaceURI
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override XmlNameTable NameTable
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public sealed override XmlNodeType NodeType
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string Prefix
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override char QuoteChar
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override ReadState ReadState
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string Value
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override Type ValueType
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string XmlLang
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override XmlSpace XmlSpace
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override bool CanCanonicalize
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected bool Signing
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlBaseReader()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void MoveToNode(XmlNode node)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void MoveToInitial(XmlDictionaryReaderQuotas quotas)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlDeclarationNode MoveToDeclaration()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool CheckStandalone(int attr)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool CheckDeclAttribute(int index, string localName, string value, bool checkLower, string valueSR)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlCommentNode MoveToComment()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlCDataNode MoveToCData()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlAtomicTextNode MoveToAtomicText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlComplexTextNode MoveToComplexText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlTextNode MoveToWhitespaceText()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void MoveToEndElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void MoveToEndOfFile()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlElementNode EnterScope()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void ExitScope()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlAttributeNode AddAttribute(QNameType qnameType, bool isAtomicValue)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected Namespace AddNamespace()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlAttributeNode AddAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlAttributeNode AddXmlAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlAttributeNode AddXmlnsAttribute(Namespace ns)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void FixXmlAttribute(XmlAttributeNode attributeNode)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Close()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlAttributeNode GetAttributeNode(int index)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlAttributeNode GetAttributeNode(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlAttributeNode GetAttributeNode(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private XmlAttributeNode GetAttributeNode(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string GetAttribute(int index)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string GetAttribute(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string GetAttribute(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string GetAttribute(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string LookupNamespace(string prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected Namespace LookupNamespace(PrefixHandleType prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected Namespace LookupNamespace(PrefixHandle prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void ProcessAttributes()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void ProcessAttributes(XmlAttributeNode[] attributeNodes, int attributeCount)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void CheckAttributes(XmlAttributeNode[] attributeNodes, int attributeCount)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void MoveToAttribute(int index)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool MoveToAttribute(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool MoveToAttribute(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool MoveToElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override XmlNodeType MoveToContent()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool MoveToFirstAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool MoveToNextAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetLocalName(bool enforceAtomization)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetNamespaceUri(bool enforceAtomization)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void GetNonAtomizedNames(out string localName, out string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsLocalName(string localName)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsLocalName(XmlDictionaryString localName)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsNamespaceUri(string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsNamespaceUri(XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public sealed override bool IsStartElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsStartElement(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsStartElement(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int IndexOfLocalName(string[] localNames, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int IndexOfLocalName(XmlDictionaryString[] localNames, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadValueChunk(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadValueAsBase64(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ReadElementContentAsString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ReadElementString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ReadElementString(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ReadElementString(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void ReadStartElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void ReadStartElement(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void ReadStartElement(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void ReadEndElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool ReadAttributeValue()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SkipValue(XmlNode node)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool TryGetBase64ContentLength(out int length)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override byte[] ReadContentAsBase64()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadElementContentAsBase64(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadContentAsBase64(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override byte[] ReadContentAsBinHex()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadElementContentAsBinHex(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadContentAsBinHex(byte[] buffer, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private int ReadBytes(Encoding encoding, int byteBlock, int charBlock, byte[] buffer, int offset, int byteCount, bool readContent)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string ReadContentAsString()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool ReadContentAsBoolean()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override long ReadContentAsLong()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int ReadContentAsInt()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override DateTime ReadContentAsDateTime()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override double ReadContentAsDouble()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override float ReadContentAsFloat()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override decimal ReadContentAsDecimal()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override UniqueId ReadContentAsUniqueId()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override TimeSpan ReadContentAsTimeSpan()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override Guid ReadContentAsGuid()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override object ReadContentAsObject()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override object ReadContentAs(Type type, IXmlNamespaceResolver namespaceResolver)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void ResolveEntity()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Skip()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool TryGetLocalNameAsDictionaryString(out XmlDictionaryString localName)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool TryGetNamespaceUriAsDictionaryString(out XmlDictionaryString localName)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool TryGetValueAsDictionaryString(out XmlDictionaryString value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override short[] ReadInt16Array(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override short[] ReadInt16Array(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int[] ReadInt32Array(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int[] ReadInt32Array(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override long[] ReadInt64Array(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override long[] ReadInt64Array(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override float[] ReadSingleArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override float[] ReadSingleArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override double[] ReadDoubleArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override double[] ReadDoubleArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override decimal[] ReadDecimalArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override decimal[] ReadDecimalArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override DateTime[] ReadDateTimeArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override DateTime[] ReadDateTimeArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override Guid[] ReadGuidArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override Guid[] ReadGuidArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override TimeSpan[] ReadTimeSpanArray(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override TimeSpan[] ReadTimeSpanArray(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public string GetOpenElements()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private char[] GetCharBuffer(int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SignStartElement(XmlSigningNodeWriter writer)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SignAttribute(XmlSigningNodeWriter writer, XmlAttributeNode attributeNode)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SignEndElement(XmlSigningNodeWriter writer)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SignNode(XmlSigningNodeWriter writer)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void SignNode()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void StartCanonicalization(Stream stream, bool includeComments, string[] inclusivePrefixes)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void EndCanonicalization()
		{
			throw null;
		}

		protected abstract XmlSigningNodeWriter CreateSigningNodeWriter();

		[MethodImpl(MethodImplOptions.NoInlining)]
		static XmlBaseReader()
		{
			throw null;
		}
	}
	internal abstract class XmlBaseWriter : XmlDictionaryWriter, IFragmentCapableXmlDictionaryWriter
	{
		private class WriteBase64AsyncResult : AsyncResult
		{
			private static AsyncCompletion onComplete;

			private XmlBaseWriter writer;

			private byte[] buffer;

			private int offset;

			private int count;

			private int actualByteCount;

			private int totalByteCount;

			[MethodImpl(MethodImplOptions.NoInlining)]
			public WriteBase64AsyncResult(byte[] buffer, int offset, int count, XmlBaseWriter writer, AsyncCallback callback, object state)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private static bool OnComplete(IAsyncResult result)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private bool HandleWriteBase64Text(IAsyncResult result)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public static void End(IAsyncResult result)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			static WriteBase64AsyncResult()
			{
				throw null;
			}
		}

		private class Element
		{
			private string prefix;

			private string localName;

			private int prefixId;

			public string Prefix
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public string LocalName
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			public int PrefixId
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Clear()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public Element()
			{
				throw null;
			}
		}

		private enum DocumentState : byte
		{
			None,
			Document,
			Epilog,
			End
		}

		private class NamespaceManager
		{
			private class XmlAttribute
			{
				private XmlSpace space;

				private string lang;

				private int depth;

				public int Depth
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public string XmlLang
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public XmlSpace XmlSpace
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				[MethodImpl(MethodImplOptions.NoInlining)]
				public XmlAttribute()
				{
					throw null;
				}

				[MethodImpl(MethodImplOptions.NoInlining)]
				public void Clear()
				{
					throw null;
				}
			}

			private class Namespace
			{
				private string prefix;

				private string ns;

				private XmlDictionaryString xNs;

				private int depth;

				private char prefixChar;

				public int Depth
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public char PrefixChar
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
				}

				public string Prefix
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public string Uri
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				public XmlDictionaryString UriDictionaryString
				{
					[MethodImpl(MethodImplOptions.NoInlining)]
					get
					{
						throw null;
					}
					[MethodImpl(MethodImplOptions.NoInlining)]
					set
					{
						throw null;
					}
				}

				[MethodImpl(MethodImplOptions.NoInlining)]
				public Namespace()
				{
					throw null;
				}

				[MethodImpl(MethodImplOptions.NoInlining)]
				public void Clear()
				{
					throw null;
				}
			}

			private Namespace[] namespaces;

			private Namespace lastNameSpace;

			private int nsCount;

			private int depth;

			private XmlAttribute[] attributes;

			private int attributeCount;

			private XmlSpace space;

			private string lang;

			private int namespaceBoundary;

			private int nsTop;

			private Namespace defaultNamespace;

			public string XmlLang
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public XmlSpace XmlSpace
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
			}

			public int NamespaceBoundary
			{
				[MethodImpl(MethodImplOptions.NoInlining)]
				get
				{
					throw null;
				}
				[MethodImpl(MethodImplOptions.NoInlining)]
				set
				{
					throw null;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public NamespaceManager()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Clear()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Close()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void DeclareNamespaces(XmlNodeWriter writer)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void EnterScope()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void ExitScope()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddLangAttribute(string lang)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddSpaceAttribute(XmlSpace space)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private void AddAttribute()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public string AddNamespace(string uri, XmlDictionaryString uriDictionaryString)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddNamespaceIfNotDeclared(string prefix, string uri, XmlDictionaryString uriDictionaryString)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void AddNamespace(string prefix, string uri, XmlDictionaryString uriDictionaryString)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public string LookupPrefix(string ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public string LookupAttributePrefix(string ns)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public string LookupNamespace(string prefix)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void Sign(XmlCanonicalWriter signingWriter)
			{
				throw null;
			}
		}

		private class XmlBaseWriterNodeWriterAsyncHelper
		{
			private static AsyncEventArgsCallback onWriteComplete;

			private XmlBaseWriter writer;

			private byte[] buffer;

			private int offset;

			private int count;

			private int actualByteCount;

			private int totalByteCount;

			private AsyncEventArgs<XmlNodeWriterWriteBase64TextArgs> nodeWriterAsyncState;

			private XmlNodeWriterWriteBase64TextArgs nodeWriterArgs;

			private AsyncEventArgs<XmlWriteBase64AsyncArguments> inputState;

			[MethodImpl(MethodImplOptions.NoInlining)]
			public XmlBaseWriterNodeWriterAsyncHelper(XmlBaseWriter writer)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public void SetArguments(AsyncEventArgs<XmlWriteBase64AsyncArguments> inputState)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			public AsyncCompletionResult StartAsync()
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private static void OnWriteComplete(IAsyncEventArgs asyncEventArgs)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private bool HandleWriteBase64Text(bool isAsyncCallback)
			{
				throw null;
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private void Clear()
			{
				throw null;
			}
		}

		private XmlNodeWriter writer;

		private NamespaceManager nsMgr;

		private Element[] elements;

		private int depth;

		private string attributeLocalName;

		private string attributeValue;

		private bool isXmlAttribute;

		private bool isXmlnsAttribute;

		private WriteState writeState;

		private DocumentState documentState;

		private byte[] trailBytes;

		private int trailByteCount;

		private XmlStreamNodeWriter nodeWriter;

		private XmlSigningNodeWriter signingWriter;

		private XmlUTF8NodeWriter textFragmentWriter;

		private XmlNodeWriter oldWriter;

		private Stream oldStream;

		private int oldNamespaceBoundary;

		private bool inList;

		private const string xmlnsNamespace = "http://www.w3.org/2000/xmlns/";

		private const string xmlNamespace = "http://www.w3.org/XML/1998/namespace";

		private static BinHexEncoding binhexEncoding;

		private static string[] prefixes;

		private XmlBaseWriterNodeWriterAsyncHelper nodeWriterAsyncHelper;

		protected bool IsClosed
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		private static BinHexEncoding BinHexEncoding
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override string XmlLang
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override XmlSpace XmlSpace
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public override WriteState WriteState
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected int NamespaceBoundary
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public override bool CanCanonicalize
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		protected bool Signing
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public virtual bool CanFragment
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected XmlBaseWriter()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void SetOutput(XmlStreamNodeWriter writer)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Flush()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void Close()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void ThrowClosed()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteXmlnsAttribute(string prefix, string ns)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteXmlnsAttribute(string prefix, XmlDictionaryString ns)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void StartAttribute(ref string prefix, string localName, string ns, XmlDictionaryString xNs)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartAttribute(string prefix, string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartAttribute(string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteEndAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteComment(string text)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteFullEndElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteCData(string text)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteDocType(string name, string pubid, string sysid, string subset)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void StartElement(ref string prefix, string localName, string ns, XmlDictionaryString xNs)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartElement(string prefix, string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartElement(string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteEndElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private Element EnterScope()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void ExitScope()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void FlushElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void StartComment()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void EndComment()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void StartContent()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void StartContent(char ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void StartContent(string s)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void StartContent(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void VerifyWhitespace(char ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void VerifyWhitespace(string s)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void VerifyWhitespace(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool IsWhitespace(char ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void EndContent()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void AutoComplete(WriteState writeState)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void EndStartElement()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override string LookupPrefix(string ns)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal string LookupNamespace(string prefix)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private string GetQualifiedNamePrefix(string namespaceUri, XmlDictionaryString xNs)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteQualifiedName(string localName, string namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteQualifiedName(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartDocument()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteStartDocument(bool standalone)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteProcessingInstruction(string name, string text)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void FinishDocument()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteEndDocument()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteEntityRef(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteName(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteNmToken(string name)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteWhitespace(string whitespace)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteString(string value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteString(XmlDictionaryString value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteChars(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteRaw(string value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteRaw(char[] chars, int offset, int count)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteCharEntity(char ch)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteSurrogateCharEntity(char lowChar, char highChar)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteValue(object value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void WritePrimitiveValue(object value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteValue(string value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteValue(int value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void WriteValue(long value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void WriteValue(ulong value)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public 

plugins/System.Threading.Channels.dll

Decompiled 2 years ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using FxResources.System.Threading.Channels;
using Internal;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyDefaultAlias("System.Threading.Channels")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata("IsTrimmable", "True")]
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.System32 | DllImportSearchPath.AssemblyDirectory)]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("Provides types for passing data between producers and consumers.\r\n\r\nCommonly Used Types:\r\nSystem.Threading.Channel\r\nSystem.Threading.Channel<T>")]
[assembly: AssemblyFileVersion("7.0.22.51805")]
[assembly: AssemblyInformationalVersion("7.0.0+d099f075e45d2aa6007a22b71b45a08758559f80")]
[assembly: AssemblyProduct("Microsoft® .NET")]
[assembly: AssemblyTitle("System.Threading.Channels")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/dotnet/runtime")]
[assembly: AssemblyVersion("7.0.0.0")]
[module: RefSafetyRules(11)]
[module: System.Runtime.CompilerServices.NullablePublicOnly(false)]
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 NullablePublicOnlyAttribute : Attribute
	{
		public readonly bool IncludesInternals;

		public NullablePublicOnlyAttribute(bool P_0)
		{
			IncludesInternals = 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 FxResources.System.Threading.Channels
{
	internal static class SR
	{
	}
}
namespace Internal
{
	internal static class PaddingHelpers
	{
		internal const int CACHE_LINE_SIZE = 128;
	}
	[StructLayout(LayoutKind.Explicit, Size = 124)]
	internal struct PaddingFor32
	{
	}
}
namespace System
{
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal struct VoidResult
	{
	}
	internal static class SR
	{
		private static readonly bool s_usingResourceKeys = AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out var isEnabled) && isEnabled;

		private static ResourceManager s_resourceManager;

		internal static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(typeof(SR)));

		internal static string ChannelClosedException_DefaultMessage => GetResourceString("ChannelClosedException_DefaultMessage");

		internal static string InvalidOperation_IncompleteAsyncOperation => GetResourceString("InvalidOperation_IncompleteAsyncOperation");

		internal static string InvalidOperation_MultipleContinuations => GetResourceString("InvalidOperation_MultipleContinuations");

		internal static string InvalidOperation_IncorrectToken => GetResourceString("InvalidOperation_IncorrectToken");

		private static bool UsingResourceKeys()
		{
			return s_usingResourceKeys;
		}

		internal static string GetResourceString(string resourceKey)
		{
			if (UsingResourceKeys())
			{
				return resourceKey;
			}
			string result = null;
			try
			{
				result = ResourceManager.GetString(resourceKey);
			}
			catch (MissingManifestResourceException)
			{
			}
			return result;
		}

		internal static string GetResourceString(string resourceKey, string defaultString)
		{
			string resourceString = GetResourceString(resourceKey);
			if (!(resourceKey == resourceString) && resourceString != null)
			{
				return resourceString;
			}
			return defaultString;
		}

		internal static string Format(string resourceFormat, object p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(resourceFormat, p1);
		}

		internal static string Format(string resourceFormat, object p1, object p2)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2);
			}
			return string.Format(resourceFormat, p1, p2);
		}

		internal static string Format(string resourceFormat, object p1, object p2, object p3)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2, p3);
			}
			return string.Format(resourceFormat, p1, p2, p3);
		}

		internal static string Format(string resourceFormat, params object[] args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + ", " + string.Join(", ", args);
				}
				return string.Format(resourceFormat, args);
			}
			return resourceFormat;
		}

		internal static string Format(IFormatProvider provider, string resourceFormat, object p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(provider, resourceFormat, p1);
		}

		internal static string Format(IFormatProvider provider, string resourceFormat, object p1, object p2)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2);
			}
			return string.Format(provider, resourceFormat, p1, p2);
		}

		internal static string Format(IFormatProvider provider, string resourceFormat, object p1, object p2, object p3)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2, p3);
			}
			return string.Format(provider, resourceFormat, p1, p2, p3);
		}

		internal static string Format(IFormatProvider provider, string resourceFormat, params object[] args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + ", " + string.Join(", ", args);
				}
				return string.Format(provider, resourceFormat, args);
			}
			return resourceFormat;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	internal sealed class AllowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	internal sealed class DisallowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	internal sealed class MaybeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	internal sealed class NotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class MaybeNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public MaybeNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class NotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public NotNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
	internal sealed class NotNullIfNotNullAttribute : Attribute
	{
		public string ParameterName { get; }

		public NotNullIfNotNullAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	internal sealed class DoesNotReturnAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class DoesNotReturnIfAttribute : Attribute
	{
		public bool ParameterValue { get; }

		public DoesNotReturnIfAttribute(bool parameterValue)
		{
			ParameterValue = parameterValue;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace System.Runtime.InteropServices
{
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
	internal sealed class LibraryImportAttribute : Attribute
	{
		public string LibraryName { get; }

		public string EntryPoint { get; set; }

		public StringMarshalling StringMarshalling { get; set; }

		public Type StringMarshallingCustomType { get; set; }

		public bool SetLastError { get; set; }

		public LibraryImportAttribute(string libraryName)
		{
			LibraryName = libraryName;
		}
	}
	internal enum StringMarshalling
	{
		Custom,
		Utf8,
		Utf16
	}
}
namespace System.Collections.Generic
{
	[DebuggerDisplay("Count = {_size}")]
	internal sealed class Deque<T>
	{
		private T[] _array = Array.Empty<T>();

		private int _head;

		private int _tail;

		private int _size;

		public int Count => _size;

		public bool IsEmpty => _size == 0;

		public void EnqueueTail(T item)
		{
			if (_size == _array.Length)
			{
				Grow();
			}
			_array[_tail] = item;
			if (++_tail == _array.Length)
			{
				_tail = 0;
			}
			_size++;
		}

		public T DequeueHead()
		{
			T result = _array[_head];
			_array[_head] = default(T);
			if (++_head == _array.Length)
			{
				_head = 0;
			}
			_size--;
			return result;
		}

		public T PeekHead()
		{
			return _array[_head];
		}

		public T PeekTail()
		{
			int num = _tail - 1;
			if (num == -1)
			{
				num = _array.Length - 1;
			}
			return _array[num];
		}

		public T DequeueTail()
		{
			if (--_tail == -1)
			{
				_tail = _array.Length - 1;
			}
			T result = _array[_tail];
			_array[_tail] = default(T);
			_size--;
			return result;
		}

		public IEnumerator<T> GetEnumerator()
		{
			int pos = _head;
			int count = _size;
			while (count-- > 0)
			{
				yield return _array[pos];
				pos = (pos + 1) % _array.Length;
			}
		}

		private void Grow()
		{
			int num = (int)((long)_array.Length * 2L);
			if (num < _array.Length + 4)
			{
				num = _array.Length + 4;
			}
			T[] array = new T[num];
			if (_head == 0)
			{
				Array.Copy(_array, array, _size);
			}
			else
			{
				Array.Copy(_array, _head, array, 0, _array.Length - _head);
				Array.Copy(_array, 0, array, _array.Length - _head, _tail);
			}
			_array = array;
			_head = 0;
			_tail = _size;
		}
	}
}
namespace System.Collections.Concurrent
{
	[DebuggerDisplay("Count = {Count}")]
	[DebuggerTypeProxy(typeof(SingleProducerSingleConsumerQueue<>.SingleProducerSingleConsumerQueue_DebugView))]
	internal sealed class SingleProducerSingleConsumerQueue<T> : IEnumerable<T>, IEnumerable
	{
		[StructLayout(LayoutKind.Sequential)]
		private sealed class Segment
		{
			internal Segment _next;

			internal readonly T[] _array;

			internal SegmentState _state;

			internal Segment(int size)
			{
				_array = new T[size];
			}
		}

		private struct SegmentState
		{
			internal Internal.PaddingFor32 _pad0;

			internal volatile int _first;

			internal int _lastCopy;

			internal Internal.PaddingFor32 _pad1;

			internal int _firstCopy;

			internal volatile int _last;

			internal Internal.PaddingFor32 _pad2;
		}

		private sealed class SingleProducerSingleConsumerQueue_DebugView
		{
			private readonly SingleProducerSingleConsumerQueue<T> _queue;

			[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
			public T[] Items => new List<T>(_queue).ToArray();

			public SingleProducerSingleConsumerQueue_DebugView(SingleProducerSingleConsumerQueue<T> queue)
			{
				_queue = queue;
			}
		}

		private const int InitialSegmentSize = 32;

		private const int MaxSegmentSize = 16777216;

		private volatile Segment _head;

		private volatile Segment _tail;

		public bool IsEmpty
		{
			get
			{
				Segment head = _head;
				if (head._state._first != head._state._lastCopy)
				{
					return false;
				}
				if (head._state._first != head._state._last)
				{
					return false;
				}
				return head._next == null;
			}
		}

		internal int Count
		{
			get
			{
				int num = 0;
				for (Segment segment = _head; segment != null; segment = segment._next)
				{
					int num2 = segment._array.Length;
					int first;
					int last;
					do
					{
						first = segment._state._first;
						last = segment._state._last;
					}
					while (first != segment._state._first);
					num += (last - first) & (num2 - 1);
				}
				return num;
			}
		}

		public SingleProducerSingleConsumerQueue()
		{
			_head = (_tail = new Segment(32));
		}

		public void Enqueue(T item)
		{
			Segment segment = _tail;
			T[] array = segment._array;
			int last = segment._state._last;
			int num = (last + 1) & (array.Length - 1);
			if (num != segment._state._firstCopy)
			{
				array[last] = item;
				segment._state._last = num;
			}
			else
			{
				EnqueueSlow(item, ref segment);
			}
		}

		private void EnqueueSlow(T item, ref Segment segment)
		{
			if (segment._state._firstCopy != segment._state._first)
			{
				segment._state._firstCopy = segment._state._first;
				Enqueue(item);
				return;
			}
			int num = _tail._array.Length << 1;
			if (num > 16777216)
			{
				num = 16777216;
			}
			Segment segment2 = new Segment(num);
			segment2._array[0] = item;
			segment2._state._last = 1;
			segment2._state._lastCopy = 1;
			try
			{
			}
			finally
			{
				Volatile.Write(ref _tail._next, segment2);
				_tail = segment2;
			}
		}

		public bool TryDequeue([MaybeNullWhen(false)] out T result)
		{
			Segment head = _head;
			T[] array = head._array;
			int first = head._state._first;
			if (first != head._state._lastCopy)
			{
				result = array[first];
				array[first] = default(T);
				head._state._first = (first + 1) & (array.Length - 1);
				return true;
			}
			return TryDequeueSlow(head, array, peek: false, out result);
		}

		public bool TryPeek([MaybeNullWhen(false)] out T result)
		{
			Segment head = _head;
			T[] array = head._array;
			int first = head._state._first;
			if (first != head._state._lastCopy)
			{
				result = array[first];
				return true;
			}
			return TryDequeueSlow(head, array, peek: true, out result);
		}

		private bool TryDequeueSlow(Segment segment, T[] array, bool peek, [MaybeNullWhen(false)] out T result)
		{
			if (segment._state._last != segment._state._lastCopy)
			{
				segment._state._lastCopy = segment._state._last;
				if (!peek)
				{
					return TryDequeue(out result);
				}
				return TryPeek(out result);
			}
			if (segment._next != null && segment._state._first == segment._state._last)
			{
				segment = segment._next;
				array = segment._array;
				_head = segment;
			}
			int first = segment._state._first;
			if (first == segment._state._last)
			{
				result = default(T);
				return false;
			}
			result = array[first];
			if (!peek)
			{
				array[first] = default(T);
				segment._state._first = (first + 1) & (segment._array.Length - 1);
				segment._state._lastCopy = segment._state._last;
			}
			return true;
		}

		public IEnumerator<T> GetEnumerator()
		{
			for (Segment segment = _head; segment != null; segment = segment._next)
			{
				for (int pt = segment._state._first; pt != segment._state._last; pt = (pt + 1) & (segment._array.Length - 1))
				{
					yield return segment._array[pt];
				}
			}
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
}
namespace System.Threading.Channels
{
	internal abstract class AsyncOperation
	{
		protected static readonly Action<object> s_availableSentinel = AvailableSentinel;

		protected static readonly Action<object> s_completedSentinel = CompletedSentinel;

		private static void AvailableSentinel(object s)
		{
		}

		private static void CompletedSentinel(object s)
		{
		}

		protected static void ThrowIncompleteOperationException()
		{
			throw new InvalidOperationException(System.SR.InvalidOperation_IncompleteAsyncOperation);
		}

		protected static void ThrowMultipleContinuations()
		{
			throw new InvalidOperationException(System.SR.InvalidOperation_MultipleContinuations);
		}

		protected static void ThrowIncorrectCurrentIdException()
		{
			throw new InvalidOperationException(System.SR.InvalidOperation_IncorrectToken);
		}
	}
	internal class AsyncOperation<TResult> : AsyncOperation, IValueTaskSource, IValueTaskSource<TResult>
	{
		private readonly CancellationTokenRegistration _registration;

		private readonly bool _pooled;

		private readonly bool _runContinuationsAsynchronously;

		private volatile int _completionReserved;

		private TResult _result;

		private ExceptionDispatchInfo _error;

		private Action<object> _continuation;

		private object _continuationState;

		private object _schedulingContext;

		private ExecutionContext _executionContext;

		private short _currentId;

		public AsyncOperation<TResult> Next { get; set; }

		public CancellationToken CancellationToken { get; }

		public ValueTask ValueTask => new ValueTask(this, _currentId);

		public ValueTask<TResult> ValueTaskOfT => new ValueTask<TResult>(this, _currentId);

		internal bool IsCompleted => (object)_continuation == AsyncOperation.s_completedSentinel;

		public AsyncOperation(bool runContinuationsAsynchronously, CancellationToken cancellationToken = default(CancellationToken), bool pooled = false)
		{
			_continuation = (pooled ? AsyncOperation.s_availableSentinel : null);
			_pooled = pooled;
			_runContinuationsAsynchronously = runContinuationsAsynchronously;
			if (cancellationToken.CanBeCanceled)
			{
				CancellationToken = cancellationToken;
				_registration = UnsafeRegister(cancellationToken, delegate(object s)
				{
					AsyncOperation<TResult> asyncOperation = (AsyncOperation<TResult>)s;
					asyncOperation.TrySetCanceled(asyncOperation.CancellationToken);
				}, this);
			}
		}

		public ValueTaskSourceStatus GetStatus(short token)
		{
			if (_currentId != token)
			{
				AsyncOperation.ThrowIncorrectCurrentIdException();
			}
			if (IsCompleted)
			{
				if (_error != null)
				{
					if (!(_error.SourceException is OperationCanceledException))
					{
						return ValueTaskSourceStatus.Faulted;
					}
					return ValueTaskSourceStatus.Canceled;
				}
				return ValueTaskSourceStatus.Succeeded;
			}
			return ValueTaskSourceStatus.Pending;
		}

		public TResult GetResult(short token)
		{
			if (_currentId != token)
			{
				AsyncOperation.ThrowIncorrectCurrentIdException();
			}
			if (!IsCompleted)
			{
				AsyncOperation.ThrowIncompleteOperationException();
			}
			ExceptionDispatchInfo error = _error;
			TResult result = _result;
			_currentId++;
			if (_pooled)
			{
				Volatile.Write(ref _continuation, AsyncOperation.s_availableSentinel);
			}
			error?.Throw();
			return result;
		}

		void IValueTaskSource.GetResult(short token)
		{
			if (_currentId != token)
			{
				AsyncOperation.ThrowIncorrectCurrentIdException();
			}
			if (!IsCompleted)
			{
				AsyncOperation.ThrowIncompleteOperationException();
			}
			ExceptionDispatchInfo error = _error;
			_currentId++;
			if (_pooled)
			{
				Volatile.Write(ref _continuation, AsyncOperation.s_availableSentinel);
			}
			error?.Throw();
		}

		public bool TryOwnAndReset()
		{
			if ((object)Interlocked.CompareExchange(ref _continuation, null, AsyncOperation.s_availableSentinel) == AsyncOperation.s_availableSentinel)
			{
				_continuationState = null;
				_result = default(TResult);
				_error = null;
				_schedulingContext = null;
				_executionContext = null;
				return true;
			}
			return false;
		}

		public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
		{
			if (_currentId != token)
			{
				AsyncOperation.ThrowIncorrectCurrentIdException();
			}
			if (_continuationState != null)
			{
				AsyncOperation.ThrowMultipleContinuations();
			}
			_continuationState = state;
			if ((flags & ValueTaskSourceOnCompletedFlags.FlowExecutionContext) != 0)
			{
				_executionContext = ExecutionContext.Capture();
			}
			SynchronizationContext synchronizationContext = null;
			TaskScheduler taskScheduler = null;
			if ((flags & ValueTaskSourceOnCompletedFlags.UseSchedulingContext) != 0)
			{
				synchronizationContext = SynchronizationContext.Current;
				if (synchronizationContext != null && synchronizationContext.GetType() != typeof(SynchronizationContext))
				{
					_schedulingContext = synchronizationContext;
				}
				else
				{
					synchronizationContext = null;
					taskScheduler = TaskScheduler.Current;
					if (taskScheduler != TaskScheduler.Default)
					{
						_schedulingContext = taskScheduler;
					}
				}
			}
			Action<object> action = Interlocked.CompareExchange(ref _continuation, continuation, null);
			if (action == null)
			{
				return;
			}
			if ((object)action != AsyncOperation.s_completedSentinel)
			{
				AsyncOperation.ThrowMultipleContinuations();
			}
			if (_schedulingContext == null)
			{
				if (_executionContext == null)
				{
					UnsafeQueueUserWorkItem(continuation, state);
				}
				else
				{
					QueueUserWorkItem(continuation, state);
				}
			}
			else if (synchronizationContext != null)
			{
				synchronizationContext.Post(delegate(object s)
				{
					KeyValuePair<Action<object>, object> keyValuePair = (KeyValuePair<Action<object>, object>)s;
					keyValuePair.Key(keyValuePair.Value);
				}, new KeyValuePair<Action<object>, object>(continuation, state));
			}
			else
			{
				Task.Factory.StartNew(continuation, state, CancellationToken.None, TaskCreationOptions.DenyChildAttach, taskScheduler);
			}
		}

		public bool UnregisterCancellation()
		{
			if (CancellationToken.CanBeCanceled)
			{
				CancellationTokenRegistration registration = _registration;
				registration.Dispose();
				return _completionReserved == 0;
			}
			return true;
		}

		public bool TrySetResult(TResult item)
		{
			UnregisterCancellation();
			if (TryReserveCompletionIfCancelable())
			{
				_result = item;
				SignalCompletion();
				return true;
			}
			return false;
		}

		public bool TrySetException(Exception exception)
		{
			UnregisterCancellation();
			if (TryReserveCompletionIfCancelable())
			{
				_error = ExceptionDispatchInfo.Capture(exception);
				SignalCompletion();
				return true;
			}
			return false;
		}

		public bool TrySetCanceled(CancellationToken cancellationToken = default(CancellationToken))
		{
			if (TryReserveCompletionIfCancelable())
			{
				_error = ExceptionDispatchInfo.Capture(new OperationCanceledException(cancellationToken));
				SignalCompletion();
				return true;
			}
			return false;
		}

		private bool TryReserveCompletionIfCancelable()
		{
			if (CancellationToken.CanBeCanceled)
			{
				return Interlocked.CompareExchange(ref _completionReserved, 1, 0) == 0;
			}
			return true;
		}

		private void SignalCompletion()
		{
			if (_continuation == null && Interlocked.CompareExchange(ref _continuation, AsyncOperation.s_completedSentinel, null) == null)
			{
				return;
			}
			if (_schedulingContext == null)
			{
				if (_runContinuationsAsynchronously)
				{
					UnsafeQueueSetCompletionAndInvokeContinuation();
					return;
				}
			}
			else if (_schedulingContext is SynchronizationContext synchronizationContext)
			{
				if (_runContinuationsAsynchronously || synchronizationContext != SynchronizationContext.Current)
				{
					synchronizationContext.Post(delegate(object s)
					{
						((AsyncOperation<TResult>)s).SetCompletionAndInvokeContinuation();
					}, this);
					return;
				}
			}
			else
			{
				TaskScheduler taskScheduler = (TaskScheduler)_schedulingContext;
				if (_runContinuationsAsynchronously || taskScheduler != TaskScheduler.Current)
				{
					Task.Factory.StartNew(delegate(object s)
					{
						((AsyncOperation<TResult>)s).SetCompletionAndInvokeContinuation();
					}, this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, taskScheduler);
					return;
				}
			}
			SetCompletionAndInvokeContinuation();
		}

		private void SetCompletionAndInvokeContinuation()
		{
			if (_executionContext == null)
			{
				Action<object> continuation = _continuation;
				_continuation = AsyncOperation.s_completedSentinel;
				continuation(_continuationState);
				return;
			}
			ExecutionContext.Run(_executionContext, delegate(object s)
			{
				AsyncOperation<TResult> asyncOperation = (AsyncOperation<TResult>)s;
				Action<object> continuation2 = asyncOperation._continuation;
				asyncOperation._continuation = AsyncOperation.s_completedSentinel;
				continuation2(asyncOperation._continuationState);
			}, this);
		}

		private void UnsafeQueueSetCompletionAndInvokeContinuation()
		{
			ThreadPool.UnsafeQueueUserWorkItem(delegate(object s)
			{
				((AsyncOperation<TResult>)s).SetCompletionAndInvokeContinuation();
			}, this);
		}

		private static void UnsafeQueueUserWorkItem(Action<object> action, object state)
		{
			QueueUserWorkItem(action, state);
		}

		private static void QueueUserWorkItem(Action<object> action, object state)
		{
			Task.Factory.StartNew(action, state, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
		}

		private static CancellationTokenRegistration UnsafeRegister(CancellationToken cancellationToken, Action<object> action, object state)
		{
			return cancellationToken.Register(action, state);
		}
	}
	internal sealed class VoidAsyncOperationWithData<TData> : AsyncOperation<VoidResult>
	{
		public TData Item { get; set; }

		public VoidAsyncOperationWithData(bool runContinuationsAsynchronously, CancellationToken cancellationToken = default(CancellationToken), bool pooled = false)
			: base(runContinuationsAsynchronously, cancellationToken, pooled)
		{
		}
	}
	[DebuggerDisplay("Items={ItemsCountForDebugger}, Capacity={_bufferedCapacity}, Mode={_mode}, Closed={ChannelIsClosedForDebugger}")]
	[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
	internal sealed class BoundedChannel<T> : Channel<T>, IDebugEnumerable<T>
	{
		[DebuggerDisplay("Items={ItemsCountForDebugger}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class BoundedChannelReader : ChannelReader<T>, IDebugEnumerable<T>
		{
			internal readonly BoundedChannel<T> _parent;

			private readonly AsyncOperation<T> _readerSingleton;

			private readonly AsyncOperation<bool> _waiterSingleton;

			public override Task Completion => _parent._completion.Task;

			public override bool CanCount => true;

			public override bool CanPeek => true;

			public override int Count
			{
				get
				{
					BoundedChannel<T> parent = _parent;
					lock (parent.SyncObj)
					{
						return parent._items.Count;
					}
				}
			}

			private int ItemsCountForDebugger => _parent._items.Count;

			internal BoundedChannelReader(BoundedChannel<T> parent)
			{
				_parent = parent;
				_readerSingleton = new AsyncOperation<T>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
				_waiterSingleton = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
			}

			public override bool TryRead([MaybeNullWhen(false)] out T item)
			{
				BoundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						item = DequeueItemAndPostProcess();
						return true;
					}
				}
				item = default(T);
				return false;
			}

			public override bool TryPeek([MaybeNullWhen(false)] out T item)
			{
				BoundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						item = parent._items.PeekHead();
						return true;
					}
				}
				item = default(T);
				return false;
			}

			public override ValueTask<T> ReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<T>(Task.FromCanceled<T>(cancellationToken));
				}
				BoundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						return new ValueTask<T>(DequeueItemAndPostProcess());
					}
					if (parent._doneWriting != null)
					{
						return ChannelUtilities.GetInvalidCompletionValueTask<T>(parent._doneWriting);
					}
					if (!cancellationToken.CanBeCanceled)
					{
						AsyncOperation<T> readerSingleton = _readerSingleton;
						if (readerSingleton.TryOwnAndReset())
						{
							parent._blockedReaders.EnqueueTail(readerSingleton);
							return readerSingleton.ValueTaskOfT;
						}
					}
					AsyncOperation<T> asyncOperation = new AsyncOperation<T>(parent._runContinuationsAsynchronously | cancellationToken.CanBeCanceled, cancellationToken);
					parent._blockedReaders.EnqueueTail(asyncOperation);
					return asyncOperation.ValueTaskOfT;
				}
			}

			public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
				}
				BoundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						return new ValueTask<bool>(result: true);
					}
					if (parent._doneWriting != null)
					{
						return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
					}
					if (!cancellationToken.CanBeCanceled)
					{
						AsyncOperation<bool> waiterSingleton = _waiterSingleton;
						if (waiterSingleton.TryOwnAndReset())
						{
							ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, waiterSingleton);
							return waiterSingleton.ValueTaskOfT;
						}
					}
					AsyncOperation<bool> asyncOperation = new AsyncOperation<bool>(parent._runContinuationsAsynchronously | cancellationToken.CanBeCanceled, cancellationToken);
					ChannelUtilities.QueueWaiter(ref _parent._waitingReadersTail, asyncOperation);
					return asyncOperation.ValueTaskOfT;
				}
			}

			private T DequeueItemAndPostProcess()
			{
				BoundedChannel<T> parent = _parent;
				T result = parent._items.DequeueHead();
				if (parent._doneWriting != null)
				{
					if (parent._items.IsEmpty)
					{
						ChannelUtilities.Complete(parent._completion, parent._doneWriting);
					}
				}
				else
				{
					while (!parent._blockedWriters.IsEmpty)
					{
						VoidAsyncOperationWithData<T> voidAsyncOperationWithData = parent._blockedWriters.DequeueHead();
						if (voidAsyncOperationWithData.TrySetResult(default(VoidResult)))
						{
							parent._items.EnqueueTail(voidAsyncOperationWithData.Item);
							return result;
						}
					}
					ChannelUtilities.WakeUpWaiters(ref parent._waitingWritersTail, result: true);
				}
				return result;
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		[DebuggerDisplay("Items={ItemsCountForDebugger}, Capacity={CapacityForDebugger}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class BoundedChannelWriter : ChannelWriter<T>, IDebugEnumerable<T>
		{
			internal readonly BoundedChannel<T> _parent;

			private readonly VoidAsyncOperationWithData<T> _writerSingleton;

			private readonly AsyncOperation<bool> _waiterSingleton;

			private int ItemsCountForDebugger => _parent._items.Count;

			private int CapacityForDebugger => _parent._bufferedCapacity;

			internal BoundedChannelWriter(BoundedChannel<T> parent)
			{
				_parent = parent;
				_writerSingleton = new VoidAsyncOperationWithData<T>(runContinuationsAsynchronously: true, default(CancellationToken), pooled: true);
				_waiterSingleton = new AsyncOperation<bool>(runContinuationsAsynchronously: true, default(CancellationToken), pooled: true);
			}

			public override bool TryComplete(Exception error)
			{
				BoundedChannel<T> parent = _parent;
				bool isEmpty;
				lock (parent.SyncObj)
				{
					if (parent._doneWriting != null)
					{
						return false;
					}
					parent._doneWriting = error ?? ChannelUtilities.s_doneWritingSentinel;
					isEmpty = parent._items.IsEmpty;
				}
				if (isEmpty)
				{
					ChannelUtilities.Complete(parent._completion, error);
				}
				ChannelUtilities.FailOperations<AsyncOperation<T>, T>(parent._blockedReaders, ChannelUtilities.CreateInvalidCompletionException(error));
				ChannelUtilities.FailOperations<VoidAsyncOperationWithData<T>, VoidResult>(parent._blockedWriters, ChannelUtilities.CreateInvalidCompletionException(error));
				ChannelUtilities.WakeUpWaiters(ref parent._waitingReadersTail, result: false, error);
				ChannelUtilities.WakeUpWaiters(ref parent._waitingWritersTail, result: false, error);
				return true;
			}

			public override bool TryWrite(T item)
			{
				AsyncOperation<T> asyncOperation = null;
				AsyncOperation<bool> listTail = null;
				BoundedChannel<T> parent = _parent;
				bool lockTaken = false;
				try
				{
					Monitor.Enter(parent.SyncObj, ref lockTaken);
					if (parent._doneWriting != null)
					{
						return false;
					}
					int count = parent._items.Count;
					if (count != 0)
					{
						if (count < parent._bufferedCapacity)
						{
							parent._items.EnqueueTail(item);
							return true;
						}
						if (parent._mode == BoundedChannelFullMode.Wait)
						{
							return false;
						}
						if (parent._mode == BoundedChannelFullMode.DropWrite)
						{
							Monitor.Exit(parent.SyncObj);
							lockTaken = false;
							parent._itemDropped?.Invoke(item);
							return true;
						}
						T obj = ((parent._mode == BoundedChannelFullMode.DropNewest) ? parent._items.DequeueTail() : parent._items.DequeueHead());
						parent._items.EnqueueTail(item);
						Monitor.Exit(parent.SyncObj);
						lockTaken = false;
						parent._itemDropped?.Invoke(obj);
						return true;
					}
					while (!parent._blockedReaders.IsEmpty)
					{
						AsyncOperation<T> asyncOperation2 = parent._blockedReaders.DequeueHead();
						if (asyncOperation2.UnregisterCancellation())
						{
							asyncOperation = asyncOperation2;
							break;
						}
					}
					if (asyncOperation == null)
					{
						parent._items.EnqueueTail(item);
						listTail = parent._waitingReadersTail;
						if (listTail == null)
						{
							return true;
						}
						parent._waitingReadersTail = null;
					}
				}
				finally
				{
					if (lockTaken)
					{
						Monitor.Exit(parent.SyncObj);
					}
				}
				if (asyncOperation != null)
				{
					bool flag = asyncOperation.TrySetResult(item);
				}
				else
				{
					ChannelUtilities.WakeUpWaiters(ref listTail, result: true);
				}
				return true;
			}

			public override ValueTask<bool> WaitToWriteAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
				}
				BoundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (parent._doneWriting != null)
					{
						return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
					}
					if (parent._items.Count < parent._bufferedCapacity || parent._mode != 0)
					{
						return new ValueTask<bool>(result: true);
					}
					if (!cancellationToken.CanBeCanceled)
					{
						AsyncOperation<bool> waiterSingleton = _waiterSingleton;
						if (waiterSingleton.TryOwnAndReset())
						{
							ChannelUtilities.QueueWaiter(ref parent._waitingWritersTail, waiterSingleton);
							return waiterSingleton.ValueTaskOfT;
						}
					}
					AsyncOperation<bool> asyncOperation = new AsyncOperation<bool>(runContinuationsAsynchronously: true, cancellationToken);
					ChannelUtilities.QueueWaiter(ref parent._waitingWritersTail, asyncOperation);
					return asyncOperation.ValueTaskOfT;
				}
			}

			public override ValueTask WriteAsync(T item, CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask(Task.FromCanceled(cancellationToken));
				}
				AsyncOperation<T> asyncOperation = null;
				AsyncOperation<bool> listTail = null;
				BoundedChannel<T> parent = _parent;
				bool lockTaken = false;
				try
				{
					Monitor.Enter(parent.SyncObj, ref lockTaken);
					if (parent._doneWriting != null)
					{
						return new ValueTask(Task.FromException(ChannelUtilities.CreateInvalidCompletionException(parent._doneWriting)));
					}
					int count = parent._items.Count;
					if (count != 0)
					{
						if (count < parent._bufferedCapacity)
						{
							parent._items.EnqueueTail(item);
							return default(ValueTask);
						}
						if (parent._mode == BoundedChannelFullMode.Wait)
						{
							if (!cancellationToken.CanBeCanceled)
							{
								VoidAsyncOperationWithData<T> writerSingleton = _writerSingleton;
								if (writerSingleton.TryOwnAndReset())
								{
									writerSingleton.Item = item;
									parent._blockedWriters.EnqueueTail(writerSingleton);
									return writerSingleton.ValueTask;
								}
							}
							VoidAsyncOperationWithData<T> voidAsyncOperationWithData = new VoidAsyncOperationWithData<T>(runContinuationsAsynchronously: true, cancellationToken);
							voidAsyncOperationWithData.Item = item;
							parent._blockedWriters.EnqueueTail(voidAsyncOperationWithData);
							return voidAsyncOperationWithData.ValueTask;
						}
						if (parent._mode == BoundedChannelFullMode.DropWrite)
						{
							Monitor.Exit(parent.SyncObj);
							lockTaken = false;
							parent._itemDropped?.Invoke(item);
							return default(ValueTask);
						}
						T obj = ((parent._mode == BoundedChannelFullMode.DropNewest) ? parent._items.DequeueTail() : parent._items.DequeueHead());
						parent._items.EnqueueTail(item);
						Monitor.Exit(parent.SyncObj);
						lockTaken = false;
						parent._itemDropped?.Invoke(obj);
						return default(ValueTask);
					}
					while (!parent._blockedReaders.IsEmpty)
					{
						AsyncOperation<T> asyncOperation2 = parent._blockedReaders.DequeueHead();
						if (asyncOperation2.UnregisterCancellation())
						{
							asyncOperation = asyncOperation2;
							break;
						}
					}
					if (asyncOperation == null)
					{
						parent._items.EnqueueTail(item);
						listTail = parent._waitingReadersTail;
						if (listTail == null)
						{
							return default(ValueTask);
						}
						parent._waitingReadersTail = null;
					}
				}
				finally
				{
					if (lockTaken)
					{
						Monitor.Exit(parent.SyncObj);
					}
				}
				if (asyncOperation != null)
				{
					bool flag = asyncOperation.TrySetResult(item);
				}
				else
				{
					ChannelUtilities.WakeUpWaiters(ref listTail, result: true);
				}
				return default(ValueTask);
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		private readonly BoundedChannelFullMode _mode;

		private readonly Action<T> _itemDropped;

		private readonly TaskCompletionSource _completion;

		private readonly int _bufferedCapacity;

		private readonly Deque<T> _items = new Deque<T>();

		private readonly Deque<AsyncOperation<T>> _blockedReaders = new Deque<AsyncOperation<T>>();

		private readonly Deque<VoidAsyncOperationWithData<T>> _blockedWriters = new Deque<VoidAsyncOperationWithData<T>>();

		private AsyncOperation<bool> _waitingReadersTail;

		private AsyncOperation<bool> _waitingWritersTail;

		private readonly bool _runContinuationsAsynchronously;

		private Exception _doneWriting;

		private object SyncObj => _items;

		private int ItemsCountForDebugger => _items.Count;

		private bool ChannelIsClosedForDebugger => _doneWriting != null;

		internal BoundedChannel(int bufferedCapacity, BoundedChannelFullMode mode, bool runContinuationsAsynchronously, Action<T> itemDropped)
		{
			_bufferedCapacity = bufferedCapacity;
			_mode = mode;
			_runContinuationsAsynchronously = runContinuationsAsynchronously;
			_itemDropped = itemDropped;
			_completion = new TaskCompletionSource(runContinuationsAsynchronously ? TaskCreationOptions.RunContinuationsAsynchronously : TaskCreationOptions.None);
			base.Reader = new BoundedChannelReader(this);
			base.Writer = new BoundedChannelWriter(this);
		}

		[Conditional("DEBUG")]
		private void AssertInvariants()
		{
			_ = _items.IsEmpty;
			_ = _items.Count;
			_ = _bufferedCapacity;
			_ = _blockedReaders.IsEmpty;
			_ = _blockedWriters.IsEmpty;
			_ = _completion.Task.IsCompleted;
		}

		IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
		{
			return _items.GetEnumerator();
		}
	}
	public enum BoundedChannelFullMode
	{
		Wait,
		DropNewest,
		DropOldest,
		DropWrite
	}
	public static class Channel
	{
		public static Channel<T> CreateUnbounded<T>()
		{
			return new UnboundedChannel<T>(runContinuationsAsynchronously: true);
		}

		public static Channel<T> CreateUnbounded<T>(UnboundedChannelOptions options)
		{
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			if (options.SingleReader)
			{
				return new SingleConsumerUnboundedChannel<T>(!options.AllowSynchronousContinuations);
			}
			return new UnboundedChannel<T>(!options.AllowSynchronousContinuations);
		}

		public static Channel<T> CreateBounded<T>(int capacity)
		{
			if (capacity < 1)
			{
				throw new ArgumentOutOfRangeException("capacity");
			}
			return new BoundedChannel<T>(capacity, BoundedChannelFullMode.Wait, runContinuationsAsynchronously: true, null);
		}

		public static Channel<T> CreateBounded<T>(BoundedChannelOptions options)
		{
			return CreateBounded<T>(options, null);
		}

		public static Channel<T> CreateBounded<T>(BoundedChannelOptions options, Action<T>? itemDropped)
		{
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}
			return new BoundedChannel<T>(options.Capacity, options.FullMode, !options.AllowSynchronousContinuations, itemDropped);
		}
	}
	public class ChannelClosedException : InvalidOperationException
	{
		public ChannelClosedException()
			: base(System.SR.ChannelClosedException_DefaultMessage)
		{
		}

		public ChannelClosedException(string? message)
			: base(message)
		{
		}

		public ChannelClosedException(Exception? innerException)
			: base(System.SR.ChannelClosedException_DefaultMessage, innerException)
		{
		}

		public ChannelClosedException(string? message, Exception? innerException)
			: base(message, innerException)
		{
		}
	}
	public abstract class ChannelOptions
	{
		public bool SingleWriter { get; set; }

		public bool SingleReader { get; set; }

		public bool AllowSynchronousContinuations { get; set; }
	}
	public sealed class BoundedChannelOptions : ChannelOptions
	{
		private int _capacity;

		private BoundedChannelFullMode _mode;

		public int Capacity
		{
			get
			{
				return _capacity;
			}
			set
			{
				if (value < 1)
				{
					throw new ArgumentOutOfRangeException("value");
				}
				_capacity = value;
			}
		}

		public BoundedChannelFullMode FullMode
		{
			get
			{
				return _mode;
			}
			set
			{
				if ((uint)value <= 3u)
				{
					_mode = value;
					return;
				}
				throw new ArgumentOutOfRangeException("value");
			}
		}

		public BoundedChannelOptions(int capacity)
		{
			if (capacity < 1)
			{
				throw new ArgumentOutOfRangeException("capacity");
			}
			_capacity = capacity;
		}
	}
	public sealed class UnboundedChannelOptions : ChannelOptions
	{
	}
	public abstract class ChannelReader<T>
	{
		public virtual Task Completion => ChannelUtilities.s_neverCompletingTask;

		public virtual bool CanCount => false;

		public virtual bool CanPeek => false;

		public virtual int Count
		{
			get
			{
				throw new NotSupportedException();
			}
		}

		public abstract bool TryRead([MaybeNullWhen(false)] out T item);

		public virtual bool TryPeek([MaybeNullWhen(false)] out T item)
		{
			item = default(T);
			return false;
		}

		public abstract ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken = default(CancellationToken));

		public virtual ValueTask<T> ReadAsync(CancellationToken cancellationToken = default(CancellationToken))
		{
			if (cancellationToken.IsCancellationRequested)
			{
				return new ValueTask<T>(Task.FromCanceled<T>(cancellationToken));
			}
			try
			{
				if (TryRead(out var item))
				{
					return new ValueTask<T>(item);
				}
			}
			catch (Exception ex) when (!(ex is ChannelClosedException) && !(ex is OperationCanceledException))
			{
				return new ValueTask<T>(Task.FromException<T>(ex));
			}
			return ReadAsyncCore(cancellationToken);
			async ValueTask<T> ReadAsyncCore(CancellationToken ct)
			{
				T item2;
				do
				{
					if (!(await WaitToReadAsync(ct).ConfigureAwait(continueOnCapturedContext: false)))
					{
						throw new ChannelClosedException();
					}
				}
				while (!TryRead(out item2));
				return item2;
			}
		}
	}
	internal static class ChannelUtilities
	{
		internal static readonly Exception s_doneWritingSentinel = new Exception("s_doneWritingSentinel");

		internal static readonly Task<bool> s_trueTask = Task.FromResult(result: true);

		internal static readonly Task<bool> s_falseTask = Task.FromResult(result: false);

		internal static readonly Task s_neverCompletingTask = new TaskCompletionSource<bool>().Task;

		internal static void Complete(TaskCompletionSource tcs, Exception error = null)
		{
			if (error is OperationCanceledException ex)
			{
				tcs.TrySetCanceled(ex.CancellationToken);
			}
			else if (error != null && error != s_doneWritingSentinel)
			{
				tcs.TrySetException(error);
			}
			else
			{
				tcs.TrySetResult();
			}
		}

		internal static ValueTask<T> GetInvalidCompletionValueTask<T>(Exception error)
		{
			Task<T> task = ((error == s_doneWritingSentinel) ? Task.FromException<T>(CreateInvalidCompletionException()) : ((error is OperationCanceledException ex) ? Task.FromCanceled<T>(ex.CancellationToken.IsCancellationRequested ? ex.CancellationToken : new CancellationToken(canceled: true)) : Task.FromException<T>(CreateInvalidCompletionException(error))));
			return new ValueTask<T>(task);
		}

		internal static void QueueWaiter(ref AsyncOperation<bool> tail, AsyncOperation<bool> waiter)
		{
			AsyncOperation<bool> asyncOperation = tail;
			if (asyncOperation == null)
			{
				waiter.Next = waiter;
			}
			else
			{
				waiter.Next = asyncOperation.Next;
				asyncOperation.Next = waiter;
			}
			tail = waiter;
		}

		internal static void WakeUpWaiters(ref AsyncOperation<bool> listTail, bool result, Exception error = null)
		{
			AsyncOperation<bool> asyncOperation = listTail;
			if (asyncOperation != null)
			{
				listTail = null;
				AsyncOperation<bool> next = asyncOperation.Next;
				AsyncOperation<bool> asyncOperation2 = next;
				do
				{
					AsyncOperation<bool> next2 = asyncOperation2.Next;
					asyncOperation2.Next = null;
					bool flag = ((error != null) ? asyncOperation2.TrySetException(error) : asyncOperation2.TrySetResult(result));
					asyncOperation2 = next2;
				}
				while (asyncOperation2 != next);
			}
		}

		internal static void FailOperations<T, TInner>(Deque<T> operations, Exception error) where T : AsyncOperation<TInner>
		{
			while (!operations.IsEmpty)
			{
				operations.DequeueHead().TrySetException(error);
			}
		}

		internal static Exception CreateInvalidCompletionException(Exception inner = null)
		{
			if (!(inner is OperationCanceledException))
			{
				if (inner == null || inner == s_doneWritingSentinel)
				{
					return new ChannelClosedException();
				}
				return new ChannelClosedException(inner);
			}
			return inner;
		}
	}
	public abstract class ChannelWriter<T>
	{
		public virtual bool TryComplete(Exception? error = null)
		{
			return false;
		}

		public abstract bool TryWrite(T item);

		public abstract ValueTask<bool> WaitToWriteAsync(CancellationToken cancellationToken = default(CancellationToken));

		public virtual ValueTask WriteAsync(T item, CancellationToken cancellationToken = default(CancellationToken))
		{
			try
			{
				return cancellationToken.IsCancellationRequested ? new ValueTask(Task.FromCanceled<T>(cancellationToken)) : (TryWrite(item) ? default(ValueTask) : WriteAsyncCore(item, cancellationToken));
			}
			catch (Exception exception)
			{
				return new ValueTask(Task.FromException(exception));
			}
		}

		private async ValueTask WriteAsyncCore(T innerItem, CancellationToken ct)
		{
			while (await WaitToWriteAsync(ct).ConfigureAwait(continueOnCapturedContext: false))
			{
				if (TryWrite(innerItem))
				{
					return;
				}
			}
			throw ChannelUtilities.CreateInvalidCompletionException();
		}

		public void Complete(Exception? error = null)
		{
			if (!TryComplete(error))
			{
				throw ChannelUtilities.CreateInvalidCompletionException();
			}
		}
	}
	public abstract class Channel<T> : Channel<T, T>
	{
	}
	public abstract class Channel<TWrite, TRead>
	{
		public ChannelReader<TRead> Reader { get; protected set; }

		public ChannelWriter<TWrite> Writer { get; protected set; }

		public static implicit operator ChannelReader<TRead>(Channel<TWrite, TRead> channel)
		{
			return channel.Reader;
		}

		public static implicit operator ChannelWriter<TWrite>(Channel<TWrite, TRead> channel)
		{
			return channel.Writer;
		}
	}
	internal interface IDebugEnumerable<T>
	{
		IEnumerator<T> GetEnumerator();
	}
	internal sealed class DebugEnumeratorDebugView<T>
	{
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
		public T[] Items { get; }

		public DebugEnumeratorDebugView(IDebugEnumerable<T> enumerable)
		{
			List<T> list = new List<T>();
			foreach (T item in enumerable)
			{
				list.Add(item);
			}
			Items = list.ToArray();
		}
	}
	[DebuggerDisplay("Items={ItemsCountForDebugger}, Closed={ChannelIsClosedForDebugger}")]
	[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
	internal sealed class SingleConsumerUnboundedChannel<T> : Channel<T>, IDebugEnumerable<T>
	{
		[DebuggerDisplay("Items={ItemsCountForDebugger}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class UnboundedChannelReader : ChannelReader<T>, IDebugEnumerable<T>
		{
			internal readonly SingleConsumerUnboundedChannel<T> _parent;

			private readonly AsyncOperation<T> _readerSingleton;

			private readonly AsyncOperation<bool> _waiterSingleton;

			public override Task Completion => _parent._completion.Task;

			public override bool CanPeek => true;

			private int ItemsCountForDebugger => _parent._items.Count;

			internal UnboundedChannelReader(SingleConsumerUnboundedChannel<T> parent)
			{
				_parent = parent;
				_readerSingleton = new AsyncOperation<T>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
				_waiterSingleton = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
			}

			public override ValueTask<T> ReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<T>(Task.FromCanceled<T>(cancellationToken));
				}
				if (TryRead(out var item))
				{
					return new ValueTask<T>(item);
				}
				SingleConsumerUnboundedChannel<T> parent = _parent;
				AsyncOperation<T> asyncOperation;
				AsyncOperation<T> asyncOperation2;
				lock (parent.SyncObj)
				{
					if (TryRead(out item))
					{
						return new ValueTask<T>(item);
					}
					if (parent._doneWriting != null)
					{
						return ChannelUtilities.GetInvalidCompletionValueTask<T>(parent._doneWriting);
					}
					asyncOperation = parent._blockedReader;
					if (!cancellationToken.CanBeCanceled && _readerSingleton.TryOwnAndReset())
					{
						asyncOperation2 = _readerSingleton;
						if (asyncOperation2 == asyncOperation)
						{
							asyncOperation = null;
						}
					}
					else
					{
						asyncOperation2 = new AsyncOperation<T>(_parent._runContinuationsAsynchronously, cancellationToken);
					}
					parent._blockedReader = asyncOperation2;
				}
				asyncOperation?.TrySetCanceled();
				return asyncOperation2.ValueTaskOfT;
			}

			public override bool TryRead([MaybeNullWhen(false)] out T item)
			{
				SingleConsumerUnboundedChannel<T> parent = _parent;
				if (parent._items.TryDequeue(out item))
				{
					if (parent._doneWriting != null && parent._items.IsEmpty)
					{
						ChannelUtilities.Complete(parent._completion, parent._doneWriting);
					}
					return true;
				}
				return false;
			}

			public override bool TryPeek([MaybeNullWhen(false)] out T item)
			{
				return _parent._items.TryPeek(out item);
			}

			public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
				}
				if (!_parent._items.IsEmpty)
				{
					return new ValueTask<bool>(result: true);
				}
				SingleConsumerUnboundedChannel<T> parent = _parent;
				AsyncOperation<bool> asyncOperation = null;
				AsyncOperation<bool> asyncOperation2;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						return new ValueTask<bool>(result: true);
					}
					if (parent._doneWriting != null)
					{
						return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
					}
					asyncOperation = parent._waitingReader;
					if (!cancellationToken.CanBeCanceled && _waiterSingleton.TryOwnAndReset())
					{
						asyncOperation2 = _waiterSingleton;
						if (asyncOperation2 == asyncOperation)
						{
							asyncOperation = null;
						}
					}
					else
					{
						asyncOperation2 = new AsyncOperation<bool>(_parent._runContinuationsAsynchronously, cancellationToken);
					}
					parent._waitingReader = asyncOperation2;
				}
				asyncOperation?.TrySetCanceled();
				return asyncOperation2.ValueTaskOfT;
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		[DebuggerDisplay("Items={ItemsCountForDebugger}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class UnboundedChannelWriter : ChannelWriter<T>, IDebugEnumerable<T>
		{
			internal readonly SingleConsumerUnboundedChannel<T> _parent;

			private int ItemsCountForDebugger => _parent._items.Count;

			internal UnboundedChannelWriter(SingleConsumerUnboundedChannel<T> parent)
			{
				_parent = parent;
			}

			public override bool TryComplete(Exception error)
			{
				AsyncOperation<T> asyncOperation = null;
				AsyncOperation<bool> asyncOperation2 = null;
				bool flag = false;
				SingleConsumerUnboundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (parent._doneWriting != null)
					{
						return false;
					}
					parent._doneWriting = error ?? ChannelUtilities.s_doneWritingSentinel;
					if (parent._items.IsEmpty)
					{
						flag = true;
						if (parent._blockedReader != null)
						{
							asyncOperation = parent._blockedReader;
							parent._blockedReader = null;
						}
						if (parent._waitingReader != null)
						{
							asyncOperation2 = parent._waitingReader;
							parent._waitingReader = null;
						}
					}
				}
				if (flag)
				{
					ChannelUtilities.Complete(parent._completion, error);
				}
				if (asyncOperation != null)
				{
					error = ChannelUtilities.CreateInvalidCompletionException(error);
					asyncOperation.TrySetException(error);
				}
				if (asyncOperation2 != null)
				{
					if (error != null)
					{
						asyncOperation2.TrySetException(error);
					}
					else
					{
						asyncOperation2.TrySetResult(item: false);
					}
				}
				return true;
			}

			public override bool TryWrite(T item)
			{
				SingleConsumerUnboundedChannel<T> parent = _parent;
				AsyncOperation<T> asyncOperation;
				do
				{
					asyncOperation = null;
					AsyncOperation<bool> asyncOperation2 = null;
					lock (parent.SyncObj)
					{
						if (parent._doneWriting != null)
						{
							return false;
						}
						asyncOperation = parent._blockedReader;
						if (asyncOperation != null)
						{
							parent._blockedReader = null;
						}
						else
						{
							parent._items.Enqueue(item);
							asyncOperation2 = parent._waitingReader;
							if (asyncOperation2 == null)
							{
								return true;
							}
							parent._waitingReader = null;
						}
					}
					if (asyncOperation2 != null)
					{
						asyncOperation2.TrySetResult(item: true);
						return true;
					}
				}
				while (!asyncOperation.TrySetResult(item));
				return true;
			}

			public override ValueTask<bool> WaitToWriteAsync(CancellationToken cancellationToken)
			{
				Exception doneWriting = _parent._doneWriting;
				if (!cancellationToken.IsCancellationRequested)
				{
					if (doneWriting != null)
					{
						if (doneWriting == ChannelUtilities.s_doneWritingSentinel)
						{
							return default(ValueTask<bool>);
						}
						return new ValueTask<bool>(Task.FromException<bool>(doneWriting));
					}
					return new ValueTask<bool>(result: true);
				}
				return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
			}

			public override ValueTask WriteAsync(T item, CancellationToken cancellationToken)
			{
				if (!cancellationToken.IsCancellationRequested)
				{
					if (!TryWrite(item))
					{
						return new ValueTask(Task.FromException(ChannelUtilities.CreateInvalidCompletionException(_parent._doneWriting)));
					}
					return default(ValueTask);
				}
				return new ValueTask(Task.FromCanceled(cancellationToken));
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		private readonly TaskCompletionSource _completion;

		private readonly SingleProducerSingleConsumerQueue<T> _items = new SingleProducerSingleConsumerQueue<T>();

		private readonly bool _runContinuationsAsynchronously;

		private volatile Exception _doneWriting;

		private AsyncOperation<T> _blockedReader;

		private AsyncOperation<bool> _waitingReader;

		private object SyncObj => _items;

		private int ItemsCountForDebugger => _items.Count;

		private bool ChannelIsClosedForDebugger => _doneWriting != null;

		internal SingleConsumerUnboundedChannel(bool runContinuationsAsynchronously)
		{
			_runContinuationsAsynchronously = runContinuationsAsynchronously;
			_completion = new TaskCompletionSource(runContinuationsAsynchronously ? TaskCreationOptions.RunContinuationsAsynchronously : TaskCreationOptions.None);
			base.Reader = new UnboundedChannelReader(this);
			base.Writer = new UnboundedChannelWriter(this);
		}

		IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
		{
			return _items.GetEnumerator();
		}
	}
	internal sealed class TaskCompletionSource : TaskCompletionSource<VoidResult>
	{
		public TaskCompletionSource(TaskCreationOptions creationOptions)
			: base(creationOptions)
		{
		}

		public bool TrySetResult()
		{
			return TrySetResult(default(VoidResult));
		}
	}
	[DebuggerDisplay("Items={ItemsCountForDebugger}, Closed={ChannelIsClosedForDebugger}")]
	[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
	internal sealed class UnboundedChannel<T> : Channel<T>, IDebugEnumerable<T>
	{
		[DebuggerDisplay("Items={Count}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class UnboundedChannelReader : ChannelReader<T>, IDebugEnumerable<T>
		{
			internal readonly UnboundedChannel<T> _parent;

			private readonly AsyncOperation<T> _readerSingleton;

			private readonly AsyncOperation<bool> _waiterSingleton;

			public override Task Completion => _parent._completion.Task;

			public override bool CanCount => true;

			public override bool CanPeek => true;

			public override int Count => _parent._items.Count;

			internal UnboundedChannelReader(UnboundedChannel<T> parent)
			{
				_parent = parent;
				_readerSingleton = new AsyncOperation<T>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
				_waiterSingleton = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, default(CancellationToken), pooled: true);
			}

			public override ValueTask<T> ReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<T>(Task.FromCanceled<T>(cancellationToken));
				}
				UnboundedChannel<T> parent = _parent;
				if (parent._items.TryDequeue(out var result))
				{
					CompleteIfDone(parent);
					return new ValueTask<T>(result);
				}
				lock (parent.SyncObj)
				{
					if (parent._items.TryDequeue(out result))
					{
						CompleteIfDone(parent);
						return new ValueTask<T>(result);
					}
					if (parent._doneWriting != null)
					{
						return ChannelUtilities.GetInvalidCompletionValueTask<T>(parent._doneWriting);
					}
					if (!cancellationToken.CanBeCanceled)
					{
						AsyncOperation<T> readerSingleton = _readerSingleton;
						if (readerSingleton.TryOwnAndReset())
						{
							parent._blockedReaders.EnqueueTail(readerSingleton);
							return readerSingleton.ValueTaskOfT;
						}
					}
					AsyncOperation<T> asyncOperation = new AsyncOperation<T>(parent._runContinuationsAsynchronously, cancellationToken);
					parent._blockedReaders.EnqueueTail(asyncOperation);
					return asyncOperation.ValueTaskOfT;
				}
			}

			public override bool TryRead([MaybeNullWhen(false)] out T item)
			{
				UnboundedChannel<T> parent = _parent;
				if (parent._items.TryDequeue(out item))
				{
					CompleteIfDone(parent);
					return true;
				}
				item = default(T);
				return false;
			}

			public override bool TryPeek([MaybeNullWhen(false)] out T item)
			{
				return _parent._items.TryPeek(out item);
			}

			private static void CompleteIfDone(UnboundedChannel<T> parent)
			{
				if (parent._doneWriting != null && parent._items.IsEmpty)
				{
					ChannelUtilities.Complete(parent._completion, parent._doneWriting);
				}
			}

			public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
				}
				if (!_parent._items.IsEmpty)
				{
					return new ValueTask<bool>(result: true);
				}
				UnboundedChannel<T> parent = _parent;
				lock (parent.SyncObj)
				{
					if (!parent._items.IsEmpty)
					{
						return new ValueTask<bool>(result: true);
					}
					if (parent._doneWriting != null)
					{
						return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
					}
					if (!cancellationToken.CanBeCanceled)
					{
						AsyncOperation<bool> waiterSingleton = _waiterSingleton;
						if (waiterSingleton.TryOwnAndReset())
						{
							ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, waiterSingleton);
							return waiterSingleton.ValueTaskOfT;
						}
					}
					AsyncOperation<bool> asyncOperation = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, cancellationToken);
					ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, asyncOperation);
					return asyncOperation.ValueTaskOfT;
				}
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		[DebuggerDisplay("Items={ItemsCountForDebugger}")]
		[DebuggerTypeProxy(typeof(DebugEnumeratorDebugView<>))]
		private sealed class UnboundedChannelWriter : ChannelWriter<T>, IDebugEnumerable<T>
		{
			internal readonly UnboundedChannel<T> _parent;

			private int ItemsCountForDebugger => _parent._items.Count;

			internal UnboundedChannelWriter(UnboundedChannel<T> parent)
			{
				_parent = parent;
			}

			public override bool TryComplete(Exception error)
			{
				UnboundedChannel<T> parent = _parent;
				bool isEmpty;
				lock (parent.SyncObj)
				{
					if (parent._doneWriting != null)
					{
						return false;
					}
					parent._doneWriting = error ?? ChannelUtilities.s_doneWritingSentinel;
					isEmpty = parent._items.IsEmpty;
				}
				if (isEmpty)
				{
					ChannelUtilities.Complete(parent._completion, error);
				}
				ChannelUtilities.FailOperations<AsyncOperation<T>, T>(parent._blockedReaders, ChannelUtilities.CreateInvalidCompletionException(error));
				ChannelUtilities.WakeUpWaiters(ref parent._waitingReadersTail, result: false, error);
				return true;
			}

			public override bool TryWrite(T item)
			{
				UnboundedChannel<T> parent = _parent;
				AsyncOperation<bool> listTail;
				while (true)
				{
					AsyncOperation<T> asyncOperation = null;
					listTail = null;
					lock (parent.SyncObj)
					{
						if (parent._doneWriting != null)
						{
							return false;
						}
						if (parent._blockedReaders.IsEmpty)
						{
							parent._items.Enqueue(item);
							listTail = parent._waitingReadersTail;
							if (listTail == null)
							{
								return true;
							}
							parent._waitingReadersTail = null;
						}
						else
						{
							asyncOperation = parent._blockedReaders.DequeueHead();
						}
					}
					if (asyncOperation == null)
					{
						break;
					}
					if (asyncOperation.TrySetResult(item))
					{
						return true;
					}
				}
				ChannelUtilities.WakeUpWaiters(ref listTail, result: true);
				return true;
			}

			public override ValueTask<bool> WaitToWriteAsync(CancellationToken cancellationToken)
			{
				Exception doneWriting = _parent._doneWriting;
				if (!cancellationToken.IsCancellationRequested)
				{
					if (doneWriting != null)
					{
						if (doneWriting == ChannelUtilities.s_doneWritingSentinel)
						{
							return default(ValueTask<bool>);
						}
						return new ValueTask<bool>(Task.FromException<bool>(doneWriting));
					}
					return new ValueTask<bool>(result: true);
				}
				return new ValueTask<bool>(Task.FromCanceled<bool>(cancellationToken));
			}

			public override ValueTask WriteAsync(T item, CancellationToken cancellationToken)
			{
				if (!cancellationToken.IsCancellationRequested)
				{
					if (!TryWrite(item))
					{
						return new ValueTask(Task.FromException(ChannelUtilities.CreateInvalidCompletionException(_parent._doneWriting)));
					}
					return default(ValueTask);
				}
				return new ValueTask(Task.FromCanceled(cancellationToken));
			}

			IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
			{
				return _parent._items.GetEnumerator();
			}
		}

		private readonly TaskCompletionSource _completion;

		private readonly ConcurrentQueue<T> _items = new ConcurrentQueue<T>();

		private readonly Deque<AsyncOperation<T>> _blockedReaders = new Deque<AsyncOperation<T>>();

		private readonly bool _runContinuationsAsynchronously;

		private AsyncOperation<bool> _waitingReadersTail;

		private Exception _doneWriting;

		private object SyncObj => _items;

		private int ItemsCountForDebugger => _items.Count;

		private bool ChannelIsClosedForDebugger => _doneWriting != null;

		internal UnboundedChannel(bool runContinuationsAsynchronously)
		{
			_runContinuationsAsynchronously = runContinuationsAsynchronously;
			_completion = new TaskCompletionSource(runContinuationsAsynchronously ? TaskCreationOptions.RunContinuationsAsynchronously : TaskCreationOptions.None);
			base.Reader = new UnboundedChannelReader(this);
			base.Writer = new UnboundedChannelWriter(this);
		}

		[Conditional("DEBUG")]
		private void AssertInvariants()
		{
			if (!_items.IsEmpty)
			{
				_ = _runContinuationsAsynchronously;
			}
			if (!_blockedReaders.IsEmpty || _waitingReadersTail != null)
			{
				_ = _runContinuationsAsynchronously;
			}
			_ = _completion.Task.IsCompleted;
		}

		IEnumerator<T> IDebugEnumerable<T>.GetEnumerator()
		{
			return _items.GetEnumerator();
		}
	}
}

plugins/System.Threading.Tasks.Extensions.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Threading.Tasks.Extensions")]
[assembly: AssemblyDescription("System.Threading.Tasks.Extensions")]
[assembly: AssemblyDefaultAlias("System.Threading.Tasks.Extensions")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyFileVersion("4.6.28619.01")]
[assembly: AssemblyInformationalVersion("4.6.28619.01 @BuiltBy: dlab14-DDVSOWINAGE069 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/7601f4f6225089ffb291dc7d58293c7bbf5c5d4f")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyVersion("4.2.0.1")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}
namespace System
{
	internal static class ThrowHelper
	{
		internal static void ThrowArgumentNullException(System.ExceptionArgument argument)
		{
			throw GetArgumentNullException(argument);
		}

		internal static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
		{
			throw GetArgumentOutOfRangeException(argument);
		}

		private static ArgumentNullException GetArgumentNullException(System.ExceptionArgument argument)
		{
			return new ArgumentNullException(GetArgumentName(argument));
		}

		private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(System.ExceptionArgument argument)
		{
			return new ArgumentOutOfRangeException(GetArgumentName(argument));
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static string GetArgumentName(System.ExceptionArgument argument)
		{
			return argument.ToString();
		}
	}
	internal enum ExceptionArgument
	{
		task,
		source,
		state
	}
}
namespace System.Threading.Tasks
{
	[StructLayout(LayoutKind.Auto)]
	[AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))]
	public readonly struct ValueTask : IEquatable<ValueTask>
	{
		private sealed class ValueTaskSourceAsTask : TaskCompletionSource<bool>
		{
			private static readonly Action<object> s_completionAction = delegate(object state)
			{
				IValueTaskSource source;
				if (!(state is ValueTaskSourceAsTask valueTaskSourceAsTask) || (source = valueTaskSourceAsTask._source) == null)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.state);
					return;
				}
				valueTaskSourceAsTask._source = null;
				ValueTaskSourceStatus status = source.GetStatus(valueTaskSourceAsTask._token);
				try
				{
					source.GetResult(valueTaskSourceAsTask._token);
					valueTaskSourceAsTask.TrySetResult(result: false);
				}
				catch (Exception exception)
				{
					if (status == ValueTaskSourceStatus.Canceled)
					{
						valueTaskSourceAsTask.TrySetCanceled();
					}
					else
					{
						valueTaskSourceAsTask.TrySetException(exception);
					}
				}
			};

			private IValueTaskSource _source;

			private readonly short _token;

			public ValueTaskSourceAsTask(IValueTaskSource source, short token)
			{
				_token = token;
				_source = source;
				source.OnCompleted(s_completionAction, this, token, ValueTaskSourceOnCompletedFlags.None);
			}
		}

		private static readonly Task s_canceledTask = Task.Delay(-1, new CancellationToken(canceled: true));

		internal readonly object _obj;

		internal readonly short _token;

		internal readonly bool _continueOnCapturedContext;

		internal static Task CompletedTask { get; } = Task.Delay(0);


		public bool IsCompleted
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return true;
				}
				if (obj is Task task)
				{
					return task.IsCompleted;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) != ValueTaskSourceStatus.Pending;
			}
		}

		public bool IsCompletedSuccessfully
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return true;
				}
				if (obj is Task task)
				{
					return task.Status == TaskStatus.RanToCompletion;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Succeeded;
			}
		}

		public bool IsFaulted
		{
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return false;
				}
				if (obj is Task task)
				{
					return task.IsFaulted;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted;
			}
		}

		public bool IsCanceled
		{
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return false;
				}
				if (obj is Task task)
				{
					return task.IsCanceled;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTask(Task task)
		{
			if (task == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.task);
			}
			_obj = task;
			_continueOnCapturedContext = true;
			_token = 0;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTask(IValueTaskSource source, short token)
		{
			if (source == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.source);
			}
			_obj = source;
			_token = token;
			_continueOnCapturedContext = true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private ValueTask(object obj, short token, bool continueOnCapturedContext)
		{
			_obj = obj;
			_token = token;
			_continueOnCapturedContext = continueOnCapturedContext;
		}

		public override int GetHashCode()
		{
			return _obj?.GetHashCode() ?? 0;
		}

		public override bool Equals(object obj)
		{
			if (obj is ValueTask)
			{
				return Equals((ValueTask)obj);
			}
			return false;
		}

		public bool Equals(ValueTask other)
		{
			if (_obj == other._obj)
			{
				return _token == other._token;
			}
			return false;
		}

		public static bool operator ==(ValueTask left, ValueTask right)
		{
			return left.Equals(right);
		}

		public static bool operator !=(ValueTask left, ValueTask right)
		{
			return !left.Equals(right);
		}

		public Task AsTask()
		{
			object obj = _obj;
			object obj2;
			if (obj != null)
			{
				obj2 = obj as Task;
				if (obj2 == null)
				{
					return GetTaskForValueTaskSource(System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj));
				}
			}
			else
			{
				obj2 = CompletedTask;
			}
			return (Task)obj2;
		}

		public ValueTask Preserve()
		{
			if (_obj != null)
			{
				return new ValueTask(AsTask());
			}
			return this;
		}

		private Task GetTaskForValueTaskSource(IValueTaskSource t)
		{
			ValueTaskSourceStatus status = t.GetStatus(_token);
			if (status != 0)
			{
				try
				{
					t.GetResult(_token);
					return CompletedTask;
				}
				catch (Exception exception)
				{
					if (status == ValueTaskSourceStatus.Canceled)
					{
						return s_canceledTask;
					}
					TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
					taskCompletionSource.TrySetException(exception);
					return taskCompletionSource.Task;
				}
			}
			ValueTaskSourceAsTask valueTaskSourceAsTask = new ValueTaskSourceAsTask(t, _token);
			return valueTaskSourceAsTask.Task;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[StackTraceHidden]
		internal void ThrowIfCompletedUnsuccessfully()
		{
			object obj = _obj;
			if (obj != null)
			{
				if (obj is Task task)
				{
					task.GetAwaiter().GetResult();
				}
				else
				{
					System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).GetResult(_token);
				}
			}
		}

		public ValueTaskAwaiter GetAwaiter()
		{
			return new ValueTaskAwaiter(this);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
		{
			return new ConfiguredValueTaskAwaitable(new ValueTask(_obj, _token, continueOnCapturedContext));
		}
	}
	[StructLayout(LayoutKind.Auto)]
	[AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))]
	public readonly struct ValueTask<TResult> : IEquatable<ValueTask<TResult>>
	{
		private sealed class ValueTaskSourceAsTask : TaskCompletionSource<TResult>
		{
			private static readonly Action<object> s_completionAction = delegate(object state)
			{
				IValueTaskSource<TResult> source;
				if (!(state is ValueTaskSourceAsTask valueTaskSourceAsTask) || (source = valueTaskSourceAsTask._source) == null)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.state);
					return;
				}
				valueTaskSourceAsTask._source = null;
				ValueTaskSourceStatus status = source.GetStatus(valueTaskSourceAsTask._token);
				try
				{
					valueTaskSourceAsTask.TrySetResult(source.GetResult(valueTaskSourceAsTask._token));
				}
				catch (Exception exception)
				{
					if (status == ValueTaskSourceStatus.Canceled)
					{
						valueTaskSourceAsTask.TrySetCanceled();
					}
					else
					{
						valueTaskSourceAsTask.TrySetException(exception);
					}
				}
			};

			private IValueTaskSource<TResult> _source;

			private readonly short _token;

			public ValueTaskSourceAsTask(IValueTaskSource<TResult> source, short token)
			{
				_source = source;
				_token = token;
				source.OnCompleted(s_completionAction, this, token, ValueTaskSourceOnCompletedFlags.None);
			}
		}

		private static Task<TResult> s_canceledTask;

		internal readonly object _obj;

		internal readonly TResult _result;

		internal readonly short _token;

		internal readonly bool _continueOnCapturedContext;

		public bool IsCompleted
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return true;
				}
				if (obj is Task<TResult> task)
				{
					return task.IsCompleted;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) != ValueTaskSourceStatus.Pending;
			}
		}

		public bool IsCompletedSuccessfully
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return true;
				}
				if (obj is Task<TResult> task)
				{
					return task.Status == TaskStatus.RanToCompletion;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Succeeded;
			}
		}

		public bool IsFaulted
		{
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return false;
				}
				if (obj is Task<TResult> task)
				{
					return task.IsFaulted;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted;
			}
		}

		public bool IsCanceled
		{
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return false;
				}
				if (obj is Task<TResult> task)
				{
					return task.IsCanceled;
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled;
			}
		}

		public TResult Result
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				object obj = _obj;
				if (obj == null)
				{
					return _result;
				}
				if (obj is Task<TResult> task)
				{
					return task.GetAwaiter().GetResult();
				}
				return System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).GetResult(_token);
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTask(TResult result)
		{
			_result = result;
			_obj = null;
			_continueOnCapturedContext = true;
			_token = 0;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTask(Task<TResult> task)
		{
			if (task == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.task);
			}
			_obj = task;
			_result = default(TResult);
			_continueOnCapturedContext = true;
			_token = 0;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTask(IValueTaskSource<TResult> source, short token)
		{
			if (source == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.source);
			}
			_obj = source;
			_token = token;
			_result = default(TResult);
			_continueOnCapturedContext = true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private ValueTask(object obj, TResult result, short token, bool continueOnCapturedContext)
		{
			_obj = obj;
			_result = result;
			_token = token;
			_continueOnCapturedContext = continueOnCapturedContext;
		}

		public override int GetHashCode()
		{
			if (_obj == null)
			{
				if (_result == null)
				{
					return 0;
				}
				return _result.GetHashCode();
			}
			return _obj.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj is ValueTask<TResult>)
			{
				return Equals((ValueTask<TResult>)obj);
			}
			return false;
		}

		public bool Equals(ValueTask<TResult> other)
		{
			if (_obj == null && other._obj == null)
			{
				return EqualityComparer<TResult>.Default.Equals(_result, other._result);
			}
			if (_obj == other._obj)
			{
				return _token == other._token;
			}
			return false;
		}

		public static bool operator ==(ValueTask<TResult> left, ValueTask<TResult> right)
		{
			return left.Equals(right);
		}

		public static bool operator !=(ValueTask<TResult> left, ValueTask<TResult> right)
		{
			return !left.Equals(right);
		}

		public Task<TResult> AsTask()
		{
			object obj = _obj;
			if (obj == null)
			{
				return Task.FromResult(_result);
			}
			if (obj is Task<TResult> result)
			{
				return result;
			}
			return GetTaskForValueTaskSource(System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj));
		}

		public ValueTask<TResult> Preserve()
		{
			if (_obj != null)
			{
				return new ValueTask<TResult>(AsTask());
			}
			return this;
		}

		private Task<TResult> GetTaskForValueTaskSource(IValueTaskSource<TResult> t)
		{
			ValueTaskSourceStatus status = t.GetStatus(_token);
			if (status != 0)
			{
				try
				{
					return Task.FromResult(t.GetResult(_token));
				}
				catch (Exception exception)
				{
					if (status == ValueTaskSourceStatus.Canceled)
					{
						Task<TResult> task = s_canceledTask;
						if (task == null)
						{
							TaskCompletionSource<TResult> taskCompletionSource = new TaskCompletionSource<TResult>();
							taskCompletionSource.TrySetCanceled();
							task = (s_canceledTask = taskCompletionSource.Task);
						}
						return task;
					}
					TaskCompletionSource<TResult> taskCompletionSource2 = new TaskCompletionSource<TResult>();
					taskCompletionSource2.TrySetException(exception);
					return taskCompletionSource2.Task;
				}
			}
			ValueTaskSourceAsTask valueTaskSourceAsTask = new ValueTaskSourceAsTask(t, _token);
			return valueTaskSourceAsTask.Task;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ValueTaskAwaiter<TResult> GetAwaiter()
		{
			return new ValueTaskAwaiter<TResult>(this);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ConfiguredValueTaskAwaitable<TResult> ConfigureAwait(bool continueOnCapturedContext)
		{
			return new ConfiguredValueTaskAwaitable<TResult>(new ValueTask<TResult>(_obj, _result, _token, continueOnCapturedContext));
		}

		public override string ToString()
		{
			if (IsCompletedSuccessfully)
			{
				TResult result = Result;
				if (result != null)
				{
					return result.ToString();
				}
			}
			return string.Empty;
		}
	}
}
namespace System.Threading.Tasks.Sources
{
	[Flags]
	public enum ValueTaskSourceOnCompletedFlags
	{
		None = 0,
		UseSchedulingContext = 1,
		FlowExecutionContext = 2
	}
	public enum ValueTaskSourceStatus
	{
		Pending,
		Succeeded,
		Faulted,
		Canceled
	}
	public interface IValueTaskSource
	{
		ValueTaskSourceStatus GetStatus(short token);

		void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags);

		void GetResult(short token);
	}
	public interface IValueTaskSource<out TResult>
	{
		ValueTaskSourceStatus GetStatus(short token);

		void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags);

		TResult GetResult(short token);
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
	public sealed class AsyncMethodBuilderAttribute : Attribute
	{
		public Type BuilderType { get; }

		public AsyncMethodBuilderAttribute(Type builderType)
		{
			BuilderType = builderType;
		}
	}
	[StructLayout(LayoutKind.Auto)]
	public struct AsyncValueTaskMethodBuilder
	{
		private AsyncTaskMethodBuilder _methodBuilder;

		private bool _haveResult;

		private bool _useBuilder;

		public ValueTask Task
		{
			get
			{
				if (_haveResult)
				{
					return default(ValueTask);
				}
				_useBuilder = true;
				return new ValueTask(_methodBuilder.Task);
			}
		}

		public static AsyncValueTaskMethodBuilder Create()
		{
			return default(AsyncValueTaskMethodBuilder);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
		{
			_methodBuilder.Start(ref stateMachine);
		}

		public void SetStateMachine(IAsyncStateMachine stateMachine)
		{
			_methodBuilder.SetStateMachine(stateMachine);
		}

		public void SetResult()
		{
			if (_useBuilder)
			{
				_methodBuilder.SetResult();
			}
			else
			{
				_haveResult = true;
			}
		}

		public void SetException(Exception exception)
		{
			_methodBuilder.SetException(exception);
		}

		public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
		{
			_useBuilder = true;
			_methodBuilder.AwaitOnCompleted(ref awaiter, ref stateMachine);
		}

		[SecuritySafeCritical]
		public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
		{
			_useBuilder = true;
			_methodBuilder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
		}
	}
	[StructLayout(LayoutKind.Auto)]
	public struct AsyncValueTaskMethodBuilder<TResult>
	{
		private AsyncTaskMethodBuilder<TResult> _methodBuilder;

		private TResult _result;

		private bool _haveResult;

		private bool _useBuilder;

		public ValueTask<TResult> Task
		{
			get
			{
				if (_haveResult)
				{
					return new ValueTask<TResult>(_result);
				}
				_useBuilder = true;
				return new ValueTask<TResult>(_methodBuilder.Task);
			}
		}

		public static AsyncValueTaskMethodBuilder<TResult> Create()
		{
			return default(AsyncValueTaskMethodBuilder<TResult>);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
		{
			_methodBuilder.Start(ref stateMachine);
		}

		public void SetStateMachine(IAsyncStateMachine stateMachine)
		{
			_methodBuilder.SetStateMachine(stateMachine);
		}

		public void SetResult(TResult result)
		{
			if (_useBuilder)
			{
				_methodBuilder.SetResult(result);
				return;
			}
			_result = result;
			_haveResult = true;
		}

		public void SetException(Exception exception)
		{
			_methodBuilder.SetException(exception);
		}

		public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
		{
			_useBuilder = true;
			_methodBuilder.AwaitOnCompleted(ref awaiter, ref stateMachine);
		}

		[SecuritySafeCritical]
		public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
		{
			_useBuilder = true;
			_methodBuilder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
		}
	}
	[StructLayout(LayoutKind.Auto)]
	public readonly struct ConfiguredValueTaskAwaitable
	{
		[StructLayout(LayoutKind.Auto)]
		public readonly struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
		{
			private readonly ValueTask _value;

			public bool IsCompleted
			{
				[MethodImpl(MethodImplOptions.AggressiveInlining)]
				get
				{
					return _value.IsCompleted;
				}
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			internal ConfiguredValueTaskAwaiter(ValueTask value)
			{
				_value = value;
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			[StackTraceHidden]
			public void GetResult()
			{
				_value.ThrowIfCompletedUnsuccessfully();
			}

			public void OnCompleted(Action continuation)
			{
				object obj = _value._obj;
				if (obj is Task task)
				{
					task.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
				}
				else if (obj != null)
				{
					System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.FlowExecutionContext | (_value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None));
				}
				else
				{
					ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
				}
			}

			public void UnsafeOnCompleted(Action continuation)
			{
				object obj = _value._obj;
				if (obj is Task task)
				{
					task.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
				}
				else if (obj != null)
				{
					System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
				}
				else
				{
					ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
				}
			}
		}

		private readonly ValueTask _value;

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ConfiguredValueTaskAwaitable(ValueTask value)
		{
			_value = value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ConfiguredValueTaskAwaiter GetAwaiter()
		{
			return new ConfiguredValueTaskAwaiter(_value);
		}
	}
	[StructLayout(LayoutKind.Auto)]
	public readonly struct ConfiguredValueTaskAwaitable<TResult>
	{
		[StructLayout(LayoutKind.Auto)]
		public readonly struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
		{
			private readonly ValueTask<TResult> _value;

			public bool IsCompleted
			{
				[MethodImpl(MethodImplOptions.AggressiveInlining)]
				get
				{
					return _value.IsCompleted;
				}
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			internal ConfiguredValueTaskAwaiter(ValueTask<TResult> value)
			{
				_value = value;
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			[StackTraceHidden]
			public TResult GetResult()
			{
				return _value.Result;
			}

			public void OnCompleted(Action continuation)
			{
				object obj = _value._obj;
				if (obj is Task<TResult> task)
				{
					task.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
				}
				else if (obj != null)
				{
					System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.FlowExecutionContext | (_value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None));
				}
				else
				{
					ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
				}
			}

			public void UnsafeOnCompleted(Action continuation)
			{
				object obj = _value._obj;
				if (obj is Task<TResult> task)
				{
					task.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
				}
				else if (obj != null)
				{
					System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
				}
				else
				{
					ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
				}
			}
		}

		private readonly ValueTask<TResult> _value;

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ConfiguredValueTaskAwaitable(ValueTask<TResult> value)
		{
			_value = value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ConfiguredValueTaskAwaiter GetAwaiter()
		{
			return new ConfiguredValueTaskAwaiter(_value);
		}
	}
	public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
	{
		internal static readonly Action<object> s_invokeActionDelegate = delegate(object state)
		{
			if (!(state is Action action))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.state);
			}
			else
			{
				action();
			}
		};

		private readonly ValueTask _value;

		public bool IsCompleted
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return _value.IsCompleted;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ValueTaskAwaiter(ValueTask value)
		{
			_value = value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[StackTraceHidden]
		public void GetResult()
		{
			_value.ThrowIfCompletedUnsuccessfully();
		}

		public void OnCompleted(Action continuation)
		{
			object obj = _value._obj;
			if (obj is Task task)
			{
				task.GetAwaiter().OnCompleted(continuation);
			}
			else if (obj != null)
			{
				System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).OnCompleted(s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext | ValueTaskSourceOnCompletedFlags.FlowExecutionContext);
			}
			else
			{
				ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation);
			}
		}

		public void UnsafeOnCompleted(Action continuation)
		{
			object obj = _value._obj;
			if (obj is Task task)
			{
				task.GetAwaiter().UnsafeOnCompleted(continuation);
			}
			else if (obj != null)
			{
				System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource>(obj).OnCompleted(s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
			}
			else
			{
				ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation);
			}
		}
	}
	public readonly struct ValueTaskAwaiter<TResult> : ICriticalNotifyCompletion, INotifyCompletion
	{
		private readonly ValueTask<TResult> _value;

		public bool IsCompleted
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return _value.IsCompleted;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ValueTaskAwaiter(ValueTask<TResult> value)
		{
			_value = value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[StackTraceHidden]
		public TResult GetResult()
		{
			return _value.Result;
		}

		public void OnCompleted(Action continuation)
		{
			object obj = _value._obj;
			if (obj is Task<TResult> task)
			{
				task.GetAwaiter().OnCompleted(continuation);
			}
			else if (obj != null)
			{
				System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext | ValueTaskSourceOnCompletedFlags.FlowExecutionContext);
			}
			else
			{
				ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation);
			}
		}

		public void UnsafeOnCompleted(Action continuation)
		{
			object obj = _value._obj;
			if (obj is Task<TResult> task)
			{
				task.GetAwaiter().UnsafeOnCompleted(continuation);
			}
			else if (obj != null)
			{
				System.Runtime.CompilerServices.Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
			}
			else
			{
				ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation);
			}
		}
	}
}
namespace System.Diagnostics
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)]
	internal sealed class StackTraceHiddenAttribute : Attribute
	{
	}
}

plugins/System.Transactions.dll

Decompiled 2 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Threading;

[assembly: BestFitMapping(false)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("System.Transactions.dll")]
[assembly: AssemblyDescription("System.Transactions.dll")]
[assembly: AssemblyDefaultAlias("System.Transactions.dll")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyProduct("Mono Common Language Infrastructure")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
[assembly: SatelliteContractVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.0.30319.17020")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyFileVersion("4.0.30319.17020")]
[assembly: AssemblyVersion("4.0.0.0")]
internal static class Consts
{
	public const string MonoVersion = "5.11.0.0";

	public const string MonoCompany = "Mono development team";

	public const string MonoProduct = "Mono Common Language Infrastructure";

	public const string MonoCopyright = "(c) Various Mono authors";

	public const int MonoCorlibVersion = 1051100001;

	public const string FxVersion = "4.0.0.0";

	public const string FxFileVersion = "4.0.30319.17020";

	public const string EnvironmentVersion = "4.0.30319.17020";

	public const string VsVersion = "0.0.0.0";

	public const string VsFileVersion = "11.0.0.0";

	private const string PublicKeyToken = "b77a5c561934e089";

	public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";

	public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

	public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

	public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

	public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
}
internal sealed class Locale
{
	[MethodImpl(MethodImplOptions.NoInlining)]
	private Locale()
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	public static string GetText(string msg)
	{
		throw null;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	public static string GetText(string fmt, params object[] args)
	{
		throw null;
	}
}
namespace System
{
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoTODOAttribute : Attribute
	{
		private string comment;

		public string Comment
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoTODOAttribute()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoTODOAttribute(string comment)
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoDocumentationNoteAttribute : MonoTODOAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoDocumentationNoteAttribute(string comment)
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoExtensionAttribute : MonoTODOAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoExtensionAttribute(string comment)
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoInternalNoteAttribute : MonoTODOAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoInternalNoteAttribute(string comment)
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoLimitationAttribute : MonoTODOAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoLimitationAttribute(string comment)
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	internal class MonoNotSupportedAttribute : MonoTODOAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public MonoNotSupportedAttribute(string comment)
		{
			throw null;
		}
	}
}
namespace System.Transactions
{
	[Serializable]
	public sealed class CommittableTransaction : Transaction, ISerializable, IDisposable, IAsyncResult
	{
		private TransactionOptions options;

		private AsyncCallback callback;

		private object user_defined_state;

		private IAsyncResult asyncResult;

		object IAsyncResult.AsyncState
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		WaitHandle IAsyncResult.AsyncWaitHandle
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		bool IAsyncResult.CompletedSynchronously
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		bool IAsyncResult.IsCompleted
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public CommittableTransaction()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public CommittableTransaction(TimeSpan timeout)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public CommittableTransaction(TransactionOptions options)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public IAsyncResult BeginCommit(AsyncCallback asyncCallback, object asyncState)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void EndCommit(IAsyncResult asyncResult)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void CommitCallback(IAsyncResult ar)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Commit()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Not implemented")]
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	public delegate Transaction HostCurrentTransactionCallback();
	public delegate void TransactionCompletedEventHandler(object sender, TransactionEventArgs e);
	public delegate void TransactionStartedEventHandler(object sender, TransactionEventArgs e);
	public enum DependentCloneOption
	{
		BlockCommitUntilComplete,
		RollbackIfNotComplete
	}
	[Serializable]
	[MonoTODO("Not supported yet")]
	public sealed class DependentTransaction : Transaction, ISerializable
	{
		private bool completed;

		internal bool Completed
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal DependentTransaction(Transaction parent, DependentCloneOption option)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public void Complete()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal DependentTransaction()
		{
			throw null;
		}
	}
	public class Enlistment
	{
		internal bool done;

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal Enlistment()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Done()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal virtual void InternalOnDone()
		{
			throw null;
		}
	}
	[Flags]
	public enum EnlistmentOptions
	{
		None = 0,
		EnlistDuringPrepareRequired = 1
	}
	public enum EnterpriseServicesInteropOption
	{
		None,
		Automatic,
		Full
	}
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	public interface IDtcTransaction
	{
		void Abort(IntPtr reason, int retaining, int async);

		void Commit(int retaining, int commitType, int reserved);

		void GetTransactionInfo(IntPtr transactionInformation);
	}
	public interface IEnlistmentNotification
	{
		void Commit(Enlistment enlistment);

		void InDoubt(Enlistment enlistment);

		void Prepare(PreparingEnlistment preparingEnlistment);

		void Rollback(Enlistment enlistment);
	}
	public interface IPromotableSinglePhaseNotification : ITransactionPromoter
	{
		void Initialize();

		void Rollback(SinglePhaseEnlistment singlePhaseEnlistment);

		void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment);
	}
	public interface ISimpleTransactionSuperior : ITransactionPromoter
	{
		void Rollback();
	}
	public interface ISinglePhaseNotification : IEnlistmentNotification
	{
		void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment);
	}
	public interface ITransactionPromoter
	{
		byte[] Promote();
	}
	public enum IsolationLevel
	{
		Serializable,
		RepeatableRead,
		ReadCommitted,
		ReadUncommitted,
		Snapshot,
		Chaos,
		Unspecified
	}
	public class PreparingEnlistment : Enlistment
	{
		private bool prepared;

		private Transaction tx;

		private IEnlistmentNotification enlisted;

		private WaitHandle waitHandle;

		private Exception ex;

		internal bool IsPrepared
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal WaitHandle WaitHandle
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal IEnlistmentNotification EnlistmentNotification
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal Exception Exception
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal PreparingEnlistment(Transaction tx, IEnlistmentNotification enlisted)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void ForceRollback()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal override void InternalOnDone()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public void ForceRollback(Exception e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public void Prepared()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public byte[] RecoveryInformation()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal PreparingEnlistment()
		{
			throw null;
		}
	}
	public class SinglePhaseEnlistment : Enlistment
	{
		private Transaction tx;

		private object abortingEnlisted;

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal SinglePhaseEnlistment()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal SinglePhaseEnlistment(Transaction tx, object abortingEnlisted)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Aborted()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Aborted(Exception e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public void Committed()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Not implemented")]
		public void InDoubt()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Not implemented")]
		public void InDoubt(Exception e)
		{
			throw null;
		}
	}
	[Serializable]
	public sealed class SubordinateTransaction : Transaction
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public SubordinateTransaction(IsolationLevel isoLevel, ISimpleTransactionSuperior superior)
		{
			throw null;
		}
	}
	[Serializable]
	public class Transaction : IDisposable, ISerializable
	{
		private delegate void AsyncCommit();

		[ThreadStatic]
		private static Transaction ambient;

		private IsolationLevel level;

		private TransactionInformation info;

		private ArrayList dependents;

		private List<IEnlistmentNotification> volatiles;

		private List<ISinglePhaseNotification> durables;

		private IPromotableSinglePhaseNotification pspe;

		private AsyncCommit asyncCommit;

		private bool committing;

		private bool committed;

		private bool aborted;

		private TransactionScope scope;

		private Exception innerException;

		private Guid tag;

		internal List<IEnlistmentNotification> Volatiles
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal List<ISinglePhaseNotification> Durables
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal IPromotableSinglePhaseNotification Pspe
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public static Transaction Current
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		internal static Transaction CurrentInternal
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public IsolationLevel IsolationLevel
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public TransactionInformation TransactionInformation
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public Guid PromoterType
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		private bool Aborted
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		internal TransactionScope Scope
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public event TransactionCompletedEventHandler TransactionCompleted
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			[CompilerGenerated]
			add
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			[CompilerGenerated]
			remove
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal Transaction()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal Transaction(Transaction other)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public Transaction Clone()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Dispose()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public DependentTransaction DependentClone(DependentCloneOption cloneOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Only SinglePhase commit supported for durable resource managers.")]
		[PermissionSet(SecurityAction.LinkDemand)]
		public Enlistment EnlistDurable(Guid resourceManagerIdentifier, IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Only Local Transaction Manager supported. Cannot have more than 1 durable resource per transaction. Only EnlistmentOptions.None supported yet.")]
		[PermissionSet(SecurityAction.LinkDemand)]
		public Enlistment EnlistDurable(Guid resourceManagerIdentifier, ISinglePhaseNotification singlePhaseNotification, EnlistmentOptions enlistmentOptions)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification promotableNotification, Guid distributedTransactionIdentifier)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public byte[] GetPromotedToken()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("EnlistmentOptions being ignored")]
		public Enlistment EnlistVolatile(IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("EnlistmentOptions being ignored")]
		public Enlistment EnlistVolatile(ISinglePhaseNotification singlePhaseNotification, EnlistmentOptions enlistmentOptions)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private Enlistment EnlistVolatileInternal(IEnlistmentNotification notification, EnlistmentOptions options)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Only Local Transaction Manager supported. Cannot have more than 1 durable resource per transaction.")]
		[PermissionSet(SecurityAction.LinkDemand)]
		public Enlistment PromoteAndEnlistDurable(Guid manager, IPromotableSinglePhaseNotification promotableNotification, ISinglePhaseNotification notification, EnlistmentOptions options)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool Equals(object obj)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private bool Equals(Transaction t)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(Transaction x, Transaction y)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(Transaction x, Transaction y)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int GetHashCode()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Rollback()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Rollback(Exception e)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal void Rollback(Exception ex, object abortingEnlisted)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected IAsyncResult BeginCommitInternal(AsyncCallback callback)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected void EndCommitInternal(IAsyncResult ar)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal void CommitInternal()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void DoCommit()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void Complete()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal void InitScope(TransactionScope scope)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void PrepareCallbackWrapper(object state)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void DoPreparePhase()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void DoCommitPhase()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void DoSingleCommit(ISinglePhaseNotification single)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void DoSingleCommit(IPromotableSinglePhaseNotification single)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void CheckAborted()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void FireCompleted()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void EnsureIncompleteCurrentScope()
		{
			throw null;
		}
	}
	[Serializable]
	public class TransactionAbortedException : TransactionException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionAbortedException()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionAbortedException(string message)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionAbortedException(string message, Exception innerException)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected TransactionAbortedException(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	public class TransactionEventArgs : EventArgs
	{
		private Transaction transaction;

		public Transaction Transaction
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionEventArgs()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal TransactionEventArgs(Transaction transaction)
		{
			throw null;
		}
	}
	[Serializable]
	public class TransactionException : SystemException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionException()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionException(string message)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionException(string message, Exception innerException)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected TransactionException(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	[Serializable]
	public class TransactionInDoubtException : TransactionException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionInDoubtException()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionInDoubtException(string message)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionInDoubtException(string message, Exception innerException)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected TransactionInDoubtException(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	public class TransactionInformation
	{
		private string local_id;

		private Guid dtcId;

		private DateTime creation_time;

		private TransactionStatus status;

		public DateTime CreationTime
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public Guid DistributedIdentifier
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			internal set
			{
				throw null;
			}
		}

		public string LocalIdentifier
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public TransactionStatus Status
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			internal set
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal TransactionInformation()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private TransactionInformation(TransactionInformation other)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal TransactionInformation Clone(TransactionInformation other)
		{
			throw null;
		}
	}
	[MonoTODO]
	public static class TransactionInterop
	{
		public static readonly Guid PromoterTypeDtc;

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static IDtcTransaction GetDtcTransaction(Transaction transaction)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static byte[] GetExportCookie(Transaction transaction, byte[] whereabouts)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static Transaction GetTransactionFromDtcTransaction(IDtcTransaction transactionNative)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static Transaction GetTransactionFromExportCookie(byte[] cookie)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static Transaction GetTransactionFromTransmitterPropagationToken(byte[] propagationToken)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static byte[] GetTransmitterPropagationToken(Transaction transaction)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO]
		public static byte[] GetWhereabouts()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static TransactionInterop()
		{
			throw null;
		}
	}
	public static class TransactionManager
	{
		private static TimeSpan defaultTimeout;

		private static TimeSpan maxTimeout;

		public static TimeSpan DefaultTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MonoTODO("Not implemented")]
		public static HostCurrentTransactionCallback HostCurrentCallback
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public static TimeSpan MaximumTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public static event TransactionStartedEventHandler DistributedTransactionStarted
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			[CompilerGenerated]
			add
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			[CompilerGenerated]
			remove
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static TransactionManager()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Not implemented")]
		public static void RecoveryComplete(Guid resourceManagerIdentifier)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("Not implemented")]
		public static Enlistment Reenlist(Guid resourceManagerIdentifier, byte[] recoveryInformation, IEnlistmentNotification enlistmentNotification)
		{
			throw null;
		}
	}
	[Serializable]
	public class TransactionManagerCommunicationException : TransactionException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionManagerCommunicationException()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionManagerCommunicationException(string message)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionManagerCommunicationException(string message, Exception innerException)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected TransactionManagerCommunicationException(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	public struct TransactionOptions
	{
		private IsolationLevel level;

		private TimeSpan timeout;

		public IsolationLevel IsolationLevel
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		public TimeSpan Timeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal TransactionOptions(IsolationLevel level, TimeSpan timeout)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator ==(TransactionOptions x, TransactionOptions y)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool operator !=(TransactionOptions x, TransactionOptions y)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool Equals(object obj)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override int GetHashCode()
		{
			throw null;
		}
	}
	[Serializable]
	public class TransactionPromotionException : TransactionException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionPromotionException()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionPromotionException(string message)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionPromotionException(string message, Exception innerException)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected TransactionPromotionException(SerializationInfo info, StreamingContext context)
		{
			throw null;
		}
	}
	public sealed class TransactionScope : IDisposable
	{
		private static TransactionOptions defaultOptions;

		private Transaction transaction;

		private Transaction oldTransaction;

		private TransactionScope parentScope;

		private TimeSpan timeout;

		private int nested;

		private bool disposed;

		private bool completed;

		private bool isRoot;

		private bool asyncFlowEnabled;

		internal bool IsComplete
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		internal TimeSpan Timeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeAsyncFlowOption asyncFlowOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(Transaction transactionToUse)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(Transaction transactionToUse, TimeSpan scopeTimeout)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("EnterpriseServicesInteropOption not supported.")]
		public TransactionScope(Transaction transactionToUse, TimeSpan scopeTimeout, EnterpriseServicesInteropOption interopOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption scopeOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption scopeOption, TimeSpan scopeTimeout)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption option, TransactionScopeAsyncFlowOption asyncFlow)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption scopeOption, TimeSpan scopeTimeout, TransactionScopeAsyncFlowOption asyncFlow)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[MonoTODO("EnterpriseServicesInteropOption not supported")]
		public TransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions, EnterpriseServicesInteropOption interopOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(Transaction transactionToUse, TransactionScopeAsyncFlowOption asyncFlowOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(Transaction transactionToUse, TimeSpan scopeTimeout, TransactionScopeAsyncFlowOption asyncFlowOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions, TransactionScopeAsyncFlowOption asyncFlowOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void Initialize(TransactionScopeOption scopeOption, Transaction tx, TransactionOptions options, EnterpriseServicesInteropOption interop, TimeSpan scopeTimeout, TransactionScopeAsyncFlowOption asyncFlow)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private Transaction InitTransaction(Transaction tx, TransactionScopeOption scopeOption)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Complete()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public void Dispose()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		static TransactionScope()
		{
			throw null;
		}
	}
	public enum TransactionScopeAsyncFlowOption
	{
		Suppress,
		Enabled
	}
	public enum TransactionScopeOption
	{
		Required,
		RequiresNew,
		Suppress
	}
	public enum TransactionStatus
	{
		Active,
		Committed,
		Aborted,
		InDoubt
	}
	[Serializable]
	public sealed class DistributedTransactionPermission : CodeAccessPermission, IUnrestrictedPermission
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public DistributedTransactionPermission(PermissionState state)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override IPermission Copy()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override void FromXml(SecurityElement securityElement)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override IPermission Intersect(IPermission target)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override bool IsSubsetOf(IPermission target)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public bool IsUnrestricted()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override SecurityElement ToXml()
		{
			throw null;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
	public sealed class DistributedTransactionPermissionAttribute : CodeAccessSecurityAttribute
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public DistributedTransactionPermissionAttribute(SecurityAction action)
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public override IPermission CreatePermission()
		{
			throw null;
		}
	}
}
namespace System.Transactions.Configuration
{
	public sealed class DefaultSettingsSection : ConfigurationSection
	{
		public string DistributedTransactionManagerName
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public TimeSpan Timeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public DefaultSettingsSection()
		{
			throw null;
		}
	}
	public sealed class MachineSettingsSection : ConfigurationSection
	{
		public TimeSpan MaxTimeout
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
			[MethodImpl(MethodImplOptions.NoInlining)]
			set
			{
				throw null;
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public MachineSettingsSection()
		{
			throw null;
		}
	}
	public sealed class TransactionsSectionGroup : ConfigurationSectionGroup
	{
		public DefaultSettingsSection DefaultSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		public MachineSettingsSection MachineSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining)]
			get
			{
				throw null;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public TransactionsSectionGroup()
		{
			throw null;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static TransactionsSectionGroup GetSectionGroup(Configuration config)
		{
			throw null;
		}
	}
}
namespace Unity
{
	internal sealed class ThrowStub : ObjectDisposedException
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void ThrowNotSupportedException()
		{
			throw null;
		}
	}
}

plugins/System.ValueTuple.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using FxResources.System.ValueTuple;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyTitle("System.ValueTuple")]
[assembly: AssemblyDescription("System.ValueTuple")]
[assembly: AssemblyDefaultAlias("System.ValueTuple")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyFileVersion("4.6.26515.06")]
[assembly: AssemblyInformationalVersion("4.6.26515.06 @BuiltBy: dlab-DDVSOWINAGE059 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/30ab651fcb4354552bd4891619a0bdd81e0ebdbf")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyVersion("4.0.3.0")]
[assembly: TypeForwardedTo(typeof(TupleElementNamesAttribute))]
[assembly: TypeForwardedTo(typeof(TupleExtensions))]
[assembly: TypeForwardedTo(typeof(ValueTuple))]
[assembly: TypeForwardedTo(typeof(ValueTuple<>))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , , >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , , , >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , , , , >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , , , , , >))]
[assembly: TypeForwardedTo(typeof(ValueTuple<, , , , , , , >))]
namespace FxResources.System.ValueTuple
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class SR
	{
		private static ResourceManager s_resourceManager;

		private static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(ResourceType));

		internal static Type ResourceType { get; } = typeof(SR);


		internal static string ArgumentException_ValueTupleIncorrectType => GetResourceString("ArgumentException_ValueTupleIncorrectType", null);

		internal static string ArgumentException_ValueTupleLastArgumentNotAValueTuple => GetResourceString("ArgumentException_ValueTupleLastArgumentNotAValueTuple", null);

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool UsingResourceKeys()
		{
			return false;
		}

		internal static string GetResourceString(string resourceKey, string defaultString)
		{
			string text = null;
			try
			{
				text = ResourceManager.GetString(resourceKey);
			}
			catch (MissingManifestResourceException)
			{
			}
			if (defaultString != null && resourceKey.Equals(text, StringComparison.Ordinal))
			{
				return defaultString;
			}
			return text;
		}

		internal static string Format(string resourceFormat, params object[] args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + string.Join(", ", args);
				}
				return string.Format(resourceFormat, args);
			}
			return resourceFormat;
		}

		internal static string Format(string resourceFormat, object p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(resourceFormat, p1);
		}

		internal static string Format(string resourceFormat, object p1, object p2)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2);
			}
			return string.Format(resourceFormat, p1, p2);
		}

		internal static string Format(string resourceFormat, object p1, object p2, object p3)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2, p3);
			}
			return string.Format(resourceFormat, p1, p2, p3);
		}
	}
}