diff --git a/PInvoke/DwmApi/DwmApi.cs b/PInvoke/DwmApi/DwmApi.cs index e25c5944..c260ca96 100644 --- a/PInvoke/DwmApi/DwmApi.cs +++ b/PInvoke/DwmApi/DwmApi.cs @@ -458,8 +458,8 @@ namespace Vanara.PInvoke [PInvokeData("dwmapi.h")] public static HRESULT DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out T pvAttribute) { + if (!CorrespondingTypeAttribute.CanGet(dwAttribute, typeof(T))) throw new ArgumentException(); var isBool = typeof(T) == typeof(bool); - if (!(typeof(T) == typeof(RECT) || isBool || typeof(T) == typeof(int) || typeof(T).IsEnum)) throw new ArgumentException(); var m = new SafeCoTaskMemHandle(Marshal.SizeOf(isBool ? typeof(uint) : typeof(T))); var hr = DwmGetWindowAttribute(hwnd, dwAttribute, (IntPtr)m, m.Size); pvAttribute = isBool ? (T)Convert.ChangeType(m.ToStructure(), typeof(bool)) : m.ToStructure(); @@ -617,7 +617,7 @@ namespace Vanara.PInvoke [PInvokeData("dwmapi.h")] public static HRESULT DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, [In] T pvAttribute) { - if (pvAttribute == null || !(pvAttribute is bool || pvAttribute is int || typeof(T).IsEnum)) throw new ArgumentException(); + if (pvAttribute == null || !CorrespondingTypeAttribute.CanSet(dwAttribute, typeof(T))) throw new ArgumentException(); var attr = pvAttribute is bool ? (object)Convert.ToUInt32(pvAttribute) : pvAttribute; using (var p = new PinnedObject(attr)) return DwmSetWindowAttribute(hwnd, dwAttribute, p, Marshal.SizeOf(attr));