本文介绍了如何将字符串转换为任何类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串转换为泛型
我有这个: pre $ string inputValue = myTxtBox.Text; PropertyInfo propInfo = typeof(MyClass).GetProperty(myPropertyName); 类型propType = propInfo.PropertyType; 对象propValue = ?????
我想将'inputString'转换为该属性的类型,以检查它是否兼容我该怎么做?
tks
解决方案使用System.ComponentModel; TypeConverter typeConverter = TypeDescriptor.GetConverter(propType); object propValue = typeConverter.ConvertFromString(inputValue);
I want to convert a string to a generic type
I have this:
string inputValue = myTxtBox.Text; PropertyInfo propInfo = typeof(MyClass).GetProperty(myPropertyName); Type propType = propInfo.PropertyType; object propValue = ?????I want to convert 'inputString' to the type of that property, to check if it's compatible how can I do that?
tks
解决方案 using System.ComponentModel; TypeConverter typeConverter = TypeDescriptor.GetConverter(propType); object propValue = typeConverter.ConvertFromString(inputValue);
更多推荐
如何将字符串转换为任何类型
发布评论