Files
6098-5/Cowain.Preheat.Communication/GenericFun.cs
T
2026-05-28 22:11:13 +08:00

38 lines
986 B
C#

using Cowain.Preheat.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Cowain.Preheat.Communication
{
public class GenericFun
{
//public string GetVariableValue<T>(Expression<Func<T>> expr, List<TDeviceParam> devParms)
//{
// var memberExpr = (MemberExpression)expr.Body;
// foreach (var item in devParms)
// {
// if (memberExpr.Member.Name == item.Key)
// {
// return item.Value;
// }
// }
// return null;
//}
public T ConvertToType<T>(string value)
{
if (null == value)
{
return default(T);
}
// 使用Convert.ChangeType将字符串转换为泛型类型T
return (T)Convert.ChangeType(value, typeof(T));
}
}
}