Added some null ref checks
Throw proper exceptions if trying to use drawing api before initializing XWT.
This commit is contained in:
Родитель
309a36f6ab
Коммит
d517fc7c25
|
@ -162,6 +162,8 @@ namespace Xwt.Drawing
|
|||
throw new ArgumentNullException ("resource");
|
||||
|
||||
var toolkit = Toolkit.CurrentEngine;
|
||||
if (toolkit == null)
|
||||
throw new ToolkitNotInitializedException ();
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension (resource);
|
||||
|
||||
|
@ -194,6 +196,8 @@ namespace Xwt.Drawing
|
|||
|
||||
public static Image CreateMultiSizeIcon (IEnumerable<Image> images)
|
||||
{
|
||||
if (Toolkit.CurrentEngine == null)
|
||||
throw new ToolkitNotInitializedException ();
|
||||
return new Image (Toolkit.CurrentEngine.ImageBackendHandler.CreateMultiSizeIcon (images.Select (i => i.GetBackend ())));
|
||||
}
|
||||
|
||||
|
@ -254,12 +258,16 @@ namespace Xwt.Drawing
|
|||
public static Image FromFile (string file)
|
||||
{
|
||||
var toolkit = Toolkit.CurrentEngine;
|
||||
if (toolkit == null)
|
||||
throw new ToolkitNotInitializedException ();
|
||||
return new Image (toolkit.ImageBackendHandler.LoadFromFile (file), toolkit);
|
||||
}
|
||||
|
||||
public static Image FromStream (Stream stream)
|
||||
{
|
||||
var toolkit = Toolkit.CurrentEngine;
|
||||
if (toolkit == null)
|
||||
throw new ToolkitNotInitializedException ();
|
||||
return new Image (toolkit.ImageBackendHandler.LoadFromStream (stream), toolkit);
|
||||
}
|
||||
|
||||
|
|
|
@ -315,6 +315,7 @@
|
|||
<Compile Include="Xwt\Keyboard.cs" />
|
||||
<Compile Include="Xwt.Backends\KeyboardHandler.cs" />
|
||||
<Compile Include="Xwt\FrameBox.cs" />
|
||||
<Compile Include="Xwt\ToolkitNotInitializedException.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup />
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// ToolkitNotInitializedException.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
using System;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
public class ToolkitNotInitializedException: Exception
|
||||
{
|
||||
public ToolkitNotInitializedException (): base ("XWT has not been initialized")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче