Skip to content

Instantly share code, notes, and snippets.

@awrowse
Created December 28, 2012 16:44
Show Gist options
  • Save awrowse/4399544 to your computer and use it in GitHub Desktop.
Save awrowse/4399544 to your computer and use it in GitHub Desktop.
ObjectSerialize.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace SSOTester {
[Serializable()]
public class SSOUser {
public SSOUser() {
GUID = Guid.NewGuid().ToString();
}
public string SSAN { get; set; }
public string FileType { get; set; }
public string Component { get; set; }
public string GUID { get; set; }
public void Save() {
String filepath = String.Format(@"{0}\SSO Test Data\{1}.xml", Environment.GetEnvironmentVariable("USERPROFILE"), this.GUID);
(new FileInfo(filepath)).Directory.Create();
FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
TextWriter tw = new StreamWriter(fs);
XmlSerializer ser = new XmlSerializer(typeof(SSOUser));
ser.Serialize(tw, this);
tw.Close();
fs.Close();
}
public static SSOUser Load(string guid) {
SSOUser user = null;
XmlSerializer ser = new XmlSerializer(typeof(SSOUser));
String filepath = String.Format(@"{0}\{1}.xml", Environment.GetEnvironmentVariable("USERPROFILE"), guid);
if (File.Exists(filepath)) {
FileStream fs = new FileStream(filepath, FileMode.Open);
user = (SSOUser)ser.Deserialize(fs);
fs.Close();
}
return user;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment