Beispiel #1
0
        public static GraphState ReadFrom(XmlReader r)
        {
            GraphState state = new GraphState();

            state.ReadXml(r);
            return(state);
        }
Beispiel #2
0
 public void ReadXml(XmlReader r)
 {
     r.MoveToContent();
     while (r.Read())
     {
         if (r.NodeType == XmlNodeType.Element)
         {
             PropertyInfo pi = this.GetType().GetProperty(r.Name);
             if (pi != null)
             {
                 Type t = pi.PropertyType;
                 if (t == typeof(Point))
                 {
                     pi.SetValue(this, DeserializePoint(r), null);
                 }
                 else if (t == typeof(Size))
                 {
                     pi.SetValue(this, DeserializeSize(r), null);
                 }
                 else if (t == typeof(int))
                 {
                     pi.SetValue(this, Int32.Parse(r.ReadString()), null);
                 }
                 else if (t == typeof(string))
                 {
                     pi.SetValue(this, r.ReadString(), null);
                 }
                 else if (t == typeof(XmlElement))
                 {
                     pi.SetValue(this, (XmlElement)doc.ReadNode(r), null);
                 }
                 else if (t == typeof(GraphState))
                 {
                     pi.SetValue(this, GraphState.ReadFrom(r), null);
                 }
                 else if (t == typeof(DateTime))
                 {
                     pi.SetValue(this, DeserializeDateTime(r), null);
                 }
                 else if (t == typeof(TimeSpan))
                 {
                     pi.SetValue(this, DeserializeTimeSpan(r), null);
                 }
                 else if (t == typeof(bool))
                 {
                     pi.SetValue(this, bool.Parse(r.ReadString()), null);
                 }
                 else if (t == typeof(QueryRow[]))
                 {
                     pi.SetValue(this, ReadQuery(r), null);
                 }
                 else
                 {
                     throw new Exception("Settings.ReadXml encountered unsupported property type '" + t.FullName + "'");
                 }
             }
             else if (r.Name == "ViewState")
             {
                 // backwards compat for old TransactionViewState slot.
                 this.SetViewStateNode(typeof(TransactionsView), (XmlElement)doc.ReadNode(r));
             }
             else if (r.Name == "Password")
             {
                 // removing passwords from the settings file!
             }
             else
             {
                 string viewType = r.GetAttribute("ViewType");
                 if (!string.IsNullOrWhiteSpace(viewType))
                 {
                     Type t = typeof(Settings).Assembly.GetType(viewType);
                     if (t != null && typeof(IView).IsAssignableFrom(t))
                     {
                         // special case...we don't know how to deserialize these so we leave it for later.
                         this.SetViewStateNode(t, (XmlElement)doc.ReadNode(r));
                     }
                 }
                 else
                 {
                     map[r.Name] = r.ReadString();
                 }
             }
         }
     }
 }