我想将树序列化为人类可读的文本格式(所需的存储空间越少越好)。我想在不实现 XmlSerializer 类所要求的无参数构造函数和公共设置器的情况下实现这一点。实现这一目标的标准方法是什么?
我的模型看起来像这样:
public interface ISpecification<T>
{ //some stuff here }
// The tree will have some nodes like this
public abstract class CompositeSpecificationBase<T>
{
public ISpecification<T> Left { get; private set; }
public ISpecification<T> Right { get; private set; }
protected CompositeSpecificationBase(ISpecification<T> left, ISpecification<T> right)
{
Left = left;
Right = right;
}
}
public class AndSpecification<T> : CompositeSpecificationBase<T>, ISpecification<T>
{
public AndSpecification(ISpecification<T> left, ISpecification<T> right)
: base(left, right)
{}
// some stuff here
}
// At least one more implementation of CompositeSpecificationBase...
// There will be many leaf types like this
public class ExampleSpec : ISpecification<SomeEntity>
{
public int SomeProperty {get; private set;}
public ExampleSpec (int someProperty)
{
SomeProperty = someProperty;
}
}