diff --git a/dotnet/IEC61850forCSharp/MmsValue.cs b/dotnet/IEC61850forCSharp/MmsValue.cs index 5d9900df..79f570a0 100644 --- a/dotnet/IEC61850forCSharp/MmsValue.cs +++ b/dotnet/IEC61850forCSharp/MmsValue.cs @@ -36,7 +36,7 @@ namespace IEC61850 /// /// This class is used to hold MMS data values of different types. /// - public class MmsValue : IEnumerable + public class MmsValue : IEnumerable, IDisposable { [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr MmsValue_toString (IntPtr self); @@ -182,6 +182,9 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr MmsVariableSpecification_getChildValue(IntPtr self, IntPtr value, string childId); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr MmsValue_clone(IntPtr self); + internal IntPtr valueReference; /* reference to native MmsValue instance */ private bool responsableForDeletion; /* if .NET wrapper is responsable for the deletion of the native MmsValue instance */ @@ -237,11 +240,23 @@ namespace IEC61850 valueReference = MmsValue_newVisibleString(value); } - ~MmsValue () - { - if (responsableForDeletion) - MmsValue_delete (valueReference); - } + public void Dispose() + { + lock (this) { + if (valueReference != IntPtr.Zero) { + + if (responsableForDeletion) + MmsValue_delete (valueReference); + + valueReference = IntPtr.Zero; + } + } + } + + ~MmsValue () + { + Dispose(); + } /// /// Create a new MmsValue instance of type MMS_BIT_STRING. @@ -888,6 +903,19 @@ namespace IEC61850 } } + /// + /// Get an identical copy of this instance + /// + public MmsValue Clone() + { + IntPtr clonePtr = MmsValue_clone(valueReference); + + if (clonePtr == IntPtr.Zero) + return null; + + return new MmsValue(clonePtr, true); + } + public override bool Equals (object obj) { MmsValue otherValue = (MmsValue) obj;