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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:25:55+00:00 2026-06-12T08:25:55+00:00

I serialize/deserialize object which contains double values using XmlSerializer and StreamWriter . In generated

  • 0

I serialize/deserialize object which contains double values using XmlSerializer and StreamWriter. In generated .xml file I find that double value stored as decimal value. I wounder is there some way to generate double in hexadecimal form instead decimal?

Some code.

class to serialize

[Serializable()]  
public class Variable
{        
    public int shift;
    public int size;
    public int min;
    public int max;
    public string name;
    public string del;

    public Variable()
    {
        shift = 26;
        size = 0;
        min = 0;
        max = 0;
        name = "noname";
        del = "-";
    }
}

serializator class

/// <summary>
/// class to serialize/deserialize another class
/// </summary>
public class serializator
{
    private serializator()
    {
    }

    /// <summary>
    /// serializator
    /// </summary>
    /// <param name="fname">filename to serialize</param>
    /// <param name="z">object to serialize</param>
    static public void ser(string fname, object z)
    {
        System.Type st = z.GetType();
        XmlSerializer xSer = new XmlSerializer(st);
        StreamWriter sWri = new StreamWriter(fname);
        xSer.Serialize(sWri, z);
        sWri.Close();
    }

    /// <summary>
    /// deserializator
    /// usage: fooclass fc = (fooclass)serializator.dser("fname.xml", fc);
    /// </summary>
    /// <param name="fname">filename to dser</param>
    /// <param name="z">object to grab type</param>
    /// <returns></returns>
    static public object dser(string fname, object z)
    {
        if (fname != null && fname != "" && z != null)
        {
            try
            {
                object rez = new object();
                XmlSerializer xSer = new XmlSerializer(z.GetType());
                StreamReader sRea = new StreamReader(fname);
                rez = xSer.Deserialize(sRea);
                sRea.Close();
                return rez;
            }
            catch(Exception e)
            {
                System.Windows.Forms.MessageBox.Show("config ouch\r\n"+e.Message);
                return null;
            }
        }
        else
        {
            return null;
        }
    }
}

piece of code from main program

Variable v = new Variable();
serializator.ser("foo.xml", v);  

resulting xml file

<?xml version="1.0" encoding="utf-8"?>
  <Variable>
    <shift>26</shift>
    <size>0</size>
    <min>0</min>
    <max>0</max>
    <name>noname</name>
    <del>-</del>
  </Variable>  

In this particular case I want to see <shift>1A</shift> or <shift>0x1A</shift> instead <shift>26</shift>. Is is possible?

  • 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-12T08:25:57+00:00Added an answer on June 12, 2026 at 8:25 am

    You can use this code of class “Variable” instead of yours:

    [Serializable()]
    public class Variable
    {
        int _shiftInt;
    
        public string shift
        {
            get
            {
                return _shiftInt.ToString("X");
            }
            set
            {
                _shiftInt = int.Parse(value, System.Globalization.NumberStyles.HexNumber);
            }
        }
    
        public int size { get; set; }
        public int min { get; set; }
        public int max { get; set; }
        public string name { get; set; }
        public string del { get; set; }
    
        public Variable()
        {
            _shiftInt = 26;
            size = 0;
            min = 0;
            max = 0;
            name = "noname";
            del = "-";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XmlSerializer to serialize an object that contains a generic list List <ChildBase>
My object template , which is deserialized from a hand made XML file contains
I am using XStream to serialize an object which contains a Date field to
I'm trying to make a genric code to serialize and deserialize any object that
I'm using Jackson to serialize and deserialize objects. The problem is that sometimes I
I'm using DataContractSerializer to serialize/deserialize my classes to/from XML. Everything works fine, but at
I'm writing a windows service application that needs to serialize and deserialize XML documents
We serialize/deserialize XML using XStream... and just got an OutOfMemory exception. Firstly I don't
In C#, how do I use an XmlSerializer to deserialize an object that might
I need to serialize an object array array<object^>^ in C++/CLI which contains one intPtr

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.