C # serialization and deserialization operations

Source: Internet
Author: User

[Serializable]
public class Billpropertyconfig
{
Public Billpropertyconfig ()
{
This. Playitembackcol = color.red;
This. Playitemfontcol = Color.Blue;
This. FontSize = new Font ("Arial", 10);
This. Fontorisize = new Font ("Arial", 10);
This. Show_start = true;
This. Show_model = true;
This. Show_set = true;
This. Show_title = true;
This. Show_in = true;
This. Show_dur = true;
This. Show_you = true;
This. Show_gua = true;
This. SHOW_GUA2 = true;
This. Show_tai = true;
This. Show_ju = true;
This. Show_dao = true;
This. Show_signal = true;
This. Show_type = true;
This. Show_department = true;
This. Show_mappingmode = true;
}
[XmlIgnore]
Public Color Playitembackcol {get; set;}
public int Serializerplayitembackcol
{
Get
{
Return Colortranslator.towin32 (Playitembackcol);
}
Set
{
Playitembackcol = Colortranslator.fromwin32 (value);
}
}
[XmlIgnore]
Public Color Playitemfontcol {get; set;}
public int Serializerplayitemfontcol
{
Get
{
Return Colortranslator.towin32 (Playitemfontcol);
}
Set
{
Playitemfontcol = Colortranslator.fromwin32 (value);
}
}
[XmlIgnore]
Public Font FontSize {get; set;}
Public MyFont Serializerfontsize
{
Get
{
MyFont _fontsize = new MyFont ();


_fontsize.name = Fontsize.name;
_fontsize.size = fontsize.size;
_fontsize.style = Fontsize.style;


return _fontsize;


}


Set
{
FontSize = new Font (value. Name, value. Size, value. Style);
}
}
[XmlIgnore]
Public Font fontorisize {get; set;}
Public MyFont Serializerfontorisize
{
Get
{
MyFont _fontorisize = new MyFont ();


_fontorisize.name = Fontorisize.name;
_fontorisize.size = fontorisize.size;
_fontorisize.style = Fontorisize.style;


return _fontorisize;


}


Set
{
Fontorisize = new Font (value. Name, value. Size, value. Style);
}
}
public bool Show_start {get; set;}
public bool Show_model {get; set;}
public bool Show_set {get; set;}
public bool Show_title {get; set;}
public bool Show_in {get; set;}
public bool Show_dur {get; set;}
public bool Show_you {get; set;}
public bool Show_gua {get; set;}
public bool Show_gua2 {get; set;}
public bool Show_tai {get; set;}
public bool Show_ju {get; set;}
public bool Show_dao {get; set;}
public bool Show_signal {get; set;}
public bool Show_type {get; set;}
public bool Show_department {get; set;}
public bool Show_mappingmode {get; set;}


public string ToXML ()
{
Return Staticmethod.obj2xml (this);
}


Public billpropertyconfig FromXml (String str)
{
Billpropertyconfig m = staticmethod.xml2obj (str, this. GetType ()) as Billpropertyconfig;
if (M! = null)
{
return m;
}
return new Billpropertyconfig ();
}
}
[Serializable]
public class MyFont
{
Public MyFont ()
{
}
public string Name;
Public FontStyle style;//This can include several other items.
public float Size;

}

public static string Obj2xml (Object obj)
{
String xmlstr = "";
Try
{
using (MemoryStream ms = new MemoryStream ())
{
XmlSerializer XML = new XmlSerializer (obj. GetType ());
Xml. Serialize (MS, obj);
Byte[] arr = Ms. ToArray ();
Xmlstr = Encoding.UTF8.GetString (arr);
}
}
Catch {}
return xmlstr;
}


public static object Xml2obj (String str, Type t)
{
if (str = = "")
return null;
Object obj = null;
Try
{
using (MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (str)))
{
XmlSerializer XML = Xmlserializer.fromtypes (new[] {T}). FirstOrDefault ();
XmlSerializer XML = new XmlSerializer (t);
obj = XML. Deserialize (MS);
}
}
Catch {}
return obj;
}

C # serialization and deserialization operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.