本帖最后由 ares128 于 2009-12-31 15:13:04 编辑

解决方案 »

  1.   

    把setvalue方法做成接口中的方法,然后通过接口进行类型转换和调用,可以避免拆箱操作。不会产生新的副本
      

  2.   


    object obj = this;
    mi.SetValue(obj, value, null);
      

  3.   

    object obj = this;
                    mi.SetValue(obj, value, null);
                    this = (Matrix)obj;这样不知道行不行的
      

  4.   


    这样是不是太麻烦了 难点微软没有考虑过struct 的反射问题么
      

  5.   

    楼主我有个简单的方法。你可以试一试了。呵呵。
    public struct Matrix
    {
        public float M00
        {
            get;
            set;
        }
        public float M01
        {
            get;
            set;
        }
        public float M02
        {
            get;
            set;
        }
        public float M03
        {
            get;
            set;
        }    public float M10
        {
            get;
            set;
        }
        public float M11
        {
            get;
            set;
        }
        public float M12
        {
            get;
            set;
        }
        public float M13
        {
            get;
            set;
        }    public float M20
        {
            get;
            set;
        }
        public float M21
        {
            get;
            set;
        }
        public float M22
        {
            get;
            set;
        }
        public float M23
        {
            get;
            set;
        }    public float M30
        {
            get;
            set;
        }
        public float M31
        {
            get;
            set;
        }
        public float M32
        {
            get;
            set;
        }
        public float M33
        {
            get;
            set;
        }    public float this[int i, int j]
        {
            get
            {
                if (i < 0 || i >= 3)
                {
                    throw new ArgumentOutOfRangeException();
                }
                if (j < 0 || j >= 3)
                {
                    throw new ArgumentOutOfRangeException();
                }
                return (float)this.GetType().GetProperty("M" + i.ToString() + j.ToString()).GetValue(this, null);
            }
            set
            {            if (i < 0 || i >= 3)
                {
                    throw new ArgumentOutOfRangeException();
                }
                if (j < 0 || j >= 3)
                {
                    throw new ArgumentOutOfRangeException();
                }            var mi = this.GetType().GetProperty("M" + i.ToString() + j.ToString());
                object m = this;
                mi.SetValue(m, value, null);
                this = (Matrix)m;
            }
        }
    }