示例#1
0
        /// <summary>
        ///   The to xml.
        /// </summary>
        /// <returns> The System.String. </returns>
        public string ToXml()
        {
            var surrogate = new StateTrackerSurrogateSelector();
            var serializer = new DataContractSerializer(
                typeof(StateTracker), new Type[0], short.MaxValue, false, false, surrogate);
            var buffer = new StringBuilder();
            using (
                var writer = XmlWriter.Create(
                    buffer,
                    new XmlWriterSettings
                        {
                            Indent = true,
                            OmitXmlDeclaration = true,
                            NamespaceHandling = NamespaceHandling.OmitDuplicates
                        }))
            {
                serializer.WriteObject(writer, this);
            }

            return buffer.ToString();
        }
示例#2
0
 /// <summary>
 /// The parse.
 /// </summary>
 /// <param name="xml">
 /// The xml. 
 /// </param>
 /// <returns>
 /// The Microsoft.Activities.Extensions.Tracking.StateTracker. 
 /// </returns>
 public static StateTracker Parse(string xml)
 {
     var surrogate = new StateTrackerSurrogateSelector();
     var serializer = new DataContractSerializer(
         typeof(StateTracker), new Type[0], short.MaxValue, false, false, surrogate);
     var buffer = new StringReader(xml);
     using (var reader = XmlReader.Create(buffer))
     {
         return (StateTracker)serializer.ReadObject(reader);
     }
 }