Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private static void GenerateUnifiedPropertyClass(
GenerateRegularProperties(source, propertyFields, classSymbol, compilation);

source.AppendLine("}");
source.AppendLine("#nullable restore");
if (!string.IsNullOrEmpty(classSymbol.ContainingNamespace?.ToDisplayString()))
source.AppendLine("}");

Expand Down Expand Up @@ -512,7 +513,7 @@ private static void GenerateInfrastructureMembers(
if (bindableFields.Count > 0 && !implementsINotify &&
!PropertyGeneratorHelpers.EventExists(classSymbol, "PropertyChanged", propertyChangedEventType))
{
source.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
source.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;");
}

// Add _Locker if needed (only for non-static fields)
Expand Down Expand Up @@ -1096,6 +1097,7 @@ public static T GetStaticProperty<T>(
{
if (lockObj != null)
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);

return backingStore;
}
finally
Expand Down Expand Up @@ -1128,21 +1130,23 @@ public static bool SetStaticProperty<T>(
{
if (lockObj != null)
System.Threading.Monitor.Enter(lockObj, ref lockWasTaken);

#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
if (ThunderDesign.Net_PCL.ToolBox.Helpers.EqualityHelper.Equality<T>(ref backingStore, value))
return false;
#else
if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(backingStore, value))
{
return false;
}
else
{
backingStore = value;
return true;
}
#endif
backingStore = value;
}
finally
{
if (lockWasTaken)
System.Threading.Monitor.Exit(lockObj!);
}

return true;
}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public sealed class BindablePropertyAttribute : Attribute
{
public bool ThreadSafe { get; }
public bool Notify { get; }
public string[] AlsoNotify { get; }
public string CallMethodAfterSet { get; }
public string[]? AlsoNotify { get; }
public string? CallMethodAfterSet { get; }
public AccessorAccessibility Getter { get; }
public AccessorAccessibility Setter { get; }

public BindablePropertyAttribute(
bool threadSafe = true,
bool notify = true,
string[] alsoNotify = null,
string callMethodAfterSet = null,
string[]? alsoNotify = null,
string? callMethodAfterSet = null,
AccessorAccessibility getter = AccessorAccessibility.Public,
AccessorAccessibility setter = AccessorAccessibility.Public)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace ThunderDesign.Net.Threading.Attributes
public sealed class PropertyAttribute : Attribute
{
public bool ThreadSafe { get; }
public string CallMethodAfterSet { get; }
public string? CallMethodAfterSet { get; }
public AccessorAccessibility Getter { get; }
public AccessorAccessibility Setter { get; }

public PropertyAttribute(
bool threadSafe = true,
string callMethodAfterSet = null,
string? callMethodAfterSet = null,
AccessorAccessibility getter = AccessorAccessibility.Public,
AccessorAccessibility setter = AccessorAccessibility.Public)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static bool SetProperty<T>(
this IBindableObject sender,
ref T backingStore,
T value,
object lockObj,
object? lockObj,
bool notifyPropertyChanged,
[CallerMemberName] string propertyName = "")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class INotifyPropertyChangedExtension
{
public static void NotifyPropertyChanged(
this INotifyPropertyChanged sender,
PropertyChangedEventHandler handler,
PropertyChangedEventHandler? handler,
[CallerMemberName] string propertyName = "",
bool notifyAndWait = true)
{
Expand All @@ -18,7 +18,7 @@ public static void NotifyPropertyChanged(

public static void NotifyPropertyChanged(
this INotifyPropertyChanged sender,
PropertyChangedEventHandler handler,
PropertyChangedEventHandler? handler,
PropertyChangedEventArgs args,
bool notifyAndWait = true)
{
Expand All @@ -35,7 +35,7 @@ public static bool SetProperty<T>(
this INotifyPropertyChanged sender,
ref T backingStore,
T value,
PropertyChangedEventHandler propertyChangedEventHandler,
PropertyChangedEventHandler? propertyChangedEventHandler,
[CallerMemberName] string propertyName = "",
bool notifyAndWait = true)
{
Expand All @@ -46,8 +46,8 @@ public static bool SetProperty<T>(
this INotifyPropertyChanged sender,
ref T backingStore,
T value,
object lockObj,
PropertyChangedEventHandler propertyChangedEventHandler,
object? lockObj,
PropertyChangedEventHandler? propertyChangedEventHandler,
[CallerMemberName] string propertyName = "",
bool notifyAndWait = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ public static class ObjectExtention
public static T GetProperty<T>(
this object sender,
ref T backingStore,
object lockObj = null)
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);
System.Threading.Monitor.Exit(lockObj!);
}
}

public static bool SetProperty<T>(
this object sender,
ref T backingStore,
T value,
object lockObj = null)
object? lockObj = null)
{
bool lockWasTaken = false;
try
Expand All @@ -50,8 +51,9 @@ public static bool SetProperty<T>(
finally
{
if (lockWasTaken)
System.Threading.Monitor.Exit(lockObj);
System.Threading.Monitor.Exit(lockObj!);
}

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
catch { }
};

public static void RunAndForget(Action action, Action<Exception> handler = null)
public static void RunAndForget(Action action, Action<Exception>? handler = null)
{
if (action == null)
throw new ArgumentNullException(nameof(action));
Expand All @@ -28,7 +28,7 @@
else
{
task.ContinueWith(
t => handler(t.Exception.GetBaseException()),

Check warning on line 31 in src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 31 in src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 31 in src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 31 in src/ThunderDesign.Net-PCL.Threading.Shared/HelperClasses/ThreadHelper.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
TaskContinuationOptions.ExecuteSynchronously |
TaskContinuationOptions.OnlyOnFaulted);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using ThunderDesign.Net.Threading.Extentions;

namespace ThunderDesign.Net.Threading.Objects
{
public abstract class DisposableThreadObject : ThreadObject, IDisposable
{
private CancellationTokenSource? _disposingCtsCached = null;

protected readonly string ClassNameCashed;
private bool _disposed = false;

protected DisposableThreadObject()
{
ClassNameCashed = this.GetType().Name;
}

~DisposableThreadObject()
{
Dispose(disposing: false);
}

protected bool Disposed
{
get { return this.GetProperty(ref _disposed, _Locker); }
set { this.SetProperty(ref _disposed, value, _Locker); }
}

protected CancellationTokenSource DisposingCts => DisposingCtsCache ??= new CancellationTokenSource();

protected CancellationTokenSource? DisposingCtsCache
{
get { return this.GetProperty(ref _disposingCtsCached, _Locker); }
private set { this.SetProperty(ref _disposingCtsCached, value, _Locker); }
}

protected CancellationTokenSource LinkTokenSourceDisposing(CancellationToken cancellationToken)
{
return CancellationTokenSource.CreateLinkedTokenSource(DisposingCts.Token, cancellationToken);
}

protected void ThrowIfDisposed()
{
if (Disposed || DisposingCtsCache?.IsCancellationRequested == true)
throw new ObjectDisposedException(ClassNameCashed);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing, bool setDisposed = true)
{
if (!Disposed)
{
if (disposing)
{
// Dispose managed resources here
DisposingCtsCache?.Cancel();
DisposingCtsCache?.Dispose();
}

// Dispose unmanaged resources here

if (setDisposed)
{
Disposed = true;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ThunderDesign.Net.Threading.Objects
{
public class ThreadObject
public abstract class ThreadObject
{
#region variables
protected readonly object _Locker = new object();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net461;net6.0;net8.0;net10.0</TargetFrameworks>
<RootNamespace>ThunderDesign.Net.Threading</RootNamespace>
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net6.0;net8.0;net9.0;net10.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>ThunderDesign.Net.Threading</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeContentInPack>true</IncludeContentInPack>
Expand All @@ -11,6 +13,10 @@
<Description>Threading interfaces and utilities for ThunderDesign cross-platform libraries.</Description>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' OR '$(TargetFramework)' == 'netstandard1.3' ">
<NoWarn>$(NoWarn);1903</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Include="**\*.config" Pack="true" PackagePath="contentFiles\any\any\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.ObjectModel;
using ThunderDesign.Net.Threading.Collections;
using ThunderDesign.Net_PCL.Threading.UnitTests.Helpers;

namespace ThunderDesign.Net_PCL.Threading.UnitTests.Collections
{
public class CollectionThreadSafeApiParityTests
{
[Fact]
public void ApiParity_CollectionThreadSafe_CoversCollectionOfT()
{
ApiParityHelper.AssertWrapperCoversBaseApi(
typeof(CollectionThreadSafe<int>),
typeof(Collection<int>));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using ThunderDesign.Net.Threading.Collections;
using ThunderDesign.Net_PCL.Threading.UnitTests.Helpers;

namespace ThunderDesign.Net_PCL.Threading.UnitTests.Collections
{
public class DictionaryThreadSafeApiParityTests
{
[Fact]
public void ApiParity_DictionaryThreadSafe_CoversDictionaryOfTKeyTValue()
{
ApiParityHelper.AssertWrapperCoversBaseApi(
typeof(DictionaryThreadSafe<string, int>),
typeof(Dictionary<string, int>));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using ThunderDesign.Net.Threading.Collections;
using ThunderDesign.Net_PCL.Threading.UnitTests.Helpers;

namespace ThunderDesign.Net_PCL.Threading.UnitTests.Collections
{
public class HashSetThreadSafeApiParityTests
{
[Fact]
public void ApiParity_HashSetThreadSafe_CoversHashSetOfT()
{
ApiParityHelper.AssertWrapperCoversBaseApi(
typeof(HashSetThreadSafe<int>),
typeof(HashSet<int>));
}
}
}
Loading
Loading