C#: Dynamic parse from System.Type

前端 未结 6 1262
没有蜡笔的小新
没有蜡笔的小新 2020-12-23 01:59

I have a Type, a String and an Object.

Is there some way I can call the parse method or convert for that type on the string dynamically?

Basically how do I r

6条回答
  •  攒了一身酷
    2020-12-23 02:24

    It's technically impossible to look at a string, and know for certain which type it represents.

    So, for any generic approach, you'll need at least:

    1. the string to be parsed
    2. the type used for parsing.

    Take a look at the static Convert.ChangeType() method.

提交回复
热议问题