Files

38 lines
980 B
C#
Raw Permalink Normal View History

using Cowain.Bake.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Cowain.Bake.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));
}
}
}