--- trunk/libxmltv/Core/PropertyDictionary.cs 2013/03/10 12:25:54 106 +++ trunk/libxmltv/Core/PropertyDictionary.cs 2013/03/10 19:22:06 122 @@ -10,8 +10,8 @@ namespace libxmltv.Core { - - public class PropertyCollection : IPropertyCollection + [Serializable] + internal class PropertyCollection : IPropertyCollection { private List items = new List(); public PropertyCollection() : this(new List()) { } @@ -44,7 +44,8 @@ return string.Format("Property Count: {0}", PropertyCount); } } - public class PropertyDictionary : PropertyDictionary, IPropertyDictionary + [Serializable] + internal class PropertyDictionary : PropertyDictionary, IPropertyDictionary { public PropertyDictionary() : base() { } public PropertyDictionary(IPropertyDictionary dictionary) : base(dictionary) { } @@ -54,7 +55,8 @@ public PropertyDictionary(int capacity, IEqualityComparer comparer) : base(capacity, comparer) { } protected PropertyDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { } } - public class PropertyDictionary : IPropertyDictionary + [Serializable] + internal class PropertyDictionary : IPropertyDictionary { [StructLayout(LayoutKind.Sequential)] private struct Entry @@ -93,7 +95,7 @@ { Type t = typeof(Dictionary); 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; } } @@ -159,87 +161,89 @@ list.CopyTo(array, arrayIndex); } public bool RemoveProperty(IPropertyValuePair item) { return RemoveProperty(item.Name); } - IEnumerator> IEnumerable>.GetEnumerator() { return new PropertyDictionaryEnumerator(this, 2); } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); } + public IEnumerator> GetEnumerator() + { + //return new PropertyDictionaryEnumerator(this, 2); + List> list = new List>(); + foreach (var k in properties) { list.Add(new PropertyValuePair(k.Key, k.Value)); } + return list.GetEnumerator(); + } + IEnumerator IEnumerable.GetEnumerator() { return properties.GetEnumerator(); } public override string ToString() { return string.Format("Property Count: {0}", PropertyCount); } #region enumerator support - public class PropertyDictionaryEnumerator : IEnumerator>, IDisposable - { - private PropertyDictionary dictionary; - private int index; - private IPropertyValuePair current; - private int getEnumeratorRetType; - internal const int DictEntry = 1; - internal const int KeyValuePair = 2; - private int version; - public PropertyDictionaryEnumerator(PropertyDictionary dictionary, int getEnumeratorRetType) - { - this.dictionary = dictionary; - this.version = dictionary.version; - this.index = 0; - this.getEnumeratorRetType = getEnumeratorRetType; - this.current = new PropertyValuePair(); - } - - public IPropertyValuePair 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(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)(PropertyValuePair)new KeyValuePair(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(); - return false; - } - public void Reset() - { - if (this.version != this.dictionary.version) - { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); - } - this.index = 0; - this.current = (IPropertyValuePair)(PropertyValuePair)new KeyValuePair(); - } - } + //public class PropertyDictionaryEnumerator : IEnumerator>, IDisposable + //{ + // private PropertyDictionary dictionary; + // private int index; + // private IPropertyValuePair current; + // private int getEnumeratorRetType; + // internal const int DictEntry = 1; + // internal const int KeyValuePair = 2; + // private int version; + // public PropertyDictionaryEnumerator(PropertyDictionary dictionary, int getEnumeratorRetType) + // { + // this.dictionary = dictionary; + // //this.version = dictionary.version; + // this.index = 0; + // this.getEnumeratorRetType = getEnumeratorRetType; + // this.current = new PropertyValuePair(); + // } + // public IPropertyValuePair 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(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)(PropertyValuePair)new KeyValuePair(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(); + // return false; + // } + // public void Reset() + // { + // //if (this.version != this.dictionary.version) + // //{ + // // ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + // //} + // this.index = 0; + // this.current = (IPropertyValuePair)(PropertyValuePair)new KeyValuePair(); + // } + //} #endregion }