Added helper method for setting properties and auto raising signal if value changes.

This commit is contained in:
Paul Knopf 2018-12-27 21:34:20 -05:00
parent cebef7514f
commit df051b8582

View file

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using Qml.Net.Internal;
@ -66,6 +67,15 @@ namespace Qml.Net
return ActivateSignal(instance, signalName);
}
public static bool SetProperty<T>(this object instance, ref T storage, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(storage, value))
return false;
storage = value;
instance.ActivateNotifySignal(propertyName);
return true;
}
public static void AttachToSignal(this object instance, string signalName, System.Delegate del)
{
instance.AttachDelegateToSignal(signalName, del);