This commit is contained in:
Hakoyu 2023-12-16 01:11:52 +08:00
parent 1e7b3751ac
commit c174ab1b13
2 changed files with 72 additions and 0 deletions

View File

@ -30,4 +30,54 @@ public class PropertyChangedXEventArgs : EventArgs
OldValue = oldValue;
NewValue = newValue;
}
#if NETCOREAPP2_0_OR_GREATER
/// <summary>
/// 获取值
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <returns>(旧值, 新值)</returns>
public (T oldValue, T newValye) GetValue<T>()
{
return ((T)OldValue!, (T)NewValue!)!;
}
#else
/// <summary>
/// 获取值
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <returns>(旧值, 新值)</returns>
public ValueInfo<T> GetValue<T>()
{
return new((T)OldValue!, (T)NewValue!)!;
}
#endif
}
#if !NETCOREAPP2_0_OR_GREATER
/// <summary>
/// 值信息
/// </summary>
/// <typeparam name="T">值类型</typeparam>
public struct ValueInfo<T>
{
/// <summary>
/// 旧值
/// </summary>
public T OldValue { get; set; }
/// <summary>
/// 新值
/// </summary>
public T NewValue { get; set; }
/// <inheritdoc/>
/// <param name="oldValue">旧值</param>
/// <param name="newValue">新值</param>
public ValueInfo(T oldValue, T newValue)
{
OldValue = oldValue;
NewValue = newValue;
}
}
#endif

View File

@ -32,4 +32,26 @@ public class PropertyChangingXEventArgs : CancelEventArgs
OldValue = oldValue;
NewValue = newValue;
}
#if NETCOREAPP2_0_OR_GREATER
/// <summary>
/// 获取值
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <returns>(旧值, 新值)</returns>
public (T oldValue, T newValye) GetValue<T>()
{
return ((T)OldValue!, (T)NewValue!)!;
}
#else
/// <summary>
/// 获取值
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <returns>(旧值, 新值)</returns>
public ValueInfo<T> GetValue<T>()
{
return new((T)OldValue!, (T)NewValue!)!;
}
#endif
}