Merge pull request #26039 from neikeq/throw_objectdisposedexception

C#: Throw ObjectDisposedException from disposed wrapper classes
This commit is contained in:
Ignacio Etcheverry 2019-02-19 01:02:20 +01:00 committed by GitHub
commit 29fd942dd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 4 deletions

View file

@ -50,6 +50,9 @@ namespace Godot.Collections
internal IntPtr GetPtr() internal IntPtr GetPtr()
{ {
if (disposed)
throw new ObjectDisposedException(GetType().FullName);
return safeHandle.DangerousGetHandle(); return safeHandle.DangerousGetHandle();
} }

View file

@ -54,6 +54,9 @@ namespace Godot.Collections
internal IntPtr GetPtr() internal IntPtr GetPtr()
{ {
if (disposed)
throw new ObjectDisposedException(GetType().FullName);
return safeHandle.DangerousGetHandle(); return safeHandle.DangerousGetHandle();
} }

View file

@ -11,7 +11,13 @@ namespace Godot
internal static IntPtr GetPtr(NodePath instance) internal static IntPtr GetPtr(NodePath instance)
{ {
return instance == null ? IntPtr.Zero : instance.ptr; if (instance == null)
return IntPtr.Zero;
if (instance.disposed)
throw new ObjectDisposedException(instance.GetType().FullName);
return instance.ptr;
} }
~NodePath() ~NodePath()
@ -49,7 +55,7 @@ namespace Godot
get { return ptr; } get { return ptr; }
} }
public NodePath() : this(string.Empty) {} public NodePath() : this(string.Empty) { }
public NodePath(string path) public NodePath(string path)
{ {

View file

@ -30,7 +30,13 @@ namespace Godot
internal static IntPtr GetPtr(Object instance) internal static IntPtr GetPtr(Object instance)
{ {
return instance == null ? IntPtr.Zero : instance.ptr; if (instance == null)
return IntPtr.Zero;
if (instance.disposed)
throw new ObjectDisposedException(instance.GetType().FullName);
return instance.ptr;
} }
~Object() ~Object()

View file

@ -11,7 +11,13 @@ namespace Godot
internal static IntPtr GetPtr(RID instance) internal static IntPtr GetPtr(RID instance)
{ {
return instance == null ? IntPtr.Zero : instance.ptr; if (instance == null)
return IntPtr.Zero;
if (instance.disposed)
throw new ObjectDisposedException(instance.GetType().FullName);
return instance.ptr;
} }
~RID() ~RID()