mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
Added helper method for setting properties and auto raising signal if value changes.
This commit is contained in:
parent
cebef7514f
commit
df051b8582
1 changed files with 11 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue