simplify new expression

This commit is contained in:
NaBian committed 2021-06-08 20:35:14 +08:00
1 parent 42b2cb3033
commit 193090da43
59 files changed
+149 -149

No files matched your search

@@ -21,7 +21,7 @@ namespace HandyControl.Tools.Converter
{
Figures = new PathFigureCollection
{
new PathFigure(new Point(radius.TopLeft, 0), new PathSegment[]
new(new Point(radius.TopLeft, 0), new PathSegment[]
{
new LineSegment(new Point(width - radius.TopRight, 0), false),
new ArcSegment(new Point(width, radius.TopRight), new Size(radius.TopRight, radius.TopRight), 90, false, SweepDirection.Clockwise, false),
@@ -23,7 +23,7 @@ namespace HandyControl.Tools.Extension
/// <returns></returns>
public static int ToInt32Reverse(this Color color) => color.R | color.G << 8 | color.B << 18;
internal static List<byte> ToList(this Color color) => new List<byte>
internal static List<byte> ToList(this Color color) => new()
{
color.R,
color.G,
@@ -5,7 +5,7 @@ namespace HandyControl.Tools.Extension
{
public static class ValueExtension
{
public static Thickness Add(this Thickness a, Thickness b) => new Thickness(a.Left + b.Left, a.Top + b.Top, a.Right + b.Right, a.Bottom + b.Bottom);
public static Thickness Add(this Thickness a, Thickness b) => new(a.Left + b.Left, a.Top + b.Top, a.Right + b.Right, a.Bottom + b.Bottom);
public static bool IsZero(this Thickness thickness) =>
MathHelper.IsZero(thickness.Left)
@@ -7,7 +7,7 @@ namespace HandyControl.Tools
{
public class ComparerGenerator
{
private static readonly Dictionary<Type, ComparerTypeCode> TypeCodeDic = new Dictionary<Type, ComparerTypeCode>
private static readonly Dictionary<Type, ComparerTypeCode> TypeCodeDic = new()
{
[typeof(DateTimeRange)] = ComparerTypeCode.DateTimeRange,
};
@@ -12,7 +12,7 @@ namespace HandyControl.Tools
{
private static List<GifImageInfo> ImageInfoList;
private static readonly ReaderWriterLock RwImgListLock = new ReaderWriterLock();
private static readonly ReaderWriterLock RwImgListLock = new();
private static Thread AnimationThread;
@@ -11,7 +11,7 @@ namespace HandyControl.Tools
{
private static ObservableCollection<KeyBinding> KeyBindingCollection;
private static readonly Dictionary<string, KeyBinding> CommandDic = new Dictionary<string, KeyBinding>();
private static readonly Dictionary<string, KeyBinding> CommandDic = new();
private static void KeyboardHook_KeyDown(object sender, KeyboardHookEventArgs e) => HitTest(e.Key);
@@ -21,7 +21,7 @@ namespace HandyControl.Tools
/// <returns></returns>
public static ThicknessAnimation CreateAnimation(Thickness thickness = default, double milliseconds = 200)
{
return new ThicknessAnimation(thickness, new Duration(TimeSpan.FromMilliseconds(milliseconds)))
return new(thickness, new Duration(TimeSpan.FromMilliseconds(milliseconds)))
{
EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut }
};
@@ -35,7 +35,7 @@ namespace HandyControl.Tools
/// <returns></returns>
public static DoubleAnimation CreateAnimation(double toValue, double milliseconds = 200)
{
return new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(milliseconds)))
return new(toValue, new Duration(TimeSpan.FromMilliseconds(milliseconds)))
{
EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut }
};
@@ -10,7 +10,7 @@ namespace HandyControl.Tools
/// </summary>
public class SingleOpenHelper
{
private static readonly Dictionary<string, ISingleOpen> OpenDic = new Dictionary<string, ISingleOpen>();
private static readonly Dictionary<string, ISingleOpen> OpenDic = new();
/// <summary>
/// 根据指定的类型创建实例
@@ -20,13 +20,13 @@ namespace HandyControl.Tools
/// <returns></returns>
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
private static readonly BitArray _cacheValid = new BitArray((int) InteropValues.CacheSlot.NumSlots);
private static readonly BitArray _cacheValid = new((int) InteropValues.CacheSlot.NumSlots);
private static bool _setDpiX = true;
private static bool _dpiInitialized;
private static readonly object _dpiLock = new object();
private static readonly object _dpiLock = new();
private static int _dpi;
@@ -8,7 +8,7 @@ namespace HandyControl.Tools
{
public class SystemMenuHook
{
private static readonly Dictionary<int, HwndSource> DataDic = new Dictionary<int, HwndSource>();
private static readonly Dictionary<int, HwndSource> DataDic = new();
public static event Action<int> Click;
@@ -30,13 +30,13 @@ namespace HandyControl.Tools.Interop
[SecurityCritical]
internal HandleRef MakeHandleRef(object obj)
{
return new HandleRef(obj, handle);
return new(obj, handle);
}
[SecurityCritical]
internal static BitmapHandle CreateFromHandle(IntPtr hbitmap, bool ownsHandle = true)
{
return new BitmapHandle(ownsHandle)
return new(ownsHandle)
{
handle = hbitmap,
};
@@ -10,7 +10,7 @@ namespace HandyControl.Tools.Interop
private static HandleType[] HandleTypes;
private static int HandleTypeCount;
private static readonly object HandleMutex = new object();
private static readonly object HandleMutex = new();
internal static IntPtr Add(IntPtr handle, int type)
{
@@ -21,7 +21,7 @@ namespace HandyControl.Tools.Interop
[SecurityCritical, SecuritySafeCritical]
internal static IconHandle GetInvalidIcon()
{
return new IconHandle();
return new();
}
[SecurityCritical]
@@ -19,7 +19,7 @@ namespace HandyControl.Tools.Interop
internal const int E_FAIL = unchecked((int) 0x80004005);
internal static readonly IntPtr HRGN_NONE = new IntPtr(-1);
internal static readonly IntPtr HRGN_NONE = new(-1);
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
@@ -240,8 +240,8 @@ namespace HandyControl.Tools.Interop
Bottom = (int) rect.Bottom;
}
public Point Position => new Point(Left, Top);
public Size Size => new Size(Width, Height);
public Point Position => new(Left, Top);
public Size Size => new(Width, Height);
public int Height
{
@@ -2,7 +2,7 @@
{
public class SynchronizedPool<T> : SimplePool<T>
{
private readonly object _lockObj = new object();
private readonly object _lockObj = new();
public SynchronizedPool(int maxPoolSize) : base(maxPoolSize)
{
@@ -9,7 +9,7 @@ namespace HandyControl.Tools
/// </summary>
public static class RegexJudgment
{
private static readonly RegexPatterns RegexPatterns = new RegexPatterns();
private static readonly RegexPatterns RegexPatterns = new();
/// <summary>
/// 判断字符串格式是否符合某种要求