zoukankan      html  css  js  c++  java
  • [Enterprise Library]Data (二)DataCollection

    上节[Enterprise Library]Data (一)Data的config文件我们看到三个集合类:
    DatabaseTypeDataCollection
    InstanceDataCollection
    ConnectionStringDataCollection

    它们都是从Enterprise Library的Common.DataCollection中继承而来,
        [XmlType(IncludeInSchema=false)]
        [Serializable]
        public abstract class DataCollection : ICollection, ISerializable, IDeserializationCallback
        {
           ...
        }


    1)DataCollection有五个构造函数:
    protected DataCollection()
    protected DataCollection(int capacity)
    protected DataCollection(IHashCodeProvider hashCodeProvider, IComparer comparer)
    protected DataCollection(int capacity, IHashCodeProvider hashCodeProvider, IComparer comparer)
    protected DataCollection(SerializationInfo info, StreamingContext context)

    2)与以前dotText中处理的普通Collection一样,内部需要定义一个IEnumerator:
            [Serializable()]
            internal class DataCollectionValuesEnumerator : IEnumerator

    类似地,这个类需要实现一下:
    public bool MoveNext()
    public void Reset()
    public object Current

    并且Collection中需要有这样一个GetEnumerator()函数:
            public IEnumerator GetEnumerator()
            {
                return new DataCollectionValuesEnumerator(this);
            }

    3)内部还额外地实现了一个存取String的Collection:KeysCollection
            [Serializable()]
            public sealed class KeysCollection : ICollection

    a)取string
    public String Get(int index)
    public string this[int index]

    b)string版的CopyTo
    void ICollection.CopyTo(Array array, int index) { string[] stringArray = array as string[]; ... }
    public void CopyTo(string[] array, int index)

    c)构造函数:nternal KeysCollection(DataCollection collection)
    d)public IEnumerator GetEnumerator()

    而在Collecton中:
            private KeysCollection keys;
            public KeysCollection Keys
            {
                get
                {
                    if (keys == null)
                    {
                        keys = new KeysCollection(this);
                    }
                    return keys;
                }
            }

    4)DataCollection中public的函数:

    public bool Contains(string name)
    public void RemoveAt(int index)
    public void Remove(string name)
    public void Clear()
    public void CopyTo(Array array, int index)


    public virtual void OnDeserialization(Object sender)
    public virtual void GetObjectData(SerializationInfo info, StreamingContext context)


    其它的内部实现以后再分析。

  • 相关阅读:
    第三章-5、图片左右滑动(动态面板引导页面)
    第三章-8、抽屉导航(动态面板)
    第三章-7、没做
    第三章-6、失败
    第三章-4、瀑布流(动态面板)
    第三章-3、跳转页面&返回页面
    第三章-2、设置条件进行外部连接,跳转页面
    第三章-1、界面原件属性使用(登录界面)
    6、如何将excel表格中的图片批量居中对齐
    React Native
  • 原文地址:https://www.cnblogs.com/huqingyu/p/217429.html
Copyright © 2011-2022 走看看