Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protobuf-net Serializing as base class
- [ProtoContract]
- class Base
- {
- [ProtoMember(1)]
- public string PublicInfo { get; set; }
- }
- class Derived : Base
- {
- public string SecretInfo { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Derived d = new Derived()
- {
- PublicInfo = "public info",
- SecretInfo = "secret info"
- };
- using (var ms = new MemoryStream())
- {
- Serializer.NonGeneric.Serialize(ms, d as Base);
- ms.Seek(0, SeekOrigin.Begin);
- Base deserialized = Serializer.Deserialize<Base>(ms);
- Console.WriteLine("Deserialized type: " + deserialized.GetType());
- Console.WriteLine("Deserialized value: " + deserialized.PublicInfo);
- }
- Console.ReadLine();
- }
- }
- Deserialized type: Base
- Deserialized value: public info
- [ProtoContract] class Generic {
- [ProtoMember(1)] public string PublicInfo { get; set; }
- }
- class Specialized {
- public Generic Generic { get; set; }
- public string SecretInfo { get; set; }
- }
- namespace NHibernate.Proxy {
- internal interface INHibernateProxy {} // pretty spectacularly evil
- }
- ...
- class Derived : Base, INHibernateProxy {}
Add Comment
Please, Sign In to add comment