C # serialization

Source: Internet
Author: User
Public class customstylehelper
{

Public static void doserialize (string strfile, customstyle)
{
Using (filestream FS = new filestream (strfile, filemode. openorcreate ))
{
Xmlserializer formatter = new xmlserializer (typeof (customstyle ));
Formatter. serialize (FS, customstyle );
}

}
Public static customstyle deserialize (string strfile)
{
Customstyle;
Using (filestream FS = new filestream (strfile, filemode. Open ))
{
Xmlserializer formatter = new xmlserializer (typeof (customstyle ));
Customstyle = (customstyle) formatter. deserialize (FS );
}
Return customstyle;

}

// The XML serialization method Cannot serialize object type attributes (such as color), but can only serialize int string type attributes
// The binary serialization method can serialize object type attributes (such as color) or Int string type attributes.
// Zhangjun 2010.12.10
Public static void binarydoserialize (string strfile, customstyle)
{
Using (filestream FS = new filestream (strfile, filemode. openorcreate ))
{
Binaryformatter formatter = new binaryformatter ();
Formatter. serialize (FS, customstyle );
}

}< br> Public static customstyle binarydeserialize (string strfile)
{< br> customstyle;
using (filestream FS = new filestream (strfile, filemode. open)
{< br> binaryformatter formatter = new binaryformatter ();
customstyle = (customstyle) formatter. deserialize (FS);
}< br> return customstyle;

}

Public static irgbcolor color2rgbcolor (color)
{

Irgbcolor newcolor = new rgbcolor ();
Newcolor. Blue = color. B;
Newcolor. Red = color. R;
Newcolor. Green = color. g;

If (color. Name. toupper () = "Transparent ")
{
Newcolor. Transparency = 0;
}

Return newcolor;
}

}

[Serializable]
Public class customstyle
{
Private color scolor;
Public color scolor
{
Get {return scolor ;}
Set {scolor = value ;}
}

Private double swidth;
Public double swidth
{
Get {return swidth ;}
Set {swidth = value ;}
}

Private color dcolor;
Public color dcolor
{
Get {return dcolor ;}
Set {dcolor = value ;}
}

Private double dwidth;
Public double dwidth
{
Get {return dwidth ;}
Set {dwidth = value ;}
}

}

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.