code formatting

This commit is contained in:
NaBian committed 2021-06-08 23:11:14 +08:00
1 parent 6a3711e6e0
commit 5afb569d11
43 files changed
+200 -287

No files matched your search

@@ -79,38 +79,26 @@ namespace HandyControl.Tools
var layoutSlot = LayoutInformation.GetLayoutSlot(element);
var x = 0.0;
var y = 0.0;
switch (element.HorizontalAlignment)
x = element.HorizontalAlignment switch
{
case HorizontalAlignment.Left:
x = layoutSlot.Left + margin.Left;
break;
case HorizontalAlignment.Center:
x = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0;
break;
case HorizontalAlignment.Right:
x = layoutSlot.Right - margin.Right - width;
break;
case HorizontalAlignment.Stretch:
x = Math.Max(layoutSlot.Left + margin.Left,
(layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0);
break;
}
switch (element.VerticalAlignment)
HorizontalAlignment.Left => layoutSlot.Left + margin.Left,
HorizontalAlignment.Center => (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 -
width / 2.0,
HorizontalAlignment.Right => layoutSlot.Right - margin.Right - width,
HorizontalAlignment.Stretch => Math.Max(layoutSlot.Left + margin.Left,
(layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0),
_ => x
};
y = element.VerticalAlignment switch
{
case VerticalAlignment.Top:
y = layoutSlot.Top + margin.Top;
break;
case VerticalAlignment.Center:
y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0;
break;
case VerticalAlignment.Bottom:
y = layoutSlot.Bottom - margin.Bottom - height;
break;
case VerticalAlignment.Stretch:
y = Math.Max(layoutSlot.Top + margin.Top,
(layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0);
break;
}
VerticalAlignment.Top => layoutSlot.Top + margin.Top,
VerticalAlignment.Center => (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 -
height / 2.0,
VerticalAlignment.Bottom => layoutSlot.Bottom - margin.Bottom - height,
VerticalAlignment.Stretch => Math.Max(layoutSlot.Top + margin.Top,
(layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0),
_ => y
};
return new Rect(x, y, width, height);
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
@@ -9,6 +10,8 @@ using HandyControl.Tools.Interop;
namespace HandyControl.Tools
{
[SuppressMessage("ReSharper", "ArrangeRedundantParentheses")]
[SuppressMessage("ReSharper", "IntVariableOverflowInUncheckedContext")]
internal static class IconHelper
{
private static Size SmallIconSize;
@@ -12,10 +12,7 @@ namespace HandyControl.Tools
[SecurityCritical]
internal static void DemandUIWindowPermission()
{
if (_allWindowsUIPermission == null)
{
_allWindowsUIPermission = new UIPermission(UIPermissionWindow.AllWindows);
}
_allWindowsUIPermission ??= new UIPermission(UIPermissionWindow.AllWindows);
_allWindowsUIPermission.Demand();
}
}
@@ -166,7 +166,7 @@ namespace HandyControl.Tools.Interop
internal static BitmapHandle CreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset)
{
if (hSection == null) hSection = new SafeFileMappingHandle(IntPtr.Zero);
hSection ??= new SafeFileMappingHandle(IntPtr.Zero);
var hBitmap = PrivateCreateDIBSection(hdc, ref bitmapInfo, iUsage, ref ppvBits, hSection, dwOffset);
return hBitmap;
@@ -547,7 +547,7 @@ namespace HandyControl.Tools.Interop
}
[StructLayout(LayoutKind.Sequential)]
private struct StartupOutput
private readonly struct StartupOutput
{
private readonly IntPtr hook;
@@ -613,31 +613,30 @@ namespace HandyControl.Tools.Interop
internal static Exception StatusException(int status)
{
switch (status)
return status switch
{
case GenericError: return new ExternalException("GdiplusGenericError");
case InvalidParameter: return new ArgumentException("GdiplusInvalidParameter");
case OutOfMemory: return new OutOfMemoryException("GdiplusOutOfMemory");
case ObjectBusy: return new InvalidOperationException("GdiplusObjectBusy");
case InsufficientBuffer: return new OutOfMemoryException("GdiplusInsufficientBuffer");
case NotImplemented: return new NotImplementedException("GdiplusNotImplemented");
case Win32Error: return new ExternalException("GdiplusGenericError");
case WrongState: return new InvalidOperationException("GdiplusWrongState");
case Aborted: return new ExternalException("GdiplusAborted");
case FileNotFound: return new FileNotFoundException("GdiplusFileNotFound");
case ValueOverflow: return new OverflowException("GdiplusOverflow");
case AccessDenied: return new ExternalException("GdiplusAccessDenied");
case UnknownImageFormat: return new ArgumentException("GdiplusUnknownImageFormat");
case PropertyNotFound: return new ArgumentException("GdiplusPropertyNotFoundError");
case PropertyNotSupported: return new ArgumentException("GdiplusPropertyNotSupportedError");
case FontFamilyNotFound: return new ArgumentException("GdiplusFontFamilyNotFound");
case FontStyleNotFound: return new ArgumentException("GdiplusFontStyleNotFound");
case NotTrueTypeFont: return new ArgumentException("GdiplusNotTrueTypeFont_NoName");
case UnsupportedGdiplusVersion: return new ExternalException("GdiplusUnsupportedGdiplusVersion");
case GdiplusNotInitialized: return new ExternalException("GdiplusNotInitialized");
}
return new ExternalException("GdiplusUnknown");
GenericError => new ExternalException("GdiplusGenericError"),
InvalidParameter => new ArgumentException("GdiplusInvalidParameter"),
OutOfMemory => new OutOfMemoryException("GdiplusOutOfMemory"),
ObjectBusy => new InvalidOperationException("GdiplusObjectBusy"),
InsufficientBuffer => new OutOfMemoryException("GdiplusInsufficientBuffer"),
NotImplemented => new NotImplementedException("GdiplusNotImplemented"),
Win32Error => new ExternalException("GdiplusGenericError"),
WrongState => new InvalidOperationException("GdiplusWrongState"),
Aborted => new ExternalException("GdiplusAborted"),
FileNotFound => new FileNotFoundException("GdiplusFileNotFound"),
ValueOverflow => new OverflowException("GdiplusOverflow"),
AccessDenied => new ExternalException("GdiplusAccessDenied"),
UnknownImageFormat => new ArgumentException("GdiplusUnknownImageFormat"),
PropertyNotFound => new ArgumentException("GdiplusPropertyNotFoundError"),
PropertyNotSupported => new ArgumentException("GdiplusPropertyNotSupportedError"),
FontFamilyNotFound => new ArgumentException("GdiplusFontFamilyNotFound"),
FontStyleNotFound => new ArgumentException("GdiplusFontStyleNotFound"),
NotTrueTypeFont => new ArgumentException("GdiplusNotTrueTypeFont_NoName"),
UnsupportedGdiplusVersion => new ExternalException("GdiplusUnsupportedGdiplusVersion"),
GdiplusNotInitialized => new ExternalException("GdiplusNotInitialized"),
_ => new ExternalException("GdiplusUnknown")
};
}
[DllImport(InteropValues.ExternDll.GdiPlus, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
@@ -53,15 +53,15 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns>
public static bool IsIp(this string ip, IpType ipType)
{
switch (ipType)
return ipType switch
{
case IpType.A: return Regex.IsMatch(ip, RegexPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegexPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegexPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegexPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegexPatterns.IpEPattern);
default: return false;
}
IpType.A => Regex.IsMatch(ip, RegexPatterns.IpAPattern),
IpType.B => Regex.IsMatch(ip, RegexPatterns.IpBPattern),
IpType.C => Regex.IsMatch(ip, RegexPatterns.IpCPattern),
IpType.D => Regex.IsMatch(ip, RegexPatterns.IpDPattern),
IpType.E => Regex.IsMatch(ip, RegexPatterns.IpEPattern),
_ => false
};
}
/// <summary>