首次提交:添加src文件夹代码
This commit is contained in:
37
Cowain.Bake.Communication/GenericFun.cs
Normal file
37
Cowain.Bake.Communication/GenericFun.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user