@@@code
public interface IDataBodyFormatterBase
{
object Deserialize(IByteBuffer reader, Version version);
}
public interface IDataBodyFormatter : IDataBodyFormatterBase
{
void Serialize(IByteBuffer writer, T value, Version version);
new T Deserialize(IByteBuffer reader, Version version);
}
# 使用一个基类
public abstract class TDataBody : DataBody, IDataBodyFormatter
{
public abstract T Deserialize(IByteBuffer reader, Version version);
public abstract void Serialize(IByteBuffer writer, T value, Version version);
object IDataBodyFormatterBase.Deserialize(IByteBuffer reader, Version version)
{
return this.Deserialize(reader, version);
}
}
public class DataBodyFormatterFactory : IDataBodyFormatterFactory
{
[Autowired()]
public Dictionary FormatterDict { get; set; }
//不允许的写法
//public Dictionary FormatterDict2 { get; set; }
public IDataBodyFormatterBase getDataBodyFormatter(int code, bool isReply = false)
{
}
}
# 使用
dataBodyFormatter = _DataBodyFactory.getDataBodyFormatter(code, IsClientMode);
@@#