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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:00:57+00:00 2026-05-27T00:00:57+00:00

for object serialization I created a DataTransferObject-Pendant for each of my objects. Each original

  • 0

for object serialization I created a DataTransferObject-Pendant for each of my objects. Each original object gets a ToDTO()-method that returns the appropriate DTO-Object with the properties to be saved . Most of my original objects are inherited from an other, so I would want each inheritance-level to care for their own properties. A simple example:

class base
{
  private string _name;

  public DTO_base ToDTO()
  {
    DTO_base result = new DTO_base();
    result.Name = _name;
    return result;
  }
}

The inherited class should override the ToDTO() method, calling the parents method and adding its own properties to be saved, like:

class inherited : base
{
  private string _description;

  public new DTO_inherited ToDTO()
  {
    DTO_inherited result = base.ToDTO();
    result.Description = _description;
    return result;
  }
}

Obviously, this wont work, because base.ToDTO() returns a DTO_base object. Can anyone suggest, how this feature would be implemented best?

Thanks in advance,
Frank

  • 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-27T00:00:58+00:00Added an answer on May 27, 2026 at 12:00 am

    I would use a Template Method:

    class baseCls
    {
      private string _name;
    
      public DTO_base ToDTO()
      {
        DTO_base result = createDTO();
        result.Name = _name;
        setAdditionalData(result);
        return result;
      }
    
      protected abstract DTO_base createDTO();
      protected abstract void setAdditionalData(DTO_base dto);
    }
    
    class inherited : baseCls
    {
      private string _description;
    
      protected override DTO_base createDTO() {
        return new DTO_inerited();
      }
      protected override void setAdditionalData(DTO_base dto) {
         inherited i = (DTO_inherited)dto;
         i.Description = _Description;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data object that is deep-cloned using a binary serialization. This data
I have a class that serializes a set of objects (using XML serialization) that
how does Serialization of objects works? How object got deserialized and a instance is
Here's the proxy method that was created for the web service I'm trying to
Is there a way to ensure that the serialization of an object is done
What is meant by object serialization? Can you please explain it with some examples?
We work heavily with serialization and having to specify Serializable tag on every object
I'm writing code to do Xml serialization. With below function. public static string SerializeToXml(object
In my task would be very nice to write a kind of objects serialization
Can anyone tell me what is the need of Serialization of objects in Java

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.