有一个对象的类型,以及转化为object的对象,如何得到真正类型的对象例如Point point = new Point(10,10);
Type type = typeof(Point);
object obj = new object();
obj = (object)point;
 
能取得的只有type和obj,能不能得到Point的实例呢

解决方案 »

  1.   


    object point = new Point(10,20);
    string str=point.GetType().GetProperty("X").GetValue(point, null).ToString();
      

  2.   


                Point point = new Point(10, 10);
                Type type = typeof(Point);
                object obj = new object();
                obj = (object)point;
                object o = Activator.CreateInstance(obj.GetType(), new object[] { 10, 10 });
      

  3.   

    话说这个得出来也还是一个object啊
      

  4.   


    是object啊,但它就是Point类的一个实例啊
    你想要达到什么目的?
      

  5.   

    没看懂你要干嘛。用得着反射么,装箱而已吧
    [code=C#] Point point = new Point(10, 10);
                object obj = (object)point;
                Point p = (Point)obj;
    code]
      

  6.   

    PropertyInfo.SetValue方法直接给object的属性它自己会识别是吧,不用我给特定的类型吗
      

  7.   

    大哥,我只是假设一个Point,你别当真啊,所有的类都可以取Type的好不
      

  8.   

    不用,SetValue第一个参数就是要设置值的对象
      

  9.   

    你是想根据TYPE创建实例?
    Activator.CreateInstance(typeof(Point));
    PS:你现在是想通过反射来实现深拷贝么?你先把思路写一下。