Throw proper exceptions if trying to use drawing api before
initializing XWT.
This commit is contained in:
Lluis Sanchez 2013-11-06 18:31:57 +01:00
Родитель 309a36f6ab
Коммит d517fc7c25
3 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -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")
{
}
}
}