Skip to content

Commit

Permalink
Add compile time exclusion (#964)
Browse files Browse the repository at this point in the history
* Add compile time exclusion

* Accept suggested changes
  • Loading branch information
kaltinril authored Nov 20, 2024
1 parent 8b02498 commit 080f5e1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions source/MonoGame.Extended/Content/ContentReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ namespace MonoGame.Extended.Content
{
public static class ContentReaderExtensions
{
private static readonly FieldInfo _contentReaderGraphicsDeviceFieldInfo = typeof(ContentReader).GetTypeInfo().GetDeclaredField("graphicsDevice");

#if FNA
public static GraphicsDevice GetGraphicsDevice(this ContentReader contentReader)
{
var serviceProvider = contentReader.ContentManager.ServiceProvider;
var graphicsDeviceService = serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

if (graphicsDeviceService == null)
{
throw new InvalidOperationException("No Graphics Device Service");
}

public static GraphicsDevice GetGraphicsDevice(this ContentReader contentReader)
{
return (GraphicsDevice)_contentReaderGraphicsDeviceFieldInfo.GetValue(contentReader);
}
return graphicsDeviceService.GraphicsDevice;
}
#endif

public static string RemoveExtension(string path)
{
Expand Down

0 comments on commit 080f5e1

Please sign in to comment.