属性的 setter 和 getter 被实现为方法(get_X 和 set_X)。
在 Projection 的 setter 中写入Projection = value
会导致对set_Projection()
from within的递归调用set_Projection()
。(同样适用于get_Projection()
。)
由于调用周围没有条件,因此递归是无限的。
至于public T PropA { get; set; }
,它是以下的糖语法:
private T _PropA;
public T PropA
{
get
{
return _PropA;
}
set
{
_PropA = value;
}
}
你应该做的是:
private Matrix _projection;
public Matrix Projection
{
get
{
return _projection;
}
protected set
{
// Make sure that Matrix is a structure and not a class
// override == and != operators in Matrix (and Equals and GetHashCode)
// If Matrix has to be a class, use !_project.Equals(value) instead
// Consider using an inaccurate compare here instead of == or Equals
// so that calculation inaccuracies won't require recalculation
if (_projection != value)
{
_projection = value;
generateFrustum();
}
}
}