如果我有这个字符串列表:
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#中有可能吗?
提前致谢.
我认为你最好使用Object Serialization/Deserialization而不是创建一个基本上需要做同样事情的自定义方法
更多信息:
http://msdn.microsoft.com/en-us/library/ms233843.aspx
| 归档时间: |
|
| 查看次数: |
130 次 |
| 最近记录: |