forked from enlightenment/efl
mono: implement dispose method based on dispose pattern
Summary: Fix CA1063, CA1816 ref T8400, T8419 Test Plan: meson setup -Dbindings=mono,cxx -Dmono-beta=true ninja test Reviewers: felipealmeida, brunobelo, YOhoho Reviewed By: YOhoho Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8419, T8400 Differential Revision: https://phab.enlightenment.org/D10460
This commit is contained in:
parent
bcf27e35a2
commit
69261251a7
|
@ -18,7 +18,7 @@ namespace Efl {
|
|||
/// </summary>
|
||||
/// <typeparam name="T">The type of the child model. It is the type used when adding/removing/getting items to this
|
||||
/// model.</typeparam>
|
||||
public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable
|
||||
public class GenericModel<T> : Efl.Object, Efl.IModel
|
||||
{
|
||||
private Efl.IModel model;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Efl.Ui
|
|||
/// factory.Style().Bind("Name"); // The factory Style property is bound to the Name property for the given model.
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class ItemFactory<T> : Efl.Ui.LayoutFactory, IDisposable
|
||||
public class ItemFactory<T> : Efl.Ui.LayoutFactory
|
||||
{
|
||||
/// <summary>Creates a new factory.
|
||||
/// </summary>
|
||||
|
|
|
@ -67,7 +67,7 @@ internal class ModelHelper
|
|||
/// </summary>
|
||||
/// <typeparam name="T">The enclosed C# model class with the properties to be added to the native model.</typeparam>
|
||||
[Efl.Eo.BindingEntity]
|
||||
public class UserModel<T> : Efl.MonoModelInternal, IDisposable
|
||||
public class UserModel<T> : Efl.MonoModelInternal
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new root model.
|
||||
|
@ -85,12 +85,6 @@ public class UserModel<T> : Efl.MonoModelInternal, IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Disposes of this instance.</summary>
|
||||
~UserModel()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>Adds a new child to the model wrapping the properties of <c>o</c>
|
||||
///
|
||||
/// <para>Reflection is used to instantiate a new <see cref="Efl.IModel" />-based class for this child and
|
||||
|
|
|
@ -95,6 +95,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
|
|||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>Disposes of this wrapper, releasing the native accessor if
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Efl.Eo
|
|||
public partial class NativeModule : IDisposable
|
||||
{
|
||||
private Lazy<IntPtr> module;
|
||||
private bool disposed = false;
|
||||
|
||||
///<summary>Lazily tries to load the module with the given name.</summary>
|
||||
///<param name="libName">The name of the module to load.</param>
|
||||
|
@ -43,12 +44,39 @@ public partial class NativeModule : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
///<summary>Unload and released the handle to the wrapped module.</summary>
|
||||
/// <summary>Finalizer to be called from the Garbage Collector.</summary>
|
||||
~NativeModule()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>Unload and released the handle to the wrapped module.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
UnloadLibrary(module.Value);
|
||||
module = null;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>Unload and released the handle to the wrapped module.</summary>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
module = null;
|
||||
}
|
||||
|
||||
if (module.IsValueCreated)
|
||||
{
|
||||
UnloadLibrary(module.Value);
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue