Skip to content

Commit 6d62d5d

Browse files
Merge pull request #43 from ThunderDesign/featureNet-10-Upgrade
Feature net 10 upgrade
2 parents 1815d9f + 257b62a commit 6d62d5d

70 files changed

Lines changed: 2736 additions & 184 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/ThunderDesign.Net-PCL.SourceGenerators/UnifiedPropertyGenerator.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ private static void GenerateUnifiedPropertyClass(
188188
GenerateRegularProperties(source, propertyFields, classSymbol, compilation);
189189

190190
source.AppendLine("}");
191+
source.AppendLine("#nullable restore");
191192
if (!string.IsNullOrEmpty(classSymbol.ContainingNamespace?.ToDisplayString()))
192193
source.AppendLine("}");
193194

@@ -512,7 +513,7 @@ private static void GenerateInfrastructureMembers(
512513
if (bindableFields.Count > 0 && !implementsINotify &&
513514
!PropertyGeneratorHelpers.EventExists(classSymbol, "PropertyChanged", propertyChangedEventType))
514515
{
515-
source.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
516+
source.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;");
516517
}
517518

518519
// Add _Locker if needed (only for non-static fields)
@@ -1096,6 +1097,7 @@ public static T GetStaticProperty<T>(
10961097
{
10971098
if (lockObj != null)
10981099
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);
1100+
10991101
return backingStore;
11001102
}
11011103
finally
@@ -1128,21 +1130,23 @@ public static bool SetStaticProperty<T>(
11281130
{
11291131
if (lockObj != null)
11301132
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);
1133+
1134+
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
1135+
if (ThunderDesign.Net_PCL.ToolBox.Helpers.EqualityHelper.Equality<T>(ref backingStore, value))
1136+
return false;
1137+
#else
11311138
if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(backingStore, value))
1132-
{
11331139
return false;
1134-
}
1135-
else
1136-
{
1137-
backingStore = value;
1138-
return true;
1139-
}
1140+
#endif
1141+
backingStore = value;
11401142
}
11411143
finally
11421144
{
11431145
if (lockWasTaken)
11441146
System.Threading.Monitor.Exit(lockObj!);
11451147
}
1148+
1149+
return true;
11461150
}");
11471151
}
11481152
}

‎src/ThunderDesign.Net-PCL.Threading.Shared/Attributes/BindablePropertyAttribute.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ public sealed class BindablePropertyAttribute : Attribute
1111
{
1212
public bool ThreadSafe { get; }
1313
public bool Notify { get; }
14-
public string[] AlsoNotify { get; }
15-
public string CallMethodAfterSet { get; }
14+
public string[]? AlsoNotify { get; }
15+
public string? CallMethodAfterSet { get; }
1616
public AccessorAccessibility Getter { get; }
1717
public AccessorAccessibility Setter { get; }
1818

1919
public BindablePropertyAttribute(
2020
bool threadSafe = true,
2121
bool notify = true,
22-
string[] alsoNotify = null,
23-
string callMethodAfterSet = null,
22+
string[]? alsoNotify = null,
23+
string? callMethodAfterSet = null,
2424
AccessorAccessibility getter = AccessorAccessibility.Public,
2525
AccessorAccessibility setter = AccessorAccessibility.Public)
2626
{

‎src/ThunderDesign.Net-PCL.Threading.Shared/Attributes/PropertyAttribute.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace ThunderDesign.Net.Threading.Attributes
88
public sealed class PropertyAttribute : Attribute
99
{
1010
public bool ThreadSafe { get; }
11-
public string CallMethodAfterSet { get; }
11+
public string? CallMethodAfterSet { get; }
1212
public AccessorAccessibility Getter { get; }
1313
public AccessorAccessibility Setter { get; }
1414

1515
public PropertyAttribute(
1616
bool threadSafe = true,
17-
string callMethodAfterSet = null,
17+
string? callMethodAfterSet = null,
1818
AccessorAccessibility getter = AccessorAccessibility.Public,
1919
AccessorAccessibility setter = AccessorAccessibility.Public)
2020
{

‎src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/IBindableObjectExtention.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static bool SetProperty<T>(
1919
this IBindableObject sender,
2020
ref T backingStore,
2121
T value,
22-
object lockObj,
22+
object? lockObj,
2323
bool notifyPropertyChanged,
2424
[CallerMemberName] string propertyName = "")
2525
{

‎src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/INotifyPropertyChangedExtension.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class INotifyPropertyChangedExtension
99
{
1010
public static void NotifyPropertyChanged(
1111
this INotifyPropertyChanged sender,
12-
PropertyChangedEventHandler handler,
12+
PropertyChangedEventHandler? handler,
1313
[CallerMemberName] string propertyName = "",
1414
bool notifyAndWait = true)
1515
{
@@ -18,7 +18,7 @@ public static void NotifyPropertyChanged(
1818

1919
public static void NotifyPropertyChanged(
2020
this INotifyPropertyChanged sender,
21-
PropertyChangedEventHandler handler,
21+
PropertyChangedEventHandler? handler,
2222
PropertyChangedEventArgs args,
2323
bool notifyAndWait = true)
2424
{
@@ -35,7 +35,7 @@ public static bool SetProperty<T>(
3535
this INotifyPropertyChanged sender,
3636
ref T backingStore,
3737
T value,
38-
PropertyChangedEventHandler propertyChangedEventHandler,
38+
PropertyChangedEventHandler? propertyChangedEventHandler,
3939
[CallerMemberName] string propertyName = "",
4040
bool notifyAndWait = true)
4141
{
@@ -46,8 +46,8 @@ public static bool SetProperty<T>(
4646
this INotifyPropertyChanged sender,
4747
ref T backingStore,
4848
T value,
49-
object lockObj,
50-
PropertyChangedEventHandler propertyChangedEventHandler,
49+
object? lockObj,
50+
PropertyChangedEventHandler? propertyChangedEventHandler,
5151
[CallerMemberName] string propertyName = "",
5252
bool notifyAndWait = true)
5353
{

‎src/ThunderDesign.Net-PCL.Threading.Shared/Extentions/ObjectExtention.cs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@ public static class ObjectExtention
1010
public static T GetProperty<T>(
1111
this object sender,
1212
ref T backingStore,
13-
object lockObj = null)
13+
object? lockObj = null)
1414
{
1515
bool lockWasTaken = false;
1616
try
1717
{
1818
if (lockObj != null)
1919
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);
20+
2021
return backingStore;
2122
}
2223
finally
2324
{
2425
if (lockWasTaken)
25-
System.Threading.Monitor.Exit(lockObj);
26+
System.Threading.Monitor.Exit(lockObj!);
2627
}
2728
}
2829

2930
public static bool SetProperty<T>(
3031
this object sender,
3132
ref T backingStore,
3233
T value,
33-
object lockObj = null)
34+
object? lockObj = null)
3435
{
3536
bool lockWasTaken = false;
3637
try
@@ -50,8 +51,9 @@ public static bool SetProperty<T>(
5051
finally
5152
{
5253
if (lockWasTaken)
53-
System.Threading.Monitor.Exit(lockObj);
54+
System.Threading.Monitor.Exit(lockObj!);
5455
}
56+
5557
return true;
5658
}
5759
}

‎src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class ThreadHelper
1111
catch { }
1212
};
1313

14-
public static void RunAndForget(Action action, Action<Exception> handler = null)
14+
public static void RunAndForget(Action action, Action<Exception>? handler = null)
1515
{
1616
if (action == null)
1717
throw new ArgumentNullException(nameof(action));
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
4+
using System.Text;
5+
using System.Threading;
6+
using ThunderDesign.Net.Threading.Extentions;
7+
8+
namespace ThunderDesign.Net.Threading.Objects
9+
{
10+
public abstract class DisposableThreadObject : ThreadObject, IDisposable
11+
{
12+
private CancellationTokenSource? _disposingCtsCached = null;
13+
14+
protected readonly string ClassNameCashed;
15+
private bool _disposed = false;
16+
17+
protected DisposableThreadObject()
18+
{
19+
ClassNameCashed = this.GetType().Name;
20+
}
21+
22+
~DisposableThreadObject()
23+
{
24+
Dispose(disposing: false);
25+
}
26+
27+
protected bool Disposed
28+
{
29+
get { return this.GetProperty(ref _disposed, _Locker); }
30+
set { this.SetProperty(ref _disposed, value, _Locker); }
31+
}
32+
33+
protected CancellationTokenSource DisposingCts => DisposingCtsCache ??= new CancellationTokenSource();
34+
35+
protected CancellationTokenSource? DisposingCtsCache
36+
{
37+
get { return this.GetProperty(ref _disposingCtsCached, _Locker); }
38+
private set { this.SetProperty(ref _disposingCtsCached, value, _Locker); }
39+
}
40+
41+
protected CancellationTokenSource LinkTokenSourceDisposing(CancellationToken cancellationToken)
42+
{
43+
return CancellationTokenSource.CreateLinkedTokenSource(DisposingCts.Token, cancellationToken);
44+
}
45+
46+
protected void ThrowIfDisposed()
47+
{
48+
if (Disposed || DisposingCtsCache?.IsCancellationRequested == true)
49+
throw new ObjectDisposedException(ClassNameCashed);
50+
}
51+
52+
public void Dispose()
53+
{
54+
Dispose(true);
55+
GC.SuppressFinalize(this);
56+
}
57+
58+
protected virtual void Dispose(bool disposing, bool setDisposed = true)
59+
{
60+
if (!Disposed)
61+
{
62+
if (disposing)
63+
{
64+
// Dispose managed resources here
65+
DisposingCtsCache?.Cancel();
66+
DisposingCtsCache?.Dispose();
67+
}
68+
69+
// Dispose unmanaged resources here
70+
71+
if (setDisposed)
72+
{
73+
Disposed = true;
74+
}
75+
}
76+
}
77+
}
78+
}

‎src/ThunderDesign.Net-PCL.Threading.Shared/Objects/ThreadObject.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ThunderDesign.Net.Threading.Objects
22
{
3-
public class ThreadObject
3+
public abstract class ThreadObject
44
{
55
#region variables
66
protected readonly object _Locker = new object();

‎src/ThunderDesign.Net-PCL.Threading.Shared/ThunderDesign.Net-PCL.Threading.Shared.csproj‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net461;net6.0;net8.0;net10.0</TargetFrameworks>
5-
<RootNamespace>ThunderDesign.Net.Threading</RootNamespace>
4+
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net6.0;net8.0;net9.0;net10.0</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<RootNamespace>ThunderDesign.Net.Threading</RootNamespace>
68
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
79
<IncludeBuildOutput>true</IncludeBuildOutput>
810
<IncludeContentInPack>true</IncludeContentInPack>
@@ -11,6 +13,10 @@
1113
<Description>Threading interfaces and utilities for ThunderDesign cross-platform libraries.</Description>
1214
</PropertyGroup>
1315

16+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' OR '$(TargetFramework)' == 'netstandard1.3' ">
17+
<NoWarn>$(NoWarn);1903</NoWarn>
18+
</PropertyGroup>
19+
1420
<ItemGroup>
1521
<None Include="**\*.config" Pack="true" PackagePath="contentFiles\any\any\" />
1622
</ItemGroup>

0 commit comments

Comments
 (0)