如何将此字符串列表强制转换为对象

oli*_*dev 1 c#

如果我有这个字符串列表:

string myObjectString = "MyObject, SetWidth, int, 10, 0, 1";
Run Code Online (Sandbox Code Playgroud)

其中:

- MyObject: the object class
- SetWidth: the property of the object
- int: type of the SetWidth is int
- 10: default value
- 0: object order
- 1: property order
Run Code Online (Sandbox Code Playgroud)

那么我该如何构造这样的对象:

[ObjectOrder(0)]
public class MyObject:
{
   private int _SetWidth = 10;

   [PropertyOrder(1)]
   public int SetWidth
   {
      set{_SetWidth=value;}
      get{return _SetWidth;}
   }
}
Run Code Online (Sandbox Code Playgroud)

所以,我想要这样的东西:

Object myObject = ConstructAnObject(myObjectString);
Run Code Online (Sandbox Code Playgroud)

myObject是一个实例MyObject.可能在C#中有可能吗?

提前致谢.

Mas*_*uso 5

我认为你最好使用Object Serialization/Deserialization而不是创建一个基本上需要做同样事情的自定义方法

更多信息:

http://msdn.microsoft.com/en-us/library/ms233843.aspx