Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebParts / WebPartCollection.cs / 1305376 / WebPartCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
///
/// Read-only collection of WebParts. Collection cannot be modified after contstruction.
///
public sealed class WebPartCollection : ReadOnlyCollectionBase {
public WebPartCollection() {
}
public WebPartCollection(ICollection webParts) {
if (webParts == null) {
throw new ArgumentNullException("webParts");
}
foreach (object obj in webParts) {
if (obj == null) {
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "webParts");
}
if (!(obj is WebPart)) {
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "WebPart"), "webParts");
}
InnerList.Add(obj);
}
}
internal int Add(WebPart value) {
Debug.Assert(value != null);
return InnerList.Add(value);
}
public bool Contains(WebPart value) {
return InnerList.Contains(value);
}
public int IndexOf(WebPart value) {
return InnerList.IndexOf(value);
}
public WebPart this[int index] {
get {
return (WebPart) InnerList[index];
}
}
///
/// Returns the WebPart with the specified id, or the GenericWebPart containing a control with
/// the specified id, or the ProxyWebPart with OriginalID or GenericWebPartID equal to the
/// specified id, performing a case-insensitive comparison. Returns null if there are no matches.
///
public WebPart this[string id] {
// PERF: Use a hashtable for lookup, instead of a linear search
get {
foreach (WebPart webPart in InnerList) {
if (String.Equals(webPart.ID, id, StringComparison.OrdinalIgnoreCase)) {
return webPart;
}
GenericWebPart genericWebPart = webPart as GenericWebPart;
if (genericWebPart != null) {
Control control = genericWebPart.ChildControl;
if (control != null) {
if (String.Equals(control.ID, id, StringComparison.OrdinalIgnoreCase)) {
return genericWebPart;
}
}
}
ProxyWebPart proxyWebPart = webPart as ProxyWebPart;
if (proxyWebPart != null) {
if ((String.Equals(proxyWebPart.OriginalID, id, StringComparison.OrdinalIgnoreCase)) ||
(String.Equals(proxyWebPart.GenericWebPartID, id, StringComparison.OrdinalIgnoreCase))) {
return proxyWebPart;
}
}
}
return null;
}
}
///
/// Copies contents from the collection to a specified array with a
/// specified starting index.
///
public void CopyTo(WebPart[] array, int index) {
InnerList.CopyTo(array, index);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
///
/// Read-only collection of WebParts. Collection cannot be modified after contstruction.
///
public sealed class WebPartCollection : ReadOnlyCollectionBase {
public WebPartCollection() {
}
public WebPartCollection(ICollection webParts) {
if (webParts == null) {
throw new ArgumentNullException("webParts");
}
foreach (object obj in webParts) {
if (obj == null) {
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "webParts");
}
if (!(obj is WebPart)) {
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "WebPart"), "webParts");
}
InnerList.Add(obj);
}
}
internal int Add(WebPart value) {
Debug.Assert(value != null);
return InnerList.Add(value);
}
public bool Contains(WebPart value) {
return InnerList.Contains(value);
}
public int IndexOf(WebPart value) {
return InnerList.IndexOf(value);
}
public WebPart this[int index] {
get {
return (WebPart) InnerList[index];
}
}
///
/// Returns the WebPart with the specified id, or the GenericWebPart containing a control with
/// the specified id, or the ProxyWebPart with OriginalID or GenericWebPartID equal to the
/// specified id, performing a case-insensitive comparison. Returns null if there are no matches.
///
public WebPart this[string id] {
// PERF: Use a hashtable for lookup, instead of a linear search
get {
foreach (WebPart webPart in InnerList) {
if (String.Equals(webPart.ID, id, StringComparison.OrdinalIgnoreCase)) {
return webPart;
}
GenericWebPart genericWebPart = webPart as GenericWebPart;
if (genericWebPart != null) {
Control control = genericWebPart.ChildControl;
if (control != null) {
if (String.Equals(control.ID, id, StringComparison.OrdinalIgnoreCase)) {
return genericWebPart;
}
}
}
ProxyWebPart proxyWebPart = webPart as ProxyWebPart;
if (proxyWebPart != null) {
if ((String.Equals(proxyWebPart.OriginalID, id, StringComparison.OrdinalIgnoreCase)) ||
(String.Equals(proxyWebPart.GenericWebPartID, id, StringComparison.OrdinalIgnoreCase))) {
return proxyWebPart;
}
}
}
return null;
}
}
///
/// Copies contents from the collection to a specified array with a
/// specified starting index.
///
public void CopyTo(WebPart[] array, int index) {
InnerList.CopyTo(array, index);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AdornerLayer.cs
- StrokeNodeOperations.cs
- PathSegment.cs
- FileDialogCustomPlace.cs
- KnownAssembliesSet.cs
- TextBounds.cs
- UIElementParagraph.cs
- ConfigXmlAttribute.cs
- RotateTransform3D.cs
- SelectionRange.cs
- FigureHelper.cs
- _AcceptOverlappedAsyncResult.cs
- HtmlInputCheckBox.cs
- DeploymentSectionCache.cs
- ProviderUtil.cs
- DesignerToolboxInfo.cs
- CompilerErrorCollection.cs
- TextBox.cs
- UnsafeNativeMethodsTablet.cs
- ResourceWriter.cs
- WorkerRequest.cs
- DeploymentExceptionMapper.cs
- TypeLoadException.cs
- InvokeHandlers.cs
- VariantWrapper.cs
- UriTemplateVariablePathSegment.cs
- RTLAwareMessageBox.cs
- KeyedPriorityQueue.cs
- ArraySortHelper.cs
- FocusWithinProperty.cs
- NumericExpr.cs
- ParagraphVisual.cs
- CompiledXpathExpr.cs
- TemplateKeyConverter.cs
- Model3D.cs
- WebPartEditorOkVerb.cs
- ObsoleteAttribute.cs
- WmlPageAdapter.cs
- ComponentChangingEvent.cs
- CodeSubDirectoriesCollection.cs
- TemplatedWizardStep.cs
- SqlBinder.cs
- ValueQuery.cs
- ManipulationStartingEventArgs.cs
- DataViewListener.cs
- ToolBar.cs
- OleDbCommand.cs
- validationstate.cs
- ZipIOExtraFieldZip64Element.cs
- AutomationPatternInfo.cs
- PropertyInfo.cs
- GlyphShapingProperties.cs
- SQLInt32.cs
- RuleSetDialog.Designer.cs
- ParenthesizePropertyNameAttribute.cs
- InspectionWorker.cs
- RowUpdatingEventArgs.cs
- RepeaterItem.cs
- Properties.cs
- WithStatement.cs
- ActivitySurrogateSelector.cs
- TextParentUndoUnit.cs
- CryptographicAttribute.cs
- ReflectionServiceProvider.cs
- AutoGeneratedFieldProperties.cs
- SingleObjectCollection.cs
- XsltOutput.cs
- XmlSchemaInferenceException.cs
- Queue.cs
- StickyNoteAnnotations.cs
- HebrewNumber.cs
- SingleObjectCollection.cs
- ColorAnimationBase.cs
- AutomationPropertyInfo.cs
- RIPEMD160Managed.cs
- StaticSiteMapProvider.cs
- DbQueryCommandTree.cs
- CodeTypeMemberCollection.cs
- HtmlInputRadioButton.cs
- VariableQuery.cs
- XmlRawWriterWrapper.cs
- EntityCommandDefinition.cs
- WebPartDisplayModeCancelEventArgs.cs
- WebPartDescriptionCollection.cs
- SectionVisual.cs
- ResourceProperty.cs
- EntityProxyTypeInfo.cs
- WebResourceAttribute.cs
- XmlWellformedWriter.cs
- DataComponentMethodGenerator.cs
- ServiceErrorHandler.cs
- DesignerActionVerbItem.cs
- ListChangedEventArgs.cs
- ElementHostAutomationPeer.cs
- GlobalItem.cs
- Documentation.cs
- CodeAttributeDeclaration.cs
- ResXFileRef.cs
- NetworkInformationPermission.cs
- Merger.cs