优化参数获取

This commit is contained in:
智能大石头 2025-06-12 11:22:17 +08:00
parent 040e356f43
commit dfce86e800
1 changed files with 10 additions and 11 deletions

View File

@ -1,5 +1,4 @@
using System.Collections; using System.Collections;
using NewLife;
using NewLife.Collections; using NewLife.Collections;
using NewLife.Data; using NewLife.Data;
using NewLife.Reflection; using NewLife.Reflection;
@ -124,10 +123,10 @@ public partial class Parameter : Entity<Parameter>
#region #region
/// <summary>根据种类返回数据</summary> /// <summary>根据种类返回数据</summary>
/// <returns></returns> /// <returns></returns>
public Object GetValue() public Object? GetValue()
{ {
var str = Value; var str = Value?.Trim();
if (str.IsNullOrEmpty()) str = LongValue; if (str.IsNullOrEmpty()) str = LongValue?.Trim();
if (str.IsNullOrEmpty()) return null; if (str.IsNullOrEmpty()) return null;
switch (Kind) switch (Kind)
@ -240,11 +239,11 @@ public partial class Parameter : Entity<Parameter>
/// <returns></returns> /// <returns></returns>
public T[] GetList<T>() public T[] GetList<T>()
{ {
var str = Value; var str = Value?.Trim();
if (str.IsNullOrEmpty()) str = LongValue; if (str.IsNullOrEmpty()) str = LongValue?.Trim();
var arr = Value.Split(",", ";"); var arr = Value.Split(",", ";", "");
return arr.Select(e => e.ChangeType<T>()).ToArray(); return arr.Select(e => e.ChangeType<T>()!).ToArray();
} }
/// <summary>获取名值对</summary> /// <summary>获取名值对</summary>
@ -253,11 +252,11 @@ public partial class Parameter : Entity<Parameter>
/// <returns></returns> /// <returns></returns>
public IDictionary<TKey, TValue> GetHash<TKey, TValue>() public IDictionary<TKey, TValue> GetHash<TKey, TValue>()
{ {
var str = Value; var str = Value?.Trim();
if (str.IsNullOrEmpty()) str = LongValue; if (str.IsNullOrEmpty()) str = LongValue?.Trim();
var dic = Value.SplitAsDictionary("=", ","); var dic = Value.SplitAsDictionary("=", ",");
return dic.ToDictionary(e => e.Key.ChangeType<TKey>(), e => e.Value.ChangeType<TValue>()); return dic.ToDictionary(e => e.Key.ChangeType<TKey>()!, e => e.Value.ChangeType<TValue>()!);
} }
/// <summary>设置列表</summary> /// <summary>设置列表</summary>