如何从字符串转换成任何类型的对象? [英] How to convert from string to object of any type?

查看:102
本文介绍了如何从字符串转换成任何类型的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从包含的数据到使用反射传递某种类型的对象的字符串转换。我有一个包含任何类型的属性不是可序列化对象,我想将数据加载到该对象。

I need to convert from a string that contains data to an object of some type that is passed using reflection. I have a not-serializable object that contains properties of any type, and I want to load data to that object.

例如,该对象有一个属性,颜色BGCOLOR 。当我尝试设置红的价值财产,我得到的转换是不可能从字符串颜色。我需要一般的code。

For example, that object has a property, Color BgColor. When I am trying to set "Red" value to that property, I get that conversion is not possible from string to Color. I need general code.

推荐答案

考虑广义类型转换

这篇关于如何从字符串转换成任何类型的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆