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

  • Home
  • SEARCH
  • 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 1089593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:14:44+00:00 2026-05-16T23:14:44+00:00

I have class: public class MyClass { [XmlElement(Date)] public DateTime Date { get; set;

  • 0

I have class:

public class MyClass
{
    [XmlElement("Date")]
    public DateTime Date { get; set; }
}

It was XML serialized to a file:

var myClass = new MyClass() { Date = new DateTime(2010, 09, 24) };
new XmlSerializer(typeof(MyClass)).Serialize(fileStream, myClass);

The result:

<MyClass>
    <Date>2010-09-24T00:00:00</Date>
</MyClass>

After that the new date-holder class was created:

public class MyDate
{
    public int Year { get; set; }
    public int Month { get; set; }
    public int Date { get; set; }
}

And was used in MyClass instead of System.DateTime:

public class MyClass
{
    [XmlElement("Date")]
    public MyDate Date { get; set; }
}

What I need is to make following code work fine:

MyClass myClass = (MyClass)new XmlSerializer(typeof(MyClass)).Deserialize(fileStream);

The problem is I can’t change the MyClass. The only things I can change are MyDate class and serialization/deserialization code.

How to make the deserialization code so as new class MyDate is deserialized from previously serialized System.DateTime?

  • 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-16T23:14:45+00:00Added an answer on May 16, 2026 at 11:14 pm

    One option would be to implement IXmlSerializable on the MyDate class and then parse the date string in the ReadXml method using XmlConvert.ToDateTime.

    If the purpose of the MyDate class is to have a different XML format, then you could support both input formats in the ReadXml method by checking what is actually present in the element, but always write to the new format in the WriteXml method.

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

Sidebar

Related Questions

Say I have this class: class myclass { public int Field1{ get; set; }
I have a class: public class MyClass<T> { public string TestProperty { get; set;
I have a class: public class MyClass { public int code { set; get;
Suppose I have a class public class MyClass { private Set<String> set = new
Suppose, i have class, define('property', 'test'); class myClass { public $test; } $obj=new myClass;
I have a class like this: Public Class MyClass Private _intList As New List(Of
Let's propose that I have the following class Public MyClass{ Date date; //Mutable getters
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <

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.