c# 将字符串转换为指定类型的值
2024-09-01 00:49:07
private object GetValueByProperty(string key, string value, ref Type typeValue)
{
Type t = typeof(T);
var property = t.GetProperty(key);
if (property == null)
{
return value;
} Type pt = property.PropertyType.IsGenericType && !property.PropertyType.IsGenericTypeDefinition
? property.PropertyType.GetGenericArguments()[] : property.PropertyType;
object obj = Convert.ChangeType(value, pt);
if (property.PropertyType.IsGenericType && !property.PropertyType.IsGenericTypeDefinition)
{
typeValue = property.PropertyType;
}
else
{
typeValue = pt;
}
return obj;
}
key:属性名称
value:字符串类型的值
typevalue:属性类型
返回:转换后的值
最新文章
- python基础_制作多级菜单_(运用:字典_列表_元组等知识)
- java读取邮件
- web前端开发工程师,你了解吗?
- 爬虫技术 -- 进阶学习(八)模拟简单浏览器(附c#代码)
- JS判断对象类型
- 经常遇到Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be e
- HttpClient使用详解(转)
- ansible中文手册-基础模块使用
- mysql 主从同步 Last_SQL_Error
- jquery 动态添加下拉框 需要增加 煊染 selectmenu(";refresh";);
- html 5的localstorag
- Vim C/C++的一键编译
- [转]使用wireshark分析TCP/IP协议中TCP包头的格式
- MYSQL insert
- Python 基于TK 文本编辑器
- 理解容器之间的连通性 - 每天5分钟玩转 Docker 容器技术(34)
- SUSE12SP3-Mycat(2)Schema.xml配置详解
- 跨域两种解决方案CORS以及JSONP
- ERRORS !MySQL 和 Javaweb 的报错合集
- Pycharm Debug调试心得
热门文章
- HDU 1789 Doing Homework again(馋)
- 使用nodejs 来压缩整个目录
- JVM参数调优:Eclipse启动实践
- Java获取URL对应的资源
- C# 实现生成带二维码的专属微信公众号推广海报
- .NET开发人员的瓶颈和职业发展
- JDK源代码学习系列03----StringBuffer+StringBuilder
- 在.net core 的webapi项目中将对象序列化成json
- 第一泰泽(Tizen)智能手机发布在俄罗斯
- 嵌入式开发(*(volatile unsigned long *)) 认识