1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
//------------------------------------------------------------------------------
// <copyright file="WebPartConnectionCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Globalization;
using System.Web.Util;
//
[
Editor("System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor))
]
public sealed class WebPartConnectionCollection : CollectionBase {
private bool _readOnly;
private string _readOnlyExceptionMessage;
private WebPartManager _webPartManager;
internal WebPartConnectionCollection(WebPartManager webPartManager) {
_webPartManager = webPartManager;
}
public bool IsReadOnly {
get {
return _readOnly;
}
}
/// <devdoc>
/// Returns the WebPartConnection at a given index.
/// </devdoc>
public WebPartConnection this[int index] {
get {
return (WebPartConnection)List[index];
}
set {
List[index] = value;
}
}
/// <devdoc>
/// Returns the WebPartConnection with the specified id, performing a case-insensitive comparison.
/// Returns null if there are no matches.
/// </devdoc>
public WebPartConnection this[string id] {
// PERF: Use a hashtable for lookup, instead of a linear search
get {
foreach (WebPartConnection connection in List) {
if (String.Equals(connection.ID, id, StringComparison.OrdinalIgnoreCase)) {
return connection;
}
}
return null;
}
}
/// <devdoc>
/// Adds a Connection to the collection.
/// </devdoc>
public int Add(WebPartConnection value) {
return List.Add(value);
}
private void CheckReadOnly() {
if (_readOnly) {
throw new InvalidOperationException(SR.GetString(_readOnlyExceptionMessage));
}
}
/// <devdoc>
/// True if the WebPartConnection is contained in the collection.
/// </devdoc>
public bool Contains(WebPartConnection value) {
return List.Contains(value);
}
internal bool ContainsProvider(WebPart provider) {
foreach (WebPartConnection connection in List) {
if (connection.Provider == provider) {
return true;
}
}
return false;
}
public void CopyTo(WebPartConnection[] array, int index) {
List.CopyTo(array, index);
}
public int IndexOf(WebPartConnection value) {
return List.IndexOf(value);
}
/// <devdoc>
/// Inserts a WebPartConnection into the collection.
/// </devdoc>
public void Insert(int index, WebPartConnection value) {
List.Insert(index, value);
}
/// <devdoc>
/// </devdoc>
protected override void OnClear() {
CheckReadOnly();
base.OnClear();
}
protected override void OnInsert(int index, object value) {
CheckReadOnly();
((WebPartConnection)value).SetWebPartManager(_webPartManager);
base.OnInsert(index, value);
}
protected override void OnRemove(int index, object value) {
CheckReadOnly();
((WebPartConnection)value).SetWebPartManager(null);
base.OnRemove(index, value);
}
protected override void OnSet(int index, object oldValue, object newValue) {
CheckReadOnly();
((WebPartConnection)oldValue).SetWebPartManager(null);
((WebPartConnection)newValue).SetWebPartManager(_webPartManager);
base.OnSet(index, oldValue, newValue);
}
/// <devdoc>
/// Validates that an object is a WebPartConnection.
/// </devdoc>
protected override void OnValidate(object value) {
base.OnValidate(value);
if (value == null) {
throw new ArgumentNullException("value", SR.GetString(SR.Collection_CantAddNull));
}
if (!(value is WebPartConnection)) {
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "WebPartConnection"), "value");
}
}
/// <devdoc>
/// Removes a WebPartConnection from the collection.
/// </devdoc>
public void Remove(WebPartConnection value) {
List.Remove(value);
}
/// <devdoc>
/// Marks the collection readonly. This is useful, because we assume that the list
/// of static connections is known at Init time, and new connections are added
/// through the WebPartManager.
/// </devdoc>
internal void SetReadOnly(string exceptionMessage) {
_readOnlyExceptionMessage = exceptionMessage;
_readOnly = true;
}
}
}
|