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 307045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:31:21+00:00 2026-05-12T07:31:21+00:00

I have an abstract class. Let’s call it Lifeform. It looks something like: public

  • 0

I have an abstract class. Let’s call it Lifeform. It looks something like:

public abstract class Lifeform {
    public virtual int Legs { get; set; }
    public virtual int Arms { get; set; }
    public virtual bool Alive { get; set; }
}

(The virtual attribute is due to the fact that I’m using nHibernate, which whines if they’re not virtual properties.)

I then have a class which inherits from that Lifeform class; we’ll call it Human. It looks something like:

public class Human: Lifeform {
    public virtual bool Hat { get; set; }
    public virtual int Age { get; set; }
    public virtual string Name { get; set; }
}

Everything’s lovely, I can use my classes, Human gets the Legs, Arms, and Alive properties when I’m using it. Except, that is, when I attempt to make a web service using the Human class. The serialized object gives me Hat, Age, and Name – but no Legs, Arms, or Alive properties.

I’ve seen a workaround that suggests using

[System.Xml.Serialization.XmlInclude(typeof(Human))]

On the base class (Lifeform), but that seems like a horrible hack that violates OO. Putting links on the base class to the classes that inherit it? Eww.

Has anyone run into this specific issue before? Have any ideas? I’ll provide more code if a more in-depth example would help describe what I’m doing more.

  • 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-05-12T07:31:22+00:00Added an answer on May 12, 2026 at 7:31 am

    From what I’ve read, you can include the XMLInclude attribute on the web method returning the object rather than in the base class. Still not pretty, but might appeal to you a little more than putting derived class names in the base class. I haven’t tried it out, but I think you can do something like this.

    [WebMethod]
    [XmlInclude(typeof(LifeForm))]
    public Human GetHuman()
    {
       return new Human();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an abstract base class that looks like this: class StellarObject(BaseModel):
I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual;
First let's establish this. I have public abstract class Foo { public static void
Possible Duplicate: When to use virtual destructors? let's say i have an abstract class
I have an abstract class and I would like to use it quickly by
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
I have an abstract class defining a pure virtual method in c++: class Base
I have an abstract base class and derived class: type TInterfaceMethod = class public
I have one abstract class -let's say myBase. And I want all the classes
Let say I have abstract class called: Tenant and Customer. The tenant in this

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.