Ryujinx-GtkSharp/Source/Libs/GtkSharp/CssProvider.cs
zii-dmg e48e6e0380
Fix loading of resources if jit inlines method (#328)
Added no inlining attribute for methods with Assembly.GetCallingAssembly() so caller assembly is correct if jit want to inline.
See https://github.com/picoe/Eto/pull/2049.
2022-01-27 21:49:41 +01:00

31 lines
857 B
C#

namespace Gtk
{
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
public partial class CssProvider
{
[MethodImpl(MethodImplOptions.NoInlining)]
public bool LoadFromResource(string resource) => LoadFromResource(Assembly.GetCallingAssembly(), resource);
[MethodImpl(MethodImplOptions.NoInlining)]
public bool LoadFromResource(Assembly assembly, string resource)
{
if (assembly == null)
assembly = Assembly.GetCallingAssembly();
Stream stream = assembly.GetManifestResourceStream(resource);
if (stream == null)
throw new ArgumentException("'" + resource + "' is not a valid resource name of assembly '" + assembly + "'.", nameof(resource));
using (var reader = new StreamReader(stream))
{
string data = reader.ReadToEnd();
return LoadFromData(data);
}
}
}
}