v10.10.2024.0701 使用IJsonHost改进Json序列化
大石头 编写于 2024-07-01 08:36:34 大石头 提交于 2024-07-01 08:48:33
X
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Threading;

namespace NewLife;

[Serializable]
[ComVisible(true)]
public class OperationCanceledException : SystemException
{
	private const int Result = -2146233029;

	private CancellationToken? token;

	public CancellationToken CancellationToken
	{
		get
		{
			if (!token.HasValue)
			{
				return CancellationToken.None;
			}
			return token.Value;
		}
	}

	public OperationCanceledException()
		: base("The operation was canceled.")
	{
		base.HResult = -2146233029;
	}

	public OperationCanceledException(string message)
		: base(message)
	{
		base.HResult = -2146233029;
	}

	public OperationCanceledException(string message, Exception innerException)
		: base(message, innerException)
	{
		base.HResult = -2146233029;
	}

	protected OperationCanceledException(SerializationInfo info, StreamingContext context)
		: base(info, context)
	{
	}

	public OperationCanceledException(CancellationToken token)
		: this()
	{
		this.token = token;
	}

	public OperationCanceledException(string message, CancellationToken token)
		: this(message)
	{
		this.token = token;
	}

	public OperationCanceledException(string message, Exception innerException, CancellationToken token)
		: base(message, innerException)
	{
		this.token = token;
	}
}