mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-20 16:21:46 +08:00
28 lines
810 B
C#
28 lines
810 B
C#
using System.Application.UI.ViewModels;
|
|
|
|
namespace System.Application
|
|
{
|
|
public static class ViewModelExtensions
|
|
{
|
|
/// <summary>
|
|
/// <see cref="IDisposable"/> 将对象添加到<see cref="ViewModelBase"/> 的<see cref="ViewModelBase.CompositeDisposable"/>中
|
|
/// </summary>
|
|
public static T AddTo<T>(this T disposable, ViewModelBase vm) where T : IDisposable
|
|
{
|
|
if (vm == null)
|
|
{
|
|
disposable.Dispose();
|
|
return disposable;
|
|
}
|
|
|
|
if (vm.CompositeDisposable == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(ViewModelBase.CompositeDisposable));
|
|
}
|
|
|
|
vm.CompositeDisposable.Add(disposable);
|
|
return disposable;
|
|
}
|
|
}
|
|
}
|