添加项目文件。

This commit is contained in:
czj
2026-06-05 10:57:09 +08:00
parent f29671b374
commit d960cb5912
166 changed files with 15996 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using UIShare.UIViewModel;
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace UIShare.Converters
{
public class FilteredParametersConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length < 2 || values[0] == null || values[1] == null)
return null;
Type currentParamType = values[0] as Type;
var allParameters = values[1] as System.Collections.IEnumerable;
if (currentParamType == null || allParameters == null)
return allParameters;
// 过滤出类型匹配的参数
return allParameters.Cast<ParameterModel>()
.Where(p => IsTypeMatch(currentParamType, p.Type))
.ToList();
}
private bool IsTypeMatch(Type currentType, Type candidateType)
{
if (candidateType == null) return false;
// 如果候选参数类型是 object则匹配所有类型
if (candidateType == typeof(object)) return true;
// 如果类型完全相同,则匹配
if (candidateType == currentType) return true;
// 处理数值类型的兼容性
if (IsNumericType(currentType) && IsNumericType(candidateType))
return true;
return false;
}
private bool IsNumericType(Type type)
{
if (type == null) return false;
switch (Type.GetTypeCode(type))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}