有关反射struct方法的一点问题! 本帖最后由 ares128 于 2009-12-31 15:13:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把setvalue方法做成接口中的方法,然后通过接口进行类型转换和调用,可以避免拆箱操作。不会产生新的副本 object obj = this;mi.SetValue(obj, value, null); object obj = this; mi.SetValue(obj, value, null); this = (Matrix)obj;这样不知道行不行的 这样是不是太麻烦了 难点微软没有考虑过struct 的反射问题么 楼主我有个简单的方法。你可以试一试了。呵呵。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; } }} WPF 窗体实现拉伸,页头用什么控件实现双击最大化和还原? 如何使日期默认不为1900-1-1 0:00:00 帮我看一下 邮件收的问题 菜鸟求教个问题 关于二维条形码开发,急! datagridview行数的统计 这个问题不解决,今天肯定要通宵了,有高手进来帮忙吗? 数据库主键的值问题 如何获得子窗体的一个控件的Click句柄???谢谢 结束线程?????? 怎样按行分割txt文件,并且生成的文件名带序号 求C#控件!
object obj = this;
mi.SetValue(obj, value, null);
mi.SetValue(obj, value, null);
this = (Matrix)obj;这样不知道行不行的
这样是不是太麻烦了 难点微软没有考虑过struct 的反射问题么
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;
}
}
}