/// <summary> /// Centralized location for seralization, but does not set any members on the class. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <param name="seralization"></param> /// <returns></returns> public static string Encode <T>(T data, SeralizeAs seralization) { if (seralization == SeralizeAs.Xml) { return(Seralizer.ObjectToXmlString <T>(data)); } else if (seralization == SeralizeAs.Json) { return(Newtonsoft.Json.JsonConvert.SerializeObject(data)); } else { throw new InvalidOperationException("Unknown seralization selected"); } }
/// <summary> /// Reads the property value. /// </summary> /// <returns>The property value.</returns> private object ReadPropertyValue() { SeralizeAs serializeAs = (SeralizeAs)Enum.Parse(typeof(SeralizeAs), this.reader.GetAttribute(SeralizeAsAttribute)); if (serializeAs == SeralizeAs.Font) { return(FontSerailizer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Point) { return(PointSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Size) { return(SizeSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.Color) { return(ColorSerializer.ReadType(this.reader)); } else if (serializeAs == SeralizeAs.RecentFiles) { return(RecentFiles.ReadType(this.reader)); } else { // SeralizeAs.Default Type type = Type.GetType(this.reader.GetAttribute(TypeAttribute)); if (type.IsEnum) { return(Enum.Parse(type, this.reader.ReadString())); } else if (type == typeof(string)) { return(this.reader.ReadString()); } else { return(Convert.ChangeType(this.reader.ReadString(), type, CultureInfo.CurrentCulture)); } } }
/// <summary> /// Constructor that allows the data and seralization to get set upon creation /// </summary> /// <param name="data"></param> /// <param name="seralization"></param> public DataEventArgs(Object data, SeralizeAs seralization) { SetData(data, seralization); }
/// <summary> /// Takes the data and seralizes it and sets the seralization /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <param name="seralization"></param> public void SetData <T>(T data, SeralizeAs seralization) { Data = Encode(data, seralization); Seralization = seralization; }