-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2279 from DGP-Studio/develop
- Loading branch information
Showing
162 changed files
with
1,419 additions
and
1,296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/ImmutableCollectionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Immutable; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Snap.Hutao.Test.BaseClassLibrary; | ||
|
||
[TestClass] | ||
public class ImmutableCollectionTest | ||
{ | ||
[TestMethod] | ||
public void ImmutableArrayUnsafeRefWrite() | ||
{ | ||
ImmutableArray<int> array = [1, 2, 3, 4, 5, 6, 7]; | ||
Unsafe.AsRef(in array.AsSpan()[3]) = 8; | ||
Assert.AreEqual(8, array[3]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md | ||
M:System.Collections.Generic.List`1.ForEach(System.Action{`0}) | ||
M:Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync | ||
M:Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync(Microsoft.UI.Xaml.Controls.ContentDialogPlacement) | ||
M:Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync(Microsoft.UI.Xaml.Controls.ContentDialogPlacement) | ||
P:Microsoft.UI.Xaml.UIElement.RasterizationScale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/Snap.Hutao/Snap.Hutao/Core/ComponentModel/AsyncDisposableObservableBox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Snap.Hutao.Core.ComponentModel; | ||
|
||
internal sealed class AsyncDisposableObservableBox<TNotifyPropertyChanged, T> : IAsyncDisposableObservableBox<T> | ||
where TNotifyPropertyChanged : INotifyPropertyChanged | ||
where T : class?, IDisposable? | ||
{ | ||
private readonly TNotifyPropertyChanged source; | ||
private readonly Func<TNotifyPropertyChanged, T> valueFactory; | ||
private readonly string propertyName; | ||
|
||
private volatile CancellationTokenSource? cts; | ||
private volatile TaskCompletionSource? tcs; | ||
private bool isDisposed; | ||
|
||
public AsyncDisposableObservableBox(T value, TNotifyPropertyChanged source, string propertyName, Func<TNotifyPropertyChanged, T> valueFactory) | ||
{ | ||
Value = value; | ||
this.source = source; | ||
this.propertyName = propertyName; | ||
this.valueFactory = valueFactory; | ||
source.PropertyChanged += OnPropertyChanged; | ||
} | ||
|
||
public T Value { get; private set; } | ||
|
||
public AsyncLock SyncRoot { get; } = new(); | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (isDisposed) | ||
{ | ||
return; | ||
} | ||
|
||
using (await SyncRoot.LockAsync().ConfigureAwait(false)) | ||
{ | ||
if (isDisposed) | ||
{ | ||
return; | ||
} | ||
|
||
isDisposed = true; | ||
source.PropertyChanged -= OnPropertyChanged; | ||
if (cts is not null) | ||
{ | ||
await cts.CancelAsync().ConfigureAwait(false); | ||
|
||
if (tcs is not null) | ||
{ | ||
await tcs.Task.ConfigureAwait(false); | ||
} | ||
|
||
cts.Dispose(); | ||
} | ||
|
||
Value?.Dispose(); | ||
Value = default!; | ||
} | ||
} | ||
|
||
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs args) | ||
{ | ||
_ = OnPropertyChangedAsync(args); | ||
} | ||
|
||
[SuppressMessage("", "SH003")] | ||
private async Task OnPropertyChangedAsync(PropertyChangedEventArgs args) | ||
{ | ||
if (cts is not null) | ||
{ | ||
await cts.CancelAsync().ConfigureAwait(false); | ||
|
||
if (tcs is not null) | ||
{ | ||
await tcs.Task.ConfigureAwait(false); | ||
} | ||
|
||
// Must await currentTcs before dispose currentCts. | ||
cts.Dispose(); | ||
} | ||
|
||
// Capture current tcs reference. | ||
TaskCompletionSource currentTcs = new(); | ||
tcs = currentTcs; | ||
cts = new(); | ||
|
||
try | ||
{ | ||
// Capture current cts reference. | ||
CancellationToken token = cts.Token; | ||
using (await SyncRoot.LockAsync().ConfigureAwait(false)) | ||
{ | ||
if (token.IsCancellationRequested) | ||
{ | ||
return; | ||
} | ||
|
||
if (args.PropertyName != propertyName) | ||
{ | ||
return; | ||
} | ||
|
||
Value?.Dispose(); | ||
Value = valueFactory(source); | ||
} | ||
} | ||
finally | ||
{ | ||
currentTcs.TrySetResult(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Snap.Hutao/Snap.Hutao/Core/ComponentModel/IAsyncDisposableObservableBox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Snap.Hutao.Core.ComponentModel; | ||
|
||
internal interface IAsyncDisposableObservableBox<out T> : IAsyncDisposable | ||
where T : class?, IDisposable? | ||
{ | ||
T Value { get; } | ||
|
||
AsyncLock SyncRoot { get; } | ||
} |
40 changes: 0 additions & 40 deletions
40
src/Snap.Hutao/Snap.Hutao/Core/ComponentModel/NotifyPropertyChangedBox.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.