清理引用,将NavigatorServices更改为使用Message来实现导航的切换
This commit is contained in:
@@ -2,10 +2,19 @@
|
||||
|
||||
namespace PMSWPF.Extensions;
|
||||
|
||||
class EnumBindingSourceExtension : MarkupExtension
|
||||
internal class EnumBindingSourceExtension : MarkupExtension
|
||||
{
|
||||
private Type? _enumType;
|
||||
|
||||
public EnumBindingSourceExtension()
|
||||
{
|
||||
}
|
||||
|
||||
public EnumBindingSourceExtension(Type enumType)
|
||||
{
|
||||
EnumType = enumType;
|
||||
}
|
||||
|
||||
public Type? EnumType
|
||||
{
|
||||
get => _enumType;
|
||||
@@ -15,7 +24,7 @@ class EnumBindingSourceExtension : MarkupExtension
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
Type enumType = Nullable.GetUnderlyingType(value) ?? value;
|
||||
var enumType = Nullable.GetUnderlyingType(value) ?? value;
|
||||
if (!enumType.IsEnum)
|
||||
throw new ArgumentException("Type must be for an Enum.");
|
||||
}
|
||||
@@ -25,13 +34,6 @@ class EnumBindingSourceExtension : MarkupExtension
|
||||
}
|
||||
}
|
||||
|
||||
public EnumBindingSourceExtension() { }
|
||||
|
||||
public EnumBindingSourceExtension(Type enumType)
|
||||
{
|
||||
EnumType = enumType;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (_enumType == null)
|
||||
|
||||
@@ -1,52 +1,53 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace PMSWPF.Extensions;
|
||||
namespace PMSWPF.Extensions;
|
||||
|
||||
public static class ObjectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象转换,将source对象上的所有属性的值,都转换到target对象上
|
||||
/// 对象转换,将source对象上的所有属性的值,都转换到target对象上
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static void CopyTo<T>(this Object source ,T target)
|
||||
public static void CopyTo<T>(this object source, T target)
|
||||
{
|
||||
var sourceType = source.GetType();
|
||||
var targetType = target.GetType();
|
||||
var sourceProperties = sourceType.GetProperties();
|
||||
foreach (PropertyInfo sourceProperty in sourceProperties)
|
||||
{
|
||||
PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
|
||||
if (targetProperty!= null && targetProperty.CanWrite && sourceProperty.CanRead && targetProperty.PropertyType == sourceProperty.PropertyType)
|
||||
{
|
||||
object value = sourceProperty.GetValue(source, null);
|
||||
targetProperty.SetValue(target, value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个泛型对象,将source对象上的所有属性的值,都转换到新创建对象上
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static T NewTo<T>(this Object source ) where T : new()
|
||||
{
|
||||
T target = new T();
|
||||
var sourceType = source.GetType();
|
||||
var targetType = target.GetType();
|
||||
var sourceProperties = sourceType.GetProperties();
|
||||
foreach (PropertyInfo sourceProperty in sourceProperties)
|
||||
foreach (var sourceProperty in sourceProperties)
|
||||
{
|
||||
PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
|
||||
if (targetProperty!= null && targetProperty.CanWrite && sourceProperty.CanRead && targetProperty.PropertyType == sourceProperty.PropertyType)
|
||||
var targetProperty = targetType.GetProperty(sourceProperty.Name);
|
||||
if (targetProperty != null && targetProperty.CanWrite && sourceProperty.CanRead &&
|
||||
targetProperty.PropertyType == sourceProperty.PropertyType)
|
||||
{
|
||||
object value = sourceProperty.GetValue(source, null);
|
||||
var value = sourceProperty.GetValue(source, null);
|
||||
targetProperty.SetValue(target, value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个泛型对象,将source对象上的所有属性的值,都转换到新创建对象上
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static T NewTo<T>(this object source) where T : new()
|
||||
{
|
||||
var target = new T();
|
||||
var sourceType = source.GetType();
|
||||
var targetType = target.GetType();
|
||||
var sourceProperties = sourceType.GetProperties();
|
||||
foreach (var sourceProperty in sourceProperties)
|
||||
{
|
||||
var targetProperty = targetType.GetProperty(sourceProperty.Name);
|
||||
if (targetProperty != null && targetProperty.CanWrite && sourceProperty.CanRead &&
|
||||
targetProperty.PropertyType == sourceProperty.PropertyType)
|
||||
{
|
||||
var value = sourceProperty.GetValue(source, null);
|
||||
targetProperty.SetValue(target, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
public static class TaskExtensions
|
||||
{
|
||||
|
||||
public static async Task Await(this Task task,Action<Exception> onError=null,Action onComplete=null)
|
||||
public static async Task Await(this Task task, Action<Exception> onError = null, Action onComplete = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -15,5 +14,4 @@ public static class TaskExtensions
|
||||
onError?.Invoke(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user