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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:33:01+00:00 2026-06-12T20:33:01+00:00

I now understand we can’t deserialize an unknown type. However, to create efficient code

  • 0

I now understand we can’t deserialize an unknown type.

However, to create efficient code I don’t want to create a method to deserialise which has X amount of overloads for the different types.

EG, my method signature could be these (an ever growing list)

static void deserialiseThis(Dog d)
        {
            Stream reader = new FileStream(@"C:\Documents and Settings\Name\Desktop\demo.xml", FileMode.Open);
            System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(d.GetType());
            Dog d = (Dog)xs.Deserialize(reader);
            DoSomethingDoggy(d);
        }

static void deserialiseThis(Cat t)
        {
//again but for cat
        }


static void deserialiseThis(Mouse t)
        {
//again but for mouse
        }

It seems neater to do this

static void deserialiseThis<T>(T t)
        {
            //logic
        }

or

static void deserialiseThis(Type t)
    {
        //logic
    }

The issue with this method though is I can’t instantiate an object using T. However, I can work out what the type is.

Is this an ideal time to use the Factory Pattern?

  • 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-12T20:33:03+00:00Added an answer on June 12, 2026 at 8:33 pm

    It could be something like this

    T Deserialize<T>(Stream s)
    {
        XmlSerializer ser = new XmlSerializer(typeof(T));
        return (T)ser.Deserialize(s);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK so now I can understand that SO's search system is primarily based around
I understand the theory behind the factory design pattern now, but can't seem to
I am now trying to understand some code and I have found a pattern,
I am reading SICP now and don't really understand the necessity of lexical addressing
BACKGROUND : I now understand how to write a C# application that can monitor
Maybe this question is easy,but I can't understand now. String.prototype.self=function() { return this; }
I have refactored working code to use proper objects and now I can't get
As i titled i have two boxes like this Guys now you can understand
So now I understand that I'm getting a ARM Data Abort exception - I
Initially I thought this was going to work, but now I understand it won't

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.