Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / WebParts / WebPartCollection.cs / 1 / 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;
using System.Security.Permissions;
///
/// Read-only collection of WebParts. Collection cannot be modified after contstruction.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
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;
using System.Security.Permissions;
///
/// Read-only collection of WebParts. Collection cannot be modified after contstruction.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
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
- WebRequestModuleElementCollection.cs
- InputGestureCollection.cs
- DataServiceRequestOfT.cs
- XmlDataSourceView.cs
- HtmlInputButton.cs
- sitestring.cs
- MailDefinitionBodyFileNameEditor.cs
- GridItem.cs
- SimpleTypeResolver.cs
- HttpPostedFileWrapper.cs
- SpecularMaterial.cs
- SqlBulkCopy.cs
- ColorConverter.cs
- DeliveryRequirementsAttribute.cs
- HttpResponse.cs
- ToggleProviderWrapper.cs
- BamlVersionHeader.cs
- DataGridViewCellStyleEditor.cs
- XsdDataContractImporter.cs
- LinqDataSourceSelectEventArgs.cs
- AnnouncementInnerClientCD1.cs
- TypeRestriction.cs
- AuthorizationRule.cs
- DeleteWorkflowOwnerCommand.cs
- DocumentStatusResources.cs
- Cursors.cs
- DataSourceCacheDurationConverter.cs
- VScrollProperties.cs
- COAUTHINFO.cs
- BinaryKeyIdentifierClause.cs
- DataExpression.cs
- ParseChildrenAsPropertiesAttribute.cs
- TrackingProfileCache.cs
- EntityDesignerDataSourceView.cs
- TimeStampChecker.cs
- RegexStringValidator.cs
- VectorCollectionConverter.cs
- InputProcessorProfilesLoader.cs
- SimpleMailWebEventProvider.cs
- GPRECTF.cs
- bindurihelper.cs
- Validator.cs
- QueryCacheManager.cs
- HTMLTextWriter.cs
- TreeNodeCollection.cs
- Selection.cs
- LookupNode.cs
- DataGridViewTextBoxEditingControl.cs
- IisTraceListener.cs
- securitymgrsite.cs
- WebPartCloseVerb.cs
- Base64Encoder.cs
- BooleanSwitch.cs
- OrderedDictionary.cs
- FileUpload.cs
- Logging.cs
- HttpEncoderUtility.cs
- HelpEvent.cs
- ValueType.cs
- LocalizationComments.cs
- TraceFilter.cs
- ContentElementCollection.cs
- LazyTextWriterCreator.cs
- AvtEvent.cs
- ComponentResourceKeyConverter.cs
- XmlSortKey.cs
- Int32Collection.cs
- SemanticBasicElement.cs
- CancelRequestedRecord.cs
- RecognizeCompletedEventArgs.cs
- RadioButtonStandardAdapter.cs
- QueryMath.cs
- XhtmlTextWriter.cs
- BStrWrapper.cs
- TraceSection.cs
- BinaryUtilClasses.cs
- ListViewEditEventArgs.cs
- CreateUserWizardStep.cs
- WebZone.cs
- EntityDataSourceChangedEventArgs.cs
- DbConnectionStringBuilder.cs
- SafeFileMappingHandle.cs
- ComponentRenameEvent.cs
- SizeF.cs
- BrowserPolicyValidator.cs
- ParallelTimeline.cs
- LinkConverter.cs
- RealizationContext.cs
- Dispatcher.cs
- _ShellExpression.cs
- BeginEvent.cs
- HyperLink.cs
- DataServiceRequestException.cs
- ArrayWithOffset.cs
- TabControlAutomationPeer.cs
- ComIntegrationManifestGenerator.cs
- SerializationFieldInfo.cs
- TextElementCollection.cs
- ElementUtil.cs
- SettingsPropertyCollection.cs