Skip to content

Commit

Permalink
EditorPage would refer EditorPage's CurrentMap and check null r…
Browse files Browse the repository at this point in the history
…eferencing
  • Loading branch information
iconstudio committed Oct 6, 2023
1 parent e508487 commit 0c55029
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Editor/TestEditor/Infrastructures/EditorCanvas.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,37 @@ namespace TestEditor
{
public sealed partial class EditorCanvas : UserControl
{
public Map CurrentMap { get; set; }
private class NullEditorPageException : NullReferenceException
{
public NullEditorPageException(string message) : base(message)
{ }
}

public Map CurrentMap
{
get
{
if (Parent is EditorPage editor)
{
return editor.CurrentMap;
}
else
{
throw new NullEditorPageException("Parent is null");
}
}
set
{
if (Parent is EditorPage editor)
{
editor.CurrentMap = value;
}
else
{
throw new NullEditorPageException("Parent is null");
}
}
}
public event TypedEventHandler<CanvasControl, CanvasDrawEventArgs> Draw
{
add => Canvas.Draw += value;
Expand Down

0 comments on commit 0c55029

Please sign in to comment.