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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:14:54+00:00 2026-06-17T17:14:54+00:00

I have a three classes that are serialized into XML data via XMLserializer Method.

  • 0

I have a three classes that are serialized into XML data via XMLserializer Method. Is there a way to make the method accessible by all of them rather than have three xmlserialize methods in my code.

//Here I'm writing to my class with the data that needs to be serialized                  
PERSON r = new PERSON();
Input l = new Search.Input();
INPUTSEARCHNBR ln = new INPUTSEARCHNBR();
ln.number = pnumber;                  
r.query = ln;                
string xml = doSerialization(r);

//Call the xmlserializer method 
private static string doSerialization(PERSON r)
{
    string serializedValue = string.Empty;

    try
    {
        XmlSerializer xmlSerializer = new XmlSerializer(r.GetType());

        using (MemoryStream ms = new MemoryStream())
        {
            xmlSerializer.Serialize(ms, r);

            ms.Position = 0;
            var sr = new StreamReader(ms);
            serializedValue = sr.ReadToEnd();
        }


        serializedVal = serializedValue.Replace("version=\"0\"", string.Empty).Replace("<?xml version=\"1.0\"?>", string.Empty).Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", string.Empty);
    }

    return serializedVal;
} 

My code repeats this two more time for two different classes, it writes to the class and then calls another xmlserialize method
because the input of the method is a different class type.
Is there are a way to make the method public or have as a class or any other way so that I don’t have to paste two additional
xmlserialize method that are exactly the same but the input class is different.

  • 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-17T17:14:55+00:00Added an answer on June 17, 2026 at 5:14 pm

    Since you don’t do anything that is class specific, you could type object:

    private static string doSerialization(object r)
    {
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes that I am using and have shortened for ease of
I have three classes that all have a static function called 'create'. I would
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
There are certain classes, such as Closeable , File and Container , that have
I have a bunch of stored, serialized classes (that all inherit from a base
I need to have a way to serialize classes in my code into a
I have a bunch of different DTO classes. They are being serialized into an
I need to read UML diagrams that are serialized into XMI. Is there any
I have a set of custom XML configuration management classes in .NET. There are

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.