Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Configuration / CustomBindingCollectionElement.cs / 1 / CustomBindingCollectionElement.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Configuration
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Globalization;
using System.ServiceModel;
using System.ServiceModel.Channels;
public sealed partial class CustomBindingCollectionElement : BindingCollectionElement
{
[ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
public CustomBindingElementCollection Bindings
{
get {return (CustomBindingElementCollection) base[ConfigurationStrings.DefaultCollectionName]; }
}
public override Type BindingType
{
get {return typeof(CustomBinding); }
}
public override ReadOnlyCollection ConfiguredBindings
{
get
{
List configuredBindings = new List();
foreach (IBindingConfigurationElement configuredBinding in this.Bindings)
{
configuredBindings.Add(configuredBinding);
}
return new ReadOnlyCollection(configuredBindings);
}
}
public override bool ContainsKey(string name)
{
// This line needed because of the IBindingSection implementation
return this.Bindings.ContainsKey(name);
}
protected internal override Binding GetDefault()
{
return System.Activator.CreateInstance();
}
internal static CustomBindingCollectionElement GetBindingCollectionElement()
{
return (CustomBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement(ConfigurationStrings.CustomBindingCollectionElementName);
}
bool TryCreateMatchingExtension(BindingElement bindingElement, ExtensionElementCollection collection, bool allowDerivedTypes, string assemblyName, out BindingElementExtensionElement result)
{
result = null;
foreach (ExtensionElement element in collection)
{
BindingElementExtensionElement bindingElementExtension = Activator.CreateInstance(Type.GetType(element.Type, true)) as BindingElementExtensionElement;
if (null == bindingElementExtension)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidExtensionType,
element.Type,
assemblyName,
ConfigurationStrings.BindingElementExtensions)));
}
bool isMatch;
if (allowDerivedTypes)
{
isMatch = bindingElementExtension.BindingElementType.IsAssignableFrom(bindingElement.GetType());
}
else
{
isMatch = bindingElementExtension.BindingElementType.Equals(bindingElement.GetType());
}
if (isMatch)
{
result = bindingElementExtension;
return true;
}
}
return false;
}
protected internal override bool TryAdd(string name, Binding binding, Configuration config)
{
if (String.IsNullOrEmpty(name))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
}
if (null == binding)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
}
if (null == config)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
}
ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);
CustomBindingElementCollection customBindings = sg.Bindings.CustomBinding.Bindings;
CustomBindingElement configElement = new CustomBindingElement(name);
customBindings.Add(configElement);
ExtensionElementCollection collection = sg.Extensions.BindingElementExtensions;
CustomBinding customBinding = (CustomBinding) binding;
foreach (BindingElement bindingElement in customBinding.Elements)
{
BindingElementExtensionElement bindingElementExtension;
bool foundMatch = TryCreateMatchingExtension(bindingElement, collection, false, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension);
if (!foundMatch)
{
foundMatch = TryCreateMatchingExtension(bindingElement, collection, true, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension);
}
if (!foundMatch)
{
break;
}
bindingElementExtension.InitializeFrom(bindingElement);
configElement.Add(bindingElementExtension);
}
bool retval = configElement.Count == customBinding.Elements.Count;
if (!retval)
{
customBindings.Remove(configElement);
}
return retval;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebPartZoneAutoFormat.cs
- DataTableClearEvent.cs
- ParameterInfo.cs
- ResolveCriteria.cs
- x509utils.cs
- ParentControlDesigner.cs
- ContainerUIElement3D.cs
- CatalogUtil.cs
- BuildResult.cs
- ConfigurationManagerInternal.cs
- BitmapImage.cs
- ConsumerConnectionPoint.cs
- CodeRemoveEventStatement.cs
- sitestring.cs
- StorageMappingItemLoader.cs
- UserUseLicenseDictionaryLoader.cs
- SourceSwitch.cs
- KoreanLunisolarCalendar.cs
- SpecialNameAttribute.cs
- BindingSource.cs
- GeneralTransform3D.cs
- ClientSettingsProvider.cs
- ColorKeyFrameCollection.cs
- XmlSchemaNotation.cs
- DeviceSpecificDesigner.cs
- CommentEmitter.cs
- WinEventHandler.cs
- DrawItemEvent.cs
- OutputCacheModule.cs
- ValidationEventArgs.cs
- ConnectionPoolManager.cs
- WaveHeader.cs
- OpCodes.cs
- MapPathBasedVirtualPathProvider.cs
- CacheRequest.cs
- XpsResource.cs
- WorkflowPageSetupDialog.cs
- SqlConnectionString.cs
- InputReport.cs
- ReturnEventArgs.cs
- AssemblyAssociatedContentFileAttribute.cs
- ValidationUtility.cs
- ExpandSegment.cs
- RegexGroupCollection.cs
- ViewgenContext.cs
- AudienceUriMode.cs
- RoleGroupCollection.cs
- sqlnorm.cs
- DesignerResources.cs
- BCryptHashAlgorithm.cs
- HtmlTableRowCollection.cs
- ComponentChangingEvent.cs
- MemoryStream.cs
- httpstaticobjectscollection.cs
- AutoGeneratedFieldProperties.cs
- DefaultBindingPropertyAttribute.cs
- PersonalizationEntry.cs
- RemotingAttributes.cs
- MobileRedirect.cs
- WindowsEditBoxRange.cs
- DesignTableCollection.cs
- CryptoApi.cs
- ItemContainerPattern.cs
- SliderAutomationPeer.cs
- HwndSourceKeyboardInputSite.cs
- Figure.cs
- OpacityConverter.cs
- ObjectTag.cs
- Int64.cs
- DecimalFormatter.cs
- CodeDomSerializerException.cs
- AssemblyResourceLoader.cs
- IItemContainerGenerator.cs
- ServiceHttpHandlerFactory.cs
- PropertyEmitterBase.cs
- OleCmdHelper.cs
- PagedDataSource.cs
- TypeForwardedToAttribute.cs
- Crc32Helper.cs
- SqlUnionizer.cs
- Exceptions.cs
- DesignerEditorPartChrome.cs
- ScrollEventArgs.cs
- Variable.cs
- ASCIIEncoding.cs
- TargetParameterCountException.cs
- WeakReference.cs
- WebAdminConfigurationHelper.cs
- MemberJoinTreeNode.cs
- SortExpressionBuilder.cs
- WebPartDeleteVerb.cs
- SoapAttributes.cs
- ThreadStateException.cs
- DataGridViewLinkCell.cs
- RequestUriProcessor.cs
- NotifyIcon.cs
- LinqExpressionNormalizer.cs
- RadioButtonPopupAdapter.cs
- ToolBarButton.cs
- MultiSelectRootGridEntry.cs