Repository navigation
Expand file tree
/
Copy pathObjectExtention.cs
More file actions
60 lines (55 loc) · 1.62 KB
/
Copy pathObjectExtention.cs
File metadata and controls
60 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections.Generic;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using ThunderDesign.Net_PCL.ToolBox.Helpers;
#endif
namespace ThunderDesign.Net.Threading.Extentions
{
public static class ObjectExtention
{
public static T GetProperty<T>(
this object sender,
ref T backingStore,
object? lockObj = null)
{
bool lockWasTaken = false;
try
{
if (lockObj != null)
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);
return backingStore;
}
finally
{
if (lockWasTaken)
System.Threading.Monitor.Exit(lockObj!);
}
}
public static bool SetProperty<T>(
this object sender,
ref T backingStore,
T value,
object? lockObj = null)
{
bool lockWasTaken = false;
try
{
if (lockObj != null)
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
if (EqualityHelper.Equality<T>(ref backingStore, value))
return false;
#else
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
#endif
backingStore = value;
}
finally
{
if (lockWasTaken)
System.Threading.Monitor.Exit(lockObj!);
}
return true;
}
}
}