lauromoura pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=69261251a71f02111a046b97fbb2e520f8d1dc1e

commit 69261251a71f02111a046b97fbb2e520f8d1dc1e
Author: Yeongjong Lee <[email protected]>
Date:   Thu Oct 24 17:46:13 2019 -0300

    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
---
 src/bindings/mono/efl_mono/GenericModel.cs   |  2 +-
 src/bindings/mono/efl_mono/ItemFactory.cs    |  2 +-
 src/bindings/mono/efl_mono/UserModel.cs      |  8 +------
 src/bindings/mono/eina_mono/eina_accessor.cs |  1 +
 src/bindings/mono/eo_mono/NativeModule.cs    | 34 +++++++++++++++++++++++++---
 5 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/bindings/mono/efl_mono/GenericModel.cs 
b/src/bindings/mono/efl_mono/GenericModel.cs
index 1f92b8cd3e..8bfa8ce2f7 100644
--- a/src/bindings/mono/efl_mono/GenericModel.cs
+++ b/src/bindings/mono/efl_mono/GenericModel.cs
@@ -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;
 
diff --git a/src/bindings/mono/efl_mono/ItemFactory.cs 
b/src/bindings/mono/efl_mono/ItemFactory.cs
index 34791e1213..a97401c9aa 100644
--- a/src/bindings/mono/efl_mono/ItemFactory.cs
+++ b/src/bindings/mono/efl_mono/ItemFactory.cs
@@ -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>
diff --git a/src/bindings/mono/efl_mono/UserModel.cs 
b/src/bindings/mono/efl_mono/UserModel.cs
index 1116dfc561..a235a3a87f 100644
--- a/src/bindings/mono/efl_mono/UserModel.cs
+++ b/src/bindings/mono/efl_mono/UserModel.cs
@@ -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
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs 
b/src/bindings/mono/eina_mono/eina_accessor.cs
index 6c939bcb52..64b4216a15 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -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
diff --git a/src/bindings/mono/eo_mono/NativeModule.cs 
b/src/bindings/mono/eo_mono/NativeModule.cs
index fd3b315561..ad9cc60214 100644
--- a/src/bindings/mono/eo_mono/NativeModule.cs
+++ b/src/bindings/mono/eo_mono/NativeModule.cs
@@ -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;
+   }
 }
 
 }

-- 


Reply via email to