﻿// Decompiled with JetBrains decompiler
// Type: System.Web.UI.WebControls.WebParts.ProxyWebPartConnectionCollection
// Assembly: System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 7E68A73E-4066-4F24-AB0A-F147209F50EC
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.dll

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Runtime;

namespace System.Web.UI.WebControls.WebParts
{
  /// <summary>
  /// Contains a collection of static <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> objects, which is used when the connections are declared in content pages and the <see cref="T:System.Web.UI.WebControls.WebParts.WebPartManager"/> control is declared in a master page. This class cannot be inherited.
  /// </summary>
  [Editor("System.ComponentModel.Design.CollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (UITypeEditor))]
  public sealed class ProxyWebPartConnectionCollection : CollectionBase
  {
    private WebPartManager _webPartManager;

    /// <summary>
    /// Gets a value indicating whether <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> objects can be added to the collection.
    /// </summary>
    /// 
    /// <returns>
    /// true if connection objects cannot be added to the collection; otherwise, false.
    /// </returns>
    public bool IsReadOnly
    {
      get
      {
        if (this._webPartManager != null)
          return this._webPartManager.StaticConnections.IsReadOnly;
        return false;
      }
    }

    /// <summary>
    /// Gets or sets a connection item within the collection, based on an index number indicating the item's location in the collection.
    /// </summary>
    /// 
    /// <returns>
    /// A <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> at the specified index in the collection.
    /// </returns>
    /// <param name="index">An integer that indicates the index of a member of the collection.  </param>
    public WebPartConnection this[int index]
    {
      get
      {
        return (WebPartConnection) this.List[index];
      }
      set
      {
        this.List[index] = (object) value;
      }
    }

    /// <summary>
    /// Returns a specific member of the collection according to a unique identifier.
    /// </summary>
    /// 
    /// <returns>
    /// The first <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> whose ID matches the value of the <paramref name="id"/> parameter. Returns null if no match is found.
    /// </returns>
    /// <param name="id">A string that contains the ID of a particular connection in the collection. </param>
    public WebPartConnection this[string id]
    {
      get
      {
        foreach (WebPartConnection webPartConnection in (IEnumerable) this.List)
        {
          if (webPartConnection != null && string.Equals(webPartConnection.ID, id, StringComparison.OrdinalIgnoreCase))
            return webPartConnection;
        }
        return (WebPartConnection) null;
      }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="T:System.Web.UI.WebControls.WebParts.ProxyWebPartConnectionCollection"/> class.
    /// </summary>
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public ProxyWebPartConnectionCollection()
    {
    }

    /// <summary>
    /// Adds a <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> object to the collection.
    /// </summary>
    /// 
    /// <returns>
    /// An integer value that indicates where the <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> was inserted into the collection.
    /// </returns>
    /// <param name="value">A <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> to add to the collection. </param>
    public int Add(WebPartConnection value)
    {
      return this.List.Add((object) value);
    }

    /// <summary>
    /// Returns a value indicating whether a particular <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> object exists in the collection.
    /// </summary>
    /// 
    /// <returns>
    /// true if <paramref name="value"/> exists in the collection; otherwise, false.
    /// </returns>
    /// <param name="value">A <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> being checked for its existence in a collection. </param>
    public bool Contains(WebPartConnection value)
    {
      return this.List.Contains((object) value);
    }

    /// <summary>
    /// Copies the collection to an array of <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> objects.
    /// </summary>
    /// <param name="array">An array of <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> objects to contain the copied collection. </param><param name="index">An integer that indicates the starting point in the array at which to place the collection contents. </param>
    public void CopyTo(WebPartConnection[] array, int index)
    {
      this.List.CopyTo((Array) array, index);
    }

    /// <summary>
    /// Returns the position of a particular member of the collection.
    /// </summary>
    /// 
    /// <returns>
    /// An integer that indicates the position of a particular object in the collection.
    /// </returns>
    /// <param name="value">A <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> that is a member of the collection. </param>
    public int IndexOf(WebPartConnection value)
    {
      return this.List.IndexOf((object) value);
    }

    /// <summary>
    /// Inserts a <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> object into the collection at the specified index.
    /// </summary>
    /// <param name="index">An integer indicating the ordinal position in the collection at which a <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> should be inserted. </param><param name="value">A <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> to insert into the collection.  </param>
    public void Insert(int index, WebPartConnection value)
    {
      this.List.Insert(index, (object) value);
    }

    protected override void OnClear()
    {
      this.CheckReadOnly();
      if (this._webPartManager != null)
      {
        foreach (WebPartConnection webPartConnection in (CollectionBase) this)
          this._webPartManager.StaticConnections.Remove(webPartConnection);
      }
      base.OnClear();
    }

    protected override void OnInsert(int index, object value)
    {
      this.CheckReadOnly();
      if (this._webPartManager != null)
        this._webPartManager.StaticConnections.Insert(index, (WebPartConnection) value);
      base.OnInsert(index, value);
    }

    protected override void OnRemove(int index, object value)
    {
      this.CheckReadOnly();
      if (this._webPartManager != null)
        this._webPartManager.StaticConnections.Remove((WebPartConnection) value);
      base.OnRemove(index, value);
    }

    protected override void OnSet(int index, object oldValue, object newValue)
    {
      this.CheckReadOnly();
      if (this._webPartManager != null)
        this._webPartManager.StaticConnections[this._webPartManager.StaticConnections.IndexOf((WebPartConnection) oldValue)] = (WebPartConnection) newValue;
      base.OnSet(index, oldValue, newValue);
    }

    protected override void OnValidate(object value)
    {
      base.OnValidate(value);
      if (value == null)
        throw new ArgumentNullException("value", System.Web.SR.GetString("Collection_CantAddNull"));
      if (!(value is WebPartConnection))
        throw new ArgumentException(System.Web.SR.GetString("Collection_InvalidType", new object[1]
        {
          (object) "WebPartConnection"
        }));
    }

    /// <summary>
    /// Removes the specified <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> object from the collection.
    /// </summary>
    /// <param name="value">The <see cref="T:System.Web.UI.WebControls.WebParts.WebPartConnection"/> to be removed. </param>
    public void Remove(WebPartConnection value)
    {
      this.List.Remove((object) value);
    }

    internal void SetWebPartManager(WebPartManager webPartManager)
    {
      this._webPartManager = webPartManager;
      foreach (WebPartConnection webPartConnection in (CollectionBase) this)
        this._webPartManager.StaticConnections.Add(webPartConnection);
    }

    private void CheckReadOnly()
    {
      if (this.IsReadOnly)
        throw new InvalidOperationException(System.Web.SR.GetString("ProxyWebPartConnectionCollection_ReadOnly"));
    }
  }
}
