support for .NET framework 3.5

Still have bugs
This commit is contained in:
NaBian committed 2019-01-21 00:43:10 +08:00
1 parent 5878039e21
commit 7d6b491f25
704 files changed
+48273 -33

No files matched your search

@@ -0,0 +1,13 @@
using System.Windows;
namespace HandyControl.Data
{
public class CancelRoutedEventArgs : RoutedEventArgs
{
public CancelRoutedEventArgs(RoutedEvent routedEvent, object source) : base(routedEvent, source)
{
}
public bool Cancel { get; set; }
}
}
@@ -0,0 +1,19 @@
using System.Windows;
namespace HandyControl.Data
{
public class FunctionEventArgs<T> : RoutedEventArgs
{
public FunctionEventArgs(T info)
{
Info = info;
}
public FunctionEventArgs(RoutedEvent routedEvent, object source) : base(routedEvent, source)
{
}
public T Info { get; set; }
}
}
@@ -0,0 +1,75 @@
using System.Windows.Media;
namespace HandyControl.Data
{
/// <summary>
/// 颜色范围
/// </summary>
public class ColorRange
{
/// <summary>
/// 颜色1
/// </summary>
private Color _color1;
/// <summary>
/// 颜色1
/// </summary>
public Color Color1
{
get => _color1;
set
{
_color1 = value;
Update();
}
}
/// <summary>
/// 颜色2
/// </summary>
private Color _color2;
/// <summary>
/// 颜色2
/// </summary>
public Color Color2
{
get => _color2;
set
{
_color2 = value;
Update();
}
}
/// <summary>
/// 颜色差值
/// </summary>
private readonly int[] _subColorArr = new int[4];
/// <summary>
/// 更新
/// </summary>
private void Update()
{
_subColorArr[0] = Color1.A - Color2.A;
_subColorArr[1] = Color1.R - Color2.R;
_subColorArr[2] = Color1.G - Color2.G;
_subColorArr[3] = Color1.B - Color2.B;
}
/// <summary>
/// 获取指定比例处的颜色
/// </summary>
/// <param name="range">范围(0-1)</param>
/// <returns></returns>
public Color GetColor(double range)
{
if (range < 0 || range > 1) return default(Color);
return Color.FromArgb((byte)(_color1.A - _subColorArr[0] * range), (byte)(_color1.R - _subColorArr[1] * range),
(byte)(_color1.G - _subColorArr[2] * range), (byte)(_color1.B - _subColorArr[3] * range));
}
}
}
@@ -0,0 +1,13 @@
namespace HandyControl.Data
{
public enum InfoType
{
Success = 0,
Info,
Warning,
Error,
Fatal,
Ask
}
}
@@ -0,0 +1,30 @@
namespace HandyControl.Data
{
/// <summary>
/// IP类型枚举
/// </summary>
public enum IpType
{
/// <summary>
/// A类IP地址
/// </summary>
A = 0,
/// <summary>
/// B类IP地址
/// </summary>
B,
/// <summary>
/// C类IP地址
/// </summary>
C,
/// <summary>
/// D类IP地址
/// </summary>
D,
/// <summary>
/// E类IP地址
/// </summary>
E
}
}
@@ -0,0 +1,24 @@
namespace HandyControl.Data
{
/// <summary>
/// 表示一个操作的返回结果类型
/// </summary>
public enum ResultType
{
/// <summary>
/// 成功
/// </summary>
Success,
/// <summary>
/// 失败
/// </summary>
Failed,
/// <summary>
/// 无数据
/// </summary>
None
}
}
@@ -0,0 +1,10 @@
namespace HandyControl.Data
{
public enum SkinType
{
Default,
Dark,
Violet
}
}
@@ -0,0 +1,23 @@
namespace HandyControl.Data
{
/// <summary>
/// 步骤状态
/// </summary>
public enum StepStatus
{
/// <summary>
/// 完成
/// </summary>
Complete,
/// <summary>
/// 进行中
/// </summary>
UnderWay,
/// <summary>
/// 等待中
/// </summary>
Waiting
}
}
@@ -0,0 +1,27 @@
namespace HandyControl.Data
{
/// <summary>
/// 文本类型枚举
/// </summary>
public enum TextType
{
Common,
Phone,
Mail,
Url,
Chinese,
Number,
Digits,
PInt,
NInt,
Int,
NnInt,
NpInt,
PDouble,
NDouble,
Double,
NnDouble,
NpDouble,
}
}
@@ -0,0 +1,9 @@
namespace HandyControl.Data
{
public enum TipPlacement
{
TopLeft,
BottomRight,
}
}
@@ -0,0 +1,12 @@
namespace HandyControl.Data
{
/// <summary>
/// 标题对齐方式
/// </summary>
public enum TitleAlignment
{
Left,
Top
}
}
@@ -0,0 +1,68 @@
using System;
using System.Collections;
namespace HandyControl.Data
{
internal enum FrugalMapStoreState
{
Success,
ThreeObjectMap,
SixObjectMap,
Array,
SortedArray,
Hashtable
}
internal delegate void FrugalMapIterationCallback(ArrayList list, int key, object value);
abstract class FrugalMapBase
{
public abstract FrugalMapStoreState InsertEntry(int key, Object value);
public abstract void RemoveEntry(int key);
/// <summary>
/// Looks for an entry that contains the given key, null is returned if the
/// key is not found.
/// </summary>
public abstract Object Search(int key);
/// <summary>
/// A routine used by enumerators that need a sorted map
/// </summary>
public abstract void Sort();
/// <summary>
/// A routine used by enumerators to iterate through the map
/// </summary>
public abstract void GetKeyValuePair(int index, out int key, out Object value);
/// <summary>
/// A routine used to iterate through all the entries in the map
/// </summary>
public abstract void Iterate(ArrayList list, FrugalMapIterationCallback callback);
/// <summary>
/// Promotes the key/value pairs in the current collection to the next larger
/// and more complex storage model.
/// </summary>
public abstract void Promote(FrugalMapBase newMap);
/// <summary>
/// Size of this data store
/// </summary>
public abstract int Count
{
get;
}
protected const int INVALIDKEY = 0x7FFFFFFF;
internal struct Entry
{
public int Key;
public object Value;
}
}
}
@@ -0,0 +1,271 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using HandyControl.Tools;
namespace HandyControl.Data
{
// ReSharper disable once InconsistentNaming
internal class GPStream : ExternDllHelper.IStream
{
protected Stream DataStream;
// to support seeking ahead of the stream length...
long _virtualPosition = -1;
internal GPStream(Stream stream)
{
if (!stream.CanSeek)
{
const int readBlock = 256;
var bytes = new byte[readBlock];
int readLen;
var current = 0;
do
{
if (bytes.Length < current + readBlock)
{
var newData = new byte[bytes.Length * 2];
Array.Copy(bytes, newData, bytes.Length);
bytes = newData;
}
readLen = stream.Read(bytes, current, readBlock);
current += readLen;
} while (readLen != 0);
DataStream = new MemoryStream(bytes);
}
else
{
DataStream = stream;
}
}
private void ActualizeVirtualPosition()
{
if (_virtualPosition == -1) return;
if (_virtualPosition > DataStream.Length)
DataStream.SetLength(_virtualPosition);
DataStream.Position = _virtualPosition;
_virtualPosition = -1;
}
public virtual ExternDllHelper.IStream Clone()
{
NotImplemented();
return null;
}
public virtual void Commit(int grfCommitFlags)
{
DataStream.Flush();
// Extend the length of the file if needed.
ActualizeVirtualPosition();
}
[
UIPermission(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows),
SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)
]
public virtual long CopyTo(ExternDllHelper.IStream pstm, long cb, long[] pcbRead)
{
const int bufsize = 4096;
var buffer = Marshal.AllocHGlobal(bufsize);
if (buffer == IntPtr.Zero) throw new OutOfMemoryException();
long written = 0;
try
{
while (written < cb)
{
var toRead = bufsize;
if (written + toRead > cb) toRead = (int)(cb - written);
var read = Read(buffer, toRead);
if (read == 0) break;
if (pstm.Write(buffer, read) != read)
{
throw EFail("Wrote an incorrect number of bytes");
}
written += read;
}
}
finally
{
Marshal.FreeHGlobal(buffer);
}
if (pcbRead != null && pcbRead.Length > 0)
{
pcbRead[0] = written;
}
return written;
}
public virtual Stream GetDataStream()
{
return DataStream;
}
public virtual void LockRegion(long libOffset, long cb, int dwLockType)
{
}
protected static ExternalException EFail(string msg)
{
throw new ExternalException(msg, ExternDllHelper.E_FAIL);
}
protected static void NotImplemented()
{
throw new ExternalException("NotImplemented");
}
public virtual int Read(IntPtr buf, int length)
{
var buffer = new byte[length];
var count = Read(buffer, length);
Marshal.Copy(buffer, 0, buf, length);
return count;
}
public virtual int Read(byte[] buffer, int length)
{
ActualizeVirtualPosition();
return DataStream.Read(buffer, 0, length);
}
public virtual void Revert()
{
NotImplemented();
}
public virtual long Seek(long offset, int origin)
{
var pos = _virtualPosition;
if (_virtualPosition == -1)
{
pos = DataStream.Position;
}
var len = DataStream.Length;
switch (origin)
{
case ExternDllHelper.StreamConsts.STREAM_SEEK_SET:
if (offset <= len)
{
DataStream.Position = offset;
_virtualPosition = -1;
}
else
{
_virtualPosition = offset;
}
break;
case ExternDllHelper.StreamConsts.STREAM_SEEK_END:
if (offset <= 0)
{
DataStream.Position = len + offset;
_virtualPosition = -1;
}
else
{
_virtualPosition = len + offset;
}
break;
case ExternDllHelper.StreamConsts.STREAM_SEEK_CUR:
if (offset + pos <= len)
{
DataStream.Position = pos + offset;
_virtualPosition = -1;
}
else
{
_virtualPosition = offset + pos;
}
break;
}
return _virtualPosition != -1 ? _virtualPosition : DataStream.Position;
}
public virtual void SetSize(long value)
{
DataStream.SetLength(value);
}
public void Stat(IntPtr pstatstg, int grfStatFlag)
{
var stats = new STATSTG {cbSize = DataStream.Length};
Marshal.StructureToPtr(stats, pstatstg, true);
}
public virtual void UnlockRegion(long libOffset, long cb, int dwLockType)
{
}
public virtual int Write(IntPtr buf, int length)
{
var buffer = new byte[length];
Marshal.Copy(buf, buffer, 0, length);
return Write(buffer, length);
}
public virtual int Write(byte[] buffer, int length)
{
ActualizeVirtualPosition();
DataStream.Write(buffer, 0, length);
return length;
}
[StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class STATSTG
{
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")]
public IntPtr pwcsName = IntPtr.Zero;
public int type;
[MarshalAs(UnmanagedType.I8)]
public long cbSize;
[MarshalAs(UnmanagedType.I8)]
public long mtime;
[MarshalAs(UnmanagedType.I8)]
public long ctime;
[MarshalAs(UnmanagedType.I8)]
public long atime;
[MarshalAs(UnmanagedType.I4)]
public int grfMode;
[MarshalAs(UnmanagedType.I4)]
public int grfLocksSupported;
public int clsid_data1;
[MarshalAs(UnmanagedType.I2)]
public short clsid_data2;
[MarshalAs(UnmanagedType.I2)]
public short clsid_data3;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b0;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b1;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b2;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b3;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b4;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b5;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b6;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b7;
[MarshalAs(UnmanagedType.I4)]
public int grfStateBits;
[MarshalAs(UnmanagedType.I4)]
public int reserved;
}
}
}
@@ -0,0 +1,29 @@
using System;
namespace HandyControl.Data
{
internal class GifFrameDimension
{
public GifFrameDimension(Guid guid) => Guid = guid;
public Guid Guid { get; }
public static GifFrameDimension Time { get; } = new GifFrameDimension(new Guid("{6aedbd6d-3fb5-418a-83a6-7f45229dc872}"));
public static GifFrameDimension Resolution { get; } = new GifFrameDimension(new Guid("{84236f7b-3bd3-428f-8dab-4ea1439ca315}"));
public static GifFrameDimension Page { get; } = new GifFrameDimension(new Guid("{7462dc86-6180-4c7e-8e3f-ee7333a7a483}"));
public override bool Equals(object o) => o is GifFrameDimension format && Guid == format.Guid;
public override int GetHashCode() => Guid.GetHashCode();
public override string ToString()
{
if (Equals(this, Time)) return "Time";
if (Equals(this, Resolution)) return "Resolution";
if (Equals(this, Page)) return "Page";
return "[FrameDimension: " + Guid + "]";
}
}
}
@@ -0,0 +1,97 @@
using System;
using HandyControl.Controls;
namespace HandyControl.Data
{
public class GifImageInfo
{
private const int PropertyTagFrameDelay = 0x5100;
private int _frame;
private readonly int[] _frameDelay;
public int FrameCount { get; }
internal GifImage Image { get; }
public bool Animated { get; }
public EventHandler FrameChangedHandler { get; set; }
internal int FrameTimer { get; set; }
public bool FrameDirty { get; private set; }
public int Frame
{
get => _frame;
set
{
if (_frame != value)
{
if (value < 0 || value >= FrameCount)
{
throw new ArgumentException("InvalidFrame");
}
if (Animated)
{
_frame = value;
FrameDirty = true;
OnFrameChanged(EventArgs.Empty);
}
}
}
}
public GifImageInfo(GifImage image)
{
Image = image;
Animated = ImageAnimator.CanAnimate(image);
if (Animated)
{
FrameCount = image.GetFrameCount(GifFrameDimension.Time);
var frameDelayItem = image.GetPropertyItem(PropertyTagFrameDelay);
// If the image does not have a frame delay, we just return 0.
//
if (frameDelayItem != null)
{
// Convert the frame delay from byte[] to int
//
var values = frameDelayItem.Value;
_frameDelay = new int[FrameCount];
for (int i = 0; i < FrameCount; ++i)
{
_frameDelay[i] = values[i * 4] + 256 * values[i * 4 + 1] + 256 * 256 * values[i * 4 + 2] + 256 * 256 * 256 * values[i * 4 + 3];
}
}
}
else
{
FrameCount = 1;
}
if (_frameDelay == null)
{
_frameDelay = new int[FrameCount];
}
}
public int FrameDelay(int frame) => _frameDelay[frame];
internal void UpdateFrame()
{
if (FrameDirty)
{
Image.SelectActiveFrame(GifFrameDimension.Time, Frame);
FrameDirty = false;
}
}
protected void OnFrameChanged(EventArgs e) => FrameChangedHandler?.Invoke(Image, e);
}
}
@@ -0,0 +1,13 @@
namespace HandyControl.Data
{
public class GifPropertyItem
{
public int Id { get; set; }
public int Len { get; set; }
public short Type { get; set; }
public byte[] Value { get; set; }
}
}
@@ -0,0 +1,114 @@
using System;
using System.Runtime.InteropServices;
using HandyControl.Tools;
namespace HandyControl.Data
{
[StructLayout(LayoutKind.Sequential)]
public class GifPropertyItemInternal : IDisposable
{
public int id;
public int len;
public short type;
public IntPtr value = IntPtr.Zero;
internal GifPropertyItemInternal()
{
}
public byte[] Value
{
get
{
if (len == 0)
return null;
var bytes = new byte[len];
Marshal.Copy(value,
bytes,
0,
len);
return bytes;
}
}
public void Dispose()
{
Dispose(true);
}
~GifPropertyItemInternal()
{
Dispose(false);
}
private void Dispose(bool disposing)
{
if (value != IntPtr.Zero)
{
Marshal.FreeHGlobal(value);
value = IntPtr.Zero;
}
if (disposing)
GC.SuppressFinalize(this);
}
internal static GifPropertyItemInternal ConvertFromPropertyItem(GifPropertyItem propItem)
{
var propItemInternal = new GifPropertyItemInternal
{
id = propItem.Id,
len = 0,
type = propItem.Type
};
var propItemValue = propItem.Value;
if (propItemValue != null)
{
var length = propItemValue.Length;
propItemInternal.len = length;
propItemInternal.value = Marshal.AllocHGlobal(length);
Marshal.Copy(propItemValue, 0, propItemInternal.value, length);
}
return propItemInternal;
}
internal static GifPropertyItem[] ConvertFromMemory(IntPtr propdata, int count)
{
var props = new GifPropertyItem[count];
for (var i = 0; i < count; i++)
{
GifPropertyItemInternal propcopy = null;
try
{
propcopy = (GifPropertyItemInternal) ExternDllHelper.PtrToStructure(propdata,
typeof(GifPropertyItemInternal));
props[i] = new GifPropertyItem
{
Id = propcopy.id,
Len = propcopy.len,
Type = propcopy.type,
Value = propcopy.Value
};
// this calls Marshal.Copy and creates a copy of the original memory into a byte array.
propcopy.value = IntPtr.Zero; // we dont actually own this memory so dont free it.
}
finally
{
propcopy?.Dispose();
}
propdata = (IntPtr) ((long) propdata + Marshal.SizeOf(typeof(GifPropertyItemInternal)));
}
return props;
}
}
}
@@ -0,0 +1,31 @@
using System;
namespace HandyControl.Data
{
public class GrowlInfo
{
public string Message { get; set; }
public bool ShowDateTime { get; set; } = true;
public int WaitTime { get; set; } = 6;
public string CancelStr { get; set; } = Properties.Langs.Lang.Cancel;
public string ConfirmStr { get; set; } = Properties.Langs.Lang.Confirm;
public Func<bool, bool> ActionBeforeClose { get; set; }
public bool StaysOpen { get; set; }
public bool IsCustom { get; set; }
public InfoType Type { get; set; }
public string IconKey { get; set; }
public string IconBrushKey { get; set; }
public bool ShowCloseButton { get; set; } = true;
}
}
@@ -0,0 +1,23 @@
namespace HandyControl.Data
{
/// <summary>
/// 表示一个操作的返回结果信息
/// </summary>
public class OperationResult<T> : OperationResult
{
/// <summary>
/// 操作结果
/// </summary>
public ResultType ResultType { get; set; }
/// <summary>
/// 返回数据
/// </summary>
public T Data { get; set; }
/// <summary>
/// 操作消息(包含错误原因等数据)
/// </summary>
public string Message { get; set; }
}
}
@@ -0,0 +1,25 @@
namespace HandyControl.Data
{
public class OperationResult
{
public static OperationResult<bool> Failed(string message = "")
{
return new OperationResult<bool>
{
ResultType = ResultType.Failed,
Message = message,
Data = false
};
}
public static OperationResult<bool> Success(string message = "")
{
return new OperationResult<bool>
{
ResultType = ResultType.Success,
Message = message,
Data = true
};
}
}
}
@@ -0,0 +1,68 @@
namespace HandyControl.Data
{
internal class ResourceToken
{
public static readonly string SuccessGeometry = nameof(SuccessGeometry);
public static readonly string InfoGeometry = nameof(InfoGeometry);
public static readonly string ErrorGeometry = nameof(ErrorGeometry);
public static readonly string WarningGeometry = nameof(WarningGeometry);
public static readonly string AskGeometry = nameof(AskGeometry);
public static readonly string FatalGeometry = nameof(FatalGeometry);
public static readonly string PrimaryBrush = nameof(PrimaryBrush);
public static readonly string SuccessBrush = nameof(SuccessBrush);
public static readonly string InfoBrush = nameof(InfoBrush);
public static readonly string DangerBrush = nameof(DangerBrush);
public static readonly string WarningBrush = nameof(WarningBrush);
public static readonly string AccentBrush = nameof(AccentBrush);
public static readonly string PrimaryTextBrush = nameof(PrimaryTextBrush);
public static readonly string ThirdlyTextBrush = nameof(ThirdlyTextBrush);
public static readonly string BlurGradientValue = nameof(BlurGradientValue);
public static readonly string ButtonCustom = nameof(ButtonCustom);
public static readonly string PaginationButtonStyle = nameof(PaginationButtonStyle);
public static readonly string WindowWin10 = nameof(WindowWin10);
public static readonly string AddTagButtonStyle = nameof(AddTagButtonStyle);
public static readonly string RadioGroupItemDefault = nameof(RadioGroupItemDefault);
public static readonly string RadioGroupItemSingle = nameof(RadioGroupItemSingle);
public static readonly string RadioGroupItemHorizontalFirst = nameof(RadioGroupItemHorizontalFirst);
public static readonly string RadioGroupItemHorizontalLast = nameof(RadioGroupItemHorizontalLast);
public static readonly string RadioGroupItemVerticalFirst = nameof(RadioGroupItemVerticalFirst);
public static readonly string RadioGroupItemVerticalLast = nameof(RadioGroupItemVerticalLast);
public static readonly string TabItemCapsuleDefault = nameof(TabItemCapsuleDefault);
public static readonly string TabItemCapsuleSingle = nameof(TabItemCapsuleSingle);
public static readonly string TabItemCapsuleHorizontalFirst = nameof(TabItemCapsuleHorizontalFirst);
public static readonly string TabItemCapsuleHorizontalLast = nameof(TabItemCapsuleHorizontalLast);
public static readonly string TabItemCapsuleVerticalFirst = nameof(TabItemCapsuleVerticalFirst);
public static readonly string TabItemCapsuleVerticalLast = nameof(TabItemCapsuleVerticalLast);
}
}
@@ -0,0 +1,63 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ import namespace="System.Collections.Generic"#>
<#@ output extension=".cs" #>
<#
var geometryList = new List<string>
{
"SuccessGeometry",
"InfoGeometry",
"ErrorGeometry",
"WarningGeometry",
"AskGeometry",
"FatalGeometry",
"PrimaryBrush"
};
var brushList = new List<string>
{
"SuccessBrush",
"InfoBrush",
"DangerBrush",
"WarningBrush",
"AccentBrush",
"PrimaryTextBrush",
"ThirdlyTextBrush",
"BlurGradientValue"
};
var styleList = new List<string>
{
"ButtonCustom",
"PaginationButtonStyle",
"WindowWin10",
"AddTagButtonStyle",
"RadioGroupItemDefault",
"RadioGroupItemSingle",
"RadioGroupItemHorizontalFirst",
"RadioGroupItemHorizontalLast",
"RadioGroupItemVerticalFirst",
"RadioGroupItemVerticalLast",
"TabItemCapsuleDefault",
"TabItemCapsuleSingle",
"TabItemCapsuleHorizontalFirst",
"TabItemCapsuleHorizontalLast",
"TabItemCapsuleVerticalFirst",
"TabItemCapsuleVerticalLast"
};
#>
namespace HandyControl.Data
{
internal class ResourceToken
{
<#foreach(var item in geometryList){#>
public static readonly string <#=item#> = nameof(<#=item#>);
<#}#>
<#foreach(var item in brushList){#>
public static readonly string <#=item#> = nameof(<#=item#>);
<#}#>
<#foreach(var item in styleList){#>
public static readonly string <#=item#> = nameof(<#=item#>);
<#}#>
}
}
@@ -0,0 +1,76 @@
// reference from https://github.com/sourcechord/FluentWPF/blob/master/FluentWPF/Utility/VersionInfo.cs
// LICENSE: https://github.com/sourcechord/FluentWPF/blob/master/LICENSE
using System;
namespace HandyControl.Data
{
public struct SystemVersionInfo
{
public static SystemVersionInfo Windows10 => new SystemVersionInfo(10, 0, 10240);
public static SystemVersionInfo Windows10_1809 => new SystemVersionInfo(10, 0, 17763);
public SystemVersionInfo(int major, int minor, int build)
{
Major = major;
Minor = minor;
Build = build;
}
public int Major { get; }
public int Minor { get; }
public int Build { get; }
public bool Equals(SystemVersionInfo other) => Major == other.Major && Minor == other.Minor && Build == other.Build;
public override bool Equals(object obj) => obj is SystemVersionInfo other && Equals(other);
public override int GetHashCode() => Major.GetHashCode() ^ Minor.GetHashCode() ^ Build.GetHashCode();
public static bool operator ==(SystemVersionInfo left, SystemVersionInfo right) => left.Equals(right);
public static bool operator !=(SystemVersionInfo left, SystemVersionInfo right) => !(left == right);
public int CompareTo(SystemVersionInfo other)
{
if (Major != other.Major)
{
return Major.CompareTo(other.Major);
}
if (Minor != other.Minor)
{
return Minor.CompareTo(other.Minor);
}
if (Build != other.Build)
{
return Build.CompareTo(other.Build);
}
return 0;
}
public int CompareTo(object obj)
{
if (!(obj is SystemVersionInfo other))
{
throw new ArgumentException();
}
return CompareTo(other);
}
public static bool operator <(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) < 0;
public static bool operator <=(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) <= 0;
public static bool operator >(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) > 0;
public static bool operator >=(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) >= 0;
public override string ToString() => $"{Major}.{Minor}.{Build}";
}
}
@@ -0,0 +1,36 @@
namespace HandyControl.Data
{
/// <summary>
/// 装箱后的值类型(用于提高效率)
/// </summary>
internal static class ValueBoxes
{
internal static object TrueBox = true;
internal static object FalseBox = false;
internal static object Double0Box = .0;
internal static object Double1Box = 1.0;
internal static object Double20Box = 20.0;
internal static object Double100Box = 100.0;
internal static object Double200Box = 200.0;
internal static object Double300Box = 300.0;
internal static object DoubleNeg1Box = -1.0;
internal static object Int0Box = 0;
internal static object Int1Box = 1;
internal static object Int2Box = 2;
internal static object Int5Box = 5;
internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
}
}