te
This commit is contained in:
parent
01151e679b
commit
57b2f0400e
265 changed files with 22828 additions and 6 deletions
60
Unused/Decal.Adapter/DisposableByRefObject.cs
Normal file
60
Unused/Decal.Adapter/DisposableByRefObject.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
|
||||
namespace Decal.Adapter;
|
||||
|
||||
public class DisposableByRefObject : MarshalByRefObject, IDisposable
|
||||
{
|
||||
private bool isDisposed;
|
||||
|
||||
private EventHandler myDisposing;
|
||||
|
||||
public event EventHandler Disposing
|
||||
{
|
||||
add
|
||||
{
|
||||
myDisposing = (EventHandler)Delegate.Combine(myDisposing, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
myDisposing = (EventHandler)Delegate.Remove(myDisposing, value);
|
||||
}
|
||||
}
|
||||
|
||||
internal DisposableByRefObject()
|
||||
{
|
||||
}
|
||||
|
||||
~DisposableByRefObject()
|
||||
{
|
||||
Dispose(userCalled: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(userCalled: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool userCalled)
|
||||
{
|
||||
if (!isDisposed && userCalled && myDisposing != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
myDisposing(this, new EventArgs());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
isDisposed = true;
|
||||
}
|
||||
|
||||
protected void EnforceDisposedOnce()
|
||||
{
|
||||
if (isDisposed)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue