/[xmltv_parser]/trunk/libxmltv/Core/PropertyDictionary.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/PropertyDictionary.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/PropertyDictionary.cs	2013/03/10 11:35:26	105
+++ trunk/libxmltv/Core/PropertyDictionary.cs	2013/03/10 19:22:06	122
@@ -10,8 +10,8 @@
 
 namespace libxmltv.Core
 {
-
-    public class PropertyCollection<T> : IPropertyCollection<T>
+    [Serializable]
+    internal class PropertyCollection<T> : IPropertyCollection<T>
     {
         private List<T> items = new List<T>();
         public PropertyCollection() : this(new List<T>()) { }
@@ -38,8 +38,14 @@
         public bool RemoveProperty(T item) { return items.Remove(item); }
         public IEnumerator<T> GetEnumerator() { return items.GetEnumerator(); }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return items.GetEnumerator(); }
+
+        public override string ToString()
+        {
+            return string.Format("Property Count: {0}", PropertyCount);
+        }
     }
-    public class PropertyDictionary : PropertyDictionary<string, object>, IPropertyDictionary
+    [Serializable]
+    internal class PropertyDictionary : PropertyDictionary<string, object>, IPropertyDictionary
     {
         public PropertyDictionary() : base() { }
         public PropertyDictionary(IPropertyDictionary dictionary) : base(dictionary) { }
@@ -49,7 +55,8 @@
         public PropertyDictionary(int capacity, IEqualityComparer<string> comparer) : base(capacity, comparer) { }
         protected PropertyDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }
     }
-    public class PropertyDictionary<TKey, TValue> : IPropertyDictionary<TKey, TValue>
+    [Serializable]
+    internal class PropertyDictionary<TKey, TValue> : IPropertyDictionary<TKey, TValue>
     {
         [StructLayout(LayoutKind.Sequential)]
         private struct Entry
@@ -58,6 +65,10 @@
             public int next;
             public TKey name;
             public TValue value;
+            public override string ToString()
+            {
+                return new PropertyValuePair<TKey, TValue>(name, value).ToString();
+            }
         }
         private Entry[] entries
         {
@@ -84,7 +95,7 @@
             {
                 Type t = typeof(Dictionary<TKey, TValue>);
                 var field = t.GetField("version", BindingFlags.NonPublic | BindingFlags.Instance);
-                var v = Convert.ToInt32(field.GetValue(properties));
+                var v = Convert.ToInt32(field.GetValue(this.properties));
                 return v;
             }
         }
@@ -150,83 +161,89 @@
             list.CopyTo(array, arrayIndex); 
         }
         public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return RemoveProperty(item.Name); }
-        IEnumerator<IPropertyValuePair<TKey, TValue>> IEnumerable<IPropertyValuePair<TKey, TValue>>.GetEnumerator() { return new PropertyDictionaryEnumerator(this, 2); }
-        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); }
+        public IEnumerator<IPropertyValuePair<TKey, TValue>> GetEnumerator() 
+        { 
+            //return new PropertyDictionaryEnumerator(this, 2); 
+            List<IPropertyValuePair<TKey, TValue>> list = new List<IPropertyValuePair<TKey, TValue>>();
+            foreach (var k in properties) { list.Add(new PropertyValuePair<TKey, TValue>(k.Key, k.Value)); }            
+            return list.GetEnumerator();
+        }
+        IEnumerator IEnumerable.GetEnumerator() { return properties.GetEnumerator(); }
 
-        #region enumerator support
-        public class PropertyDictionaryEnumerator : IEnumerator<IPropertyValuePair<TKey, TValue>>, IDisposable
+        public override string ToString()
         {
-            private PropertyDictionary<TKey, TValue> dictionary;
-            private int index;
-            private IPropertyValuePair<TKey, TValue> current;
-            private int getEnumeratorRetType;
-            internal const int DictEntry = 1;
-            internal const int KeyValuePair = 2;
-            private int version;
-            public PropertyDictionaryEnumerator(PropertyDictionary<TKey, TValue> dictionary, int getEnumeratorRetType) 
-            {
-                this.dictionary = dictionary;
-                this.version = dictionary.version;
-                this.index = 0;
-                this.getEnumeratorRetType = getEnumeratorRetType;
-                this.current = new PropertyValuePair<TKey, TValue>();
-            }
-
-            public IPropertyValuePair<TKey, TValue> Current
-            {
-                get { return this.current; }
-            }
-
-            public void Dispose()
-            {
-            }
-
-            object IEnumerator.Current
-            {
-                get
-                {
-                    if ((this.index == 0) || (this.index == (this.dictionary.Count() + 1)))
-                    {
-                        throw new InvalidOperationException("Operation can't happen");
-                    }
-                    if (this.getEnumeratorRetType == 1)
-                    {
-                        return new DictionaryEntry(this.current.Name, this.current.Value);
-                    }
-                    return new PropertyValuePair<TKey, TValue>(this.current.Name, this.current.Value);
-                }
-            }
-
-            public bool MoveNext()
-            {
-                if (this.version != this.dictionary.version)
-                {
-                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
-                }
-                while (this.index < this.dictionary.Count())
-                {
-                    if (this.dictionary.entries[this.index].hashCode >= 0)
-                    {
-                        this.current =(IPropertyValuePair<TKey,TValue>)(PropertyValuePair<TKey,TValue>)new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value);
-                        this.index++;
-                        return true;
-                    }
-                    this.index++;
-                }
-                this.index = this.dictionary.Count() + 1;
-                this.current = new PropertyValuePair<TKey, TValue>();
-                return false;
-            }
-            public void Reset()
-            {
-                if (this.version != this.dictionary.version)
-                {
-                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
-                }
-                this.index = 0;
-                this.current = (IPropertyValuePair<TKey, TValue>)(PropertyValuePair<TKey, TValue>)new KeyValuePair<TKey, TValue>();
-            }
+            return string.Format("Property Count: {0}", PropertyCount);
         }
+        #region enumerator support
+        //public class PropertyDictionaryEnumerator : IEnumerator<IPropertyValuePair<TKey, TValue>>, IDisposable
+        //{
+        //    private PropertyDictionary<TKey, TValue> dictionary;
+        //    private int index;
+        //    private IPropertyValuePair<TKey, TValue> current;
+        //    private int getEnumeratorRetType;
+        //    internal const int DictEntry = 1;
+        //    internal const int KeyValuePair = 2;
+        //    private int version;
+        //    public PropertyDictionaryEnumerator(PropertyDictionary<TKey, TValue> dictionary, int getEnumeratorRetType) 
+        //    {
+        //        this.dictionary = dictionary;
+        //        //this.version = dictionary.version;
+        //        this.index = 0;
+        //        this.getEnumeratorRetType = getEnumeratorRetType;
+        //        this.current = new PropertyValuePair<TKey, TValue>();
+        //    }
+        //    public IPropertyValuePair<TKey, TValue> Current
+        //    {
+        //        get { return this.current; }
+        //    }
+        //    public void Dispose()
+        //    {
+        //    }
+        //    object IEnumerator.Current
+        //    {
+        //        get
+        //        {
+        //            if ((this.index == 0) || (this.index == (this.dictionary.Count() + 1)))
+        //            {
+        //                throw new InvalidOperationException("Operation can't happen");
+        //            }
+        //            if (this.getEnumeratorRetType == 1)
+        //            {
+        //                return new DictionaryEntry(this.current.Name, this.current.Value);
+        //            }
+        //            return new PropertyValuePair<TKey, TValue>(this.current.Name, this.current.Value);
+        //        }
+        //    }
+        //    public bool MoveNext()
+        //    {
+        //        //if (this.version != this.dictionary.version)
+        //        //{
+        //        //    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
+        //        //}
+        //        while (this.index < this.dictionary.Count())
+        //        {
+        //            if (this.dictionary.entries[this.index].hashCode >= 0)
+        //            {
+        //                this.current =(IPropertyValuePair<TKey,TValue>)(PropertyValuePair<TKey,TValue>)new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value);
+        //                this.index++;
+        //                return true;
+        //            }
+        //            this.index++;
+        //        }
+        //        this.index = this.dictionary.Count() + 1;
+        //        this.current = new PropertyValuePair<TKey, TValue>();
+        //        return false;
+        //    }
+        //    public void Reset()
+        //    {
+        //        //if (this.version != this.dictionary.version)
+        //        //{
+        //        //    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
+        //        //}
+        //        this.index = 0;
+        //        this.current = (IPropertyValuePair<TKey, TValue>)(PropertyValuePair<TKey, TValue>)new KeyValuePair<TKey, TValue>();
+        //    }
+        //}
         #endregion   
     }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22