I\'m trying to serialize the following class:
[Serializable()]
public class BindingNode : IEnumerable
{
public BindingNode()
{
This would be your problem: BindingNode : IEnumerable
This would be recursive and you would encouter a StackOverFlowException
. Typically people create two classes.
The single class:
public class BindingNode
{
/*..*/
}
The colleciton class:
public class BindingNodeCollection : IEnumerable
{
/*..*/
}
This approach usually also increases cohesion and satisfies the Single Responsiblity Principle (SRP). It does this by seperating concerts. Collection logic is placed in the collection class and then the original class does what it was entended to do.