Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:30:17+00:00 2026-06-05T22:30:17+00:00

[ProtoContract] public abstract class Animal { [ProtoMember(1)] public abstract string Type { get; set;

  • 0
[ProtoContract]
public abstract class Animal
{
    [ProtoMember(1)]
    public abstract string Type { get; set; }
    [ProtoMember(2)]
    public string Name { get; set; }
    [ProtoMember(3)]
    public int Likeability { get; set; }
}

public class Cat : Animal
{
    public override string Type { get; set; }
    public int Friendliness { get; set; }

    public override string ToString()
    {
        return String.Format("Type : {0}, Name : {1}, Likeability : {2}, Friendliness : {3}", Type, Name, Likeability, Friendliness);
    }
}

use case i.e.

var animal = new Cat() { Name = "Whiskers", Friendliness = 10 , Type = "cat", Likeability = 5};
var model = TypeModel.Create();
model[typeof(Animal)].AddSubType(4, typeof(Cat));
model[typeof(Cat)].AddField(1, "Friendliness");
var typeModel = model.Compile();

var memoryStream = new MemoryStream();
typeModel.Serialize(memoryStream, animal);

var deserializedCat = new Cat() { Name = "PusPus" };
memoryStream.Seek(0, SeekOrigin.Begin);
var deserializedCat1 = typeModel.Deserialize(memoryStream, deserializedCat, typeof(Cat));
Console.WriteLine("deserializedCat : hash : " + deserializedCat.GetHashCode() + "\n" + deserializedCat);
Console.WriteLine("deserializedCat1 : hash : " + deserializedCat1.GetHashCode() + "\n" + deserializedCat1);

Is the above use case correct for reusable runtime serialization or should one explicitly map the “Cat” ignoring the “Animal” and Also a bit confused w.r.t “ComplileInPlace” how does it differ from Compile ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:30:18+00:00Added an answer on June 5, 2026 at 10:30 pm

    In terms of mapping at runtime, that looks fine. Does it work as expected? i.e. do you get a cat back? and both the Animal and Cat members?

    Differences in the Compile* methods:

    • CompileInPlace() makes the existing model, such that future calls to model.Serialize(...) will use the serialized form. Normally this is automatic anyway the first time each type is required, but this allows it to be prepared ahead of time; the “in place” approach also has extra features – it can access private members, and it can do extra stack tricks for small performance tweaks – but it is not available on all platforms
    • Compile(string,string) allows you to compile the model to a separate dll file, which can be referenced and used for fully-static serialization (i.e. no reflection at runtime)
    • Compile() does something like that, but creates an instance of a TypeModel built from the model, without a separate dll file

    In most cases, CompileInPlace() is what you are after – although you don’t need to do anything at all, since it will usually automatically compile-in-place when needed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the following.. public class Foo { public string Name { get; private
public class A { public int X { get; private set; } public A(int
I have a very simple class that I'm trying to serialize: [ProtoContract] public class
We are using protobuf-net (and love it!). We now have a protocontract-decorated child class
Does anybody know what is the right way to set up a ProtoContract for
I have a .NET type, which is attributed with neither ProtoContract nor DataContract. In
(NOTE: Dictionary where T is some ProtoContract / ProtoMembered class works fine. ) This
I have a protocol buffer setup like this: [ProtoContract] Foo { [ProtoMember(1)] Bar[] Bars;
How can I get v2 of protobuf-net to ignore the fact that my class
In the following examples: public class RowData { public object[] Values; } public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.