[blam] Item: Use ElementExtensions to save properties.



commit 2ae084fce4b27f8028f6cb0b4e3c7f15e916acd2
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Sat Sep 25 21:41:00 2010 +0200

    Item: Use ElementExtensions to save properties.
    
    The constructor reads in these extensions and caches them as variables
    to be read and written in the normal way.
    
    WriteExtensions() must be called in order for the updated values to
    be serialised.

 src/Item.cs |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/src/Item.cs b/src/Item.cs
index 72ba0b0..0c26f7f 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -10,11 +10,11 @@ using System.ServiceModel.Syndication;
 
 namespace Imendio.Blam {
 	public class Item : SyndicationItem {
-		[XmlAttribute] public bool     Unread = true;
-		[XmlAttribute] public bool     Old = false;
-		[XmlAttribute] public bool     Permanent = false;
+		public bool    Unread = true;
+		public bool     Old = false;
+		public bool     Permanent = false;
 
-		[XmlAttribute] public string   keywords = "";
+		public string   keywords = "";
 
         public SyndicationContent exposed_text;
 
@@ -36,6 +36,15 @@ namespace Imendio.Blam {
 			}
 		}
 
+        public void WriteExtensions()
+        {
+            ElementExtensions.Clear();
+            ElementExtensions.Add("unread", "blam", Unread);
+            ElementExtensions.Add("old", "blam", Old);
+            ElementExtensions.Add("permanent", "blam", Permanent);
+            ElementExtensions.Add("keywords", "blam", keywords);
+        }
+
 		public Item ()
 		{
 		}
@@ -54,10 +63,33 @@ namespace Imendio.Blam {
                 this.exposed_text = item.Content;
             }
 
-            /* Get <content:encoded> elements, overwriting <content> */
             foreach(SyndicationElementExtension ext in this.ElementExtensions){
-                if(ext.OuterName == "encoded"){
-                    this.exposed_text = ext.GetObject<SyndicationContent>();
+                switch(ext.OuterNamespace){
+                /* Read our Item properties */
+                case "blam":
+                    switch(ext.OuterName){
+                    case "unread":
+                        Unread = ext.GetObject<bool>();
+                        break;
+                    case "old":
+                        Old = ext.GetObject<bool>();
+                        break;
+                    case "permanent":
+                        Permanent = ext.GetObject<bool>();
+                        break;
+                    case "keywords":
+                        Keywords = ext.GetObject<string>();
+                        break;
+                    }
+                    break;
+                case "content":
+                    /* <content:encoded> overwrites anything */
+                    switch(ext.OuterName){
+                    case "encoded":
+                        this.exposed_text = ext.GetObject<SyndicationContent>();
+                        break;
+                    }
+                    break;
                 }
             }
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]