-
-
Notifications
You must be signed in to change notification settings - Fork 331
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 #810 from LykosAI/main
v2.11.6
- Loading branch information
Showing
15 changed files
with
276 additions
and
162 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
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
75 changes: 75 additions & 0 deletions
75
StabilityMatrix.Avalonia/ViewModels/Base/DisposableLoadableViewModelBase.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,75 @@ | ||
using System; | ||
using System.Reactive.Disposables; | ||
using JetBrains.Annotations; | ||
|
||
namespace StabilityMatrix.Avalonia.ViewModels.Base; | ||
|
||
public abstract class DisposableLoadableViewModelBase : LoadableViewModelBase, IDisposable | ||
{ | ||
private readonly CompositeDisposable instanceDisposables = new(); | ||
|
||
/// <summary> | ||
/// Adds a disposable to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposable">The disposable to add.</param> | ||
protected void AddDisposable([HandlesResourceDisposal] IDisposable disposable) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
|
||
/// <summary> | ||
/// Adds disposables to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposables">The disposables to add.</param> | ||
protected void AddDisposable([HandlesResourceDisposal] params IDisposable[] disposables) | ||
{ | ||
foreach (var disposable in disposables) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Adds a disposable to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposable">The disposable to add.</param> | ||
/// <typeparam name="T">The type of the disposable.</typeparam> | ||
/// <returns>The disposable that was added.</returns> | ||
protected T AddDisposable<T>([HandlesResourceDisposal] T disposable) | ||
where T : IDisposable | ||
{ | ||
instanceDisposables.Add(disposable); | ||
return disposable; | ||
} | ||
|
||
/// <summary> | ||
/// Adds disposables to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposables">The disposables to add.</param> | ||
/// <typeparam name="T">The type of the disposables.</typeparam> | ||
/// <returns>The disposables that were added.</returns> | ||
protected T[] AddDisposable<T>([HandlesResourceDisposal] params T[] disposables) | ||
where T : IDisposable | ||
{ | ||
foreach (var disposable in disposables) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
|
||
return disposables; | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
instanceDisposables.Dispose(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
StabilityMatrix.Avalonia/ViewModels/Base/DisposableViewModelBase.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,75 @@ | ||
using System; | ||
using System.Reactive.Disposables; | ||
using JetBrains.Annotations; | ||
|
||
namespace StabilityMatrix.Avalonia.ViewModels.Base; | ||
|
||
public abstract class DisposableViewModelBase : ViewModelBase, IDisposable | ||
{ | ||
private readonly CompositeDisposable instanceDisposables = new(); | ||
|
||
/// <summary> | ||
/// Adds a disposable to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposable">The disposable to add.</param> | ||
protected void AddDisposable([HandlesResourceDisposal] IDisposable disposable) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
|
||
/// <summary> | ||
/// Adds disposables to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposables">The disposables to add.</param> | ||
protected void AddDisposable([HandlesResourceDisposal] params IDisposable[] disposables) | ||
{ | ||
foreach (var disposable in disposables) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Adds a disposable to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposable">The disposable to add.</param> | ||
/// <typeparam name="T">The type of the disposable.</typeparam> | ||
/// <returns>The disposable that was added.</returns> | ||
protected T AddDisposable<T>([HandlesResourceDisposal] T disposable) | ||
where T : IDisposable | ||
{ | ||
instanceDisposables.Add(disposable); | ||
return disposable; | ||
} | ||
|
||
/// <summary> | ||
/// Adds disposables to be disposed when this view model is disposed. | ||
/// </summary> | ||
/// <param name="disposables">The disposables to add.</param> | ||
/// <typeparam name="T">The type of the disposables.</typeparam> | ||
/// <returns>The disposables that were added.</returns> | ||
protected T[] AddDisposable<T>([HandlesResourceDisposal] params T[] disposables) | ||
where T : IDisposable | ||
{ | ||
foreach (var disposable in disposables) | ||
{ | ||
instanceDisposables.Add(disposable); | ||
} | ||
|
||
return disposables; | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
instanceDisposables.Dispose(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
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
Oops, something went wrong.