As defined your SkeletonVectorCollection
is recursive as your this[JointType]
implementation has no backing property and is trying to store to itself. If you don't need/want to inherit from Skeleton
you can switch to a Dictionary
and get the implementation for free.
public class SkeletonVectorCollection : Dictionary<JointType, BoneVector>
{
public SkeletonVectorCollection(Skeleton input)
{
foreach (BoneOrientation orientation in input.BoneOrientations)
{
this[orientation.EndJoint] = new BoneVector(input.Joints[orientation.StartJoint], input.Joints[orientation.EndJoint]);
}
}
}
If you must inherit from Skeleton
then you need to provide an implementation with some sort of storage behind it here is a version that uses a dictionary internally.
public class SkeletonVectorCollection : Skeleton
{
private Dictionary<JointType, BoneVector> _boneVectors = new Dictionary<JointType, BoneVector>();
public SkeletonVectorCollection(Skeleton input)
{
foreach (BoneOrientation orientation in input.BoneOrientations)
{
this[orientation.EndJoint] = new BoneVector(input.Joints[orientation.StartJoint], input.Joints[orientation.EndJoint]);
}
}
public BoneVector this[JointType jointType]
{
get
{
return _boneVectors[jointType];
}
protected set
{
_boneVectors[jointType] = value;
}
}
}