Skip to content

Commit

Permalink
Fix AOT incompatible code (#7534)
Browse files Browse the repository at this point in the history
* Fix AOT incompatible code
Use code patterns which are AOT-friendly. That improves R2R and Native AOT scenarios
  • Loading branch information
kant2002 authored Feb 5, 2022
1 parent fb7cf3d commit 0dca903
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.X11/NativeDialogs/Gtk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Dispose()
public static IDisposable ConnectSignal<T>(IntPtr obj, string name, T handler)
{
var handle = GCHandle.Alloc(handler);
var ptr = Marshal.GetFunctionPointerForDelegate((Delegate)(object)handler);
var ptr = Marshal.GetFunctionPointerForDelegate<T>(handler);
using (var utf = new Utf8Buffer(name))
{
var id = g_signal_connect_object(obj, utf, ptr, IntPtr.Zero, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ public struct BITMAPINFOHEADER

public void Init()
{
biSize = (uint)Marshal.SizeOf(this);
biSize = (uint)sizeof(BITMAPINFOHEADER);
}
}

Expand Down Expand Up @@ -1521,7 +1521,7 @@ internal struct RTL_OSVERSIONINFOEX
internal static Version RtlGetVersion()
{
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf(v);
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
if (RtlGetVersion(ref v) == 0)
{
return new Version((int)v.dwMajorVersion, (int)v.dwMinorVersion, (int)v.dwBuildNumber);
Expand Down Expand Up @@ -1914,7 +1914,7 @@ public static WINDOWPLACEMENT Default
get
{
WINDOWPLACEMENT result = new WINDOWPLACEMENT();
result.Length = Marshal.SizeOf(result);
result.Length = Marshal.SizeOf<WINDOWPLACEMENT>();
return result;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public Size? FrameSize
return new Size(rcWindow.Width, rcWindow.Height) / RenderScaling;
}

DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var rect, Marshal.SizeOf(typeof(RECT)));
DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var rect, Marshal.SizeOf<RECT>());
return new Size(rect.Width, rect.Height) / RenderScaling;
}
}
Expand Down Expand Up @@ -337,7 +337,7 @@ private WindowTransparencyLevel Win7EnableBlur(WindowTransparencyLevel transpare
private WindowTransparencyLevel Win8xEnableBlur(WindowTransparencyLevel transparencyLevel)
{
var accent = new AccentPolicy();
var accentStructSize = Marshal.SizeOf(accent);
var accentStructSize = Marshal.SizeOf<AccentPolicy>();

if (transparencyLevel == WindowTransparencyLevel.AcrylicBlur)
{
Expand Down Expand Up @@ -392,7 +392,7 @@ private WindowTransparencyLevel Win10EnableBlur(WindowTransparencyLevel transpar
bool canUseAcrylic = Win32Platform.WindowsVersion.Major > 10 || Win32Platform.WindowsVersion.Build >= 19628;

var accent = new AccentPolicy();
var accentStructSize = Marshal.SizeOf(accent);
var accentStructSize = Marshal.SizeOf<AccentPolicy>();

if (transparencyLevel == WindowTransparencyLevel.AcrylicBlur && !canUseAcrylic)
{
Expand Down

0 comments on commit 0dca903

Please sign in to comment.