Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / System / Diagnostics / SourceElementsCollection.cs / 1 / SourceElementsCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System.Configuration; using System.Collections; using System.Collections.Specialized; using System.Xml; namespace System.Diagnostics { [ConfigurationCollection(typeof(SourceElement), AddItemName = "source", CollectionType = ConfigurationElementCollectionType.BasicMap)] internal class SourceElementsCollection : ConfigurationElementCollection { new public SourceElement this[string name] { get { return (SourceElement) BaseGet(name); } } protected override string ElementName { get { return "source"; } } public override ConfigurationElementCollectionType CollectionType { get { return ConfigurationElementCollectionType.BasicMap; } } protected override ConfigurationElement CreateNewElement() { SourceElement se = new SourceElement(); se.Listeners.InitializeDefaultInternal(); return se; } protected override Object GetElementKey(ConfigurationElement element) { return ((SourceElement) element).Name; } } internal class SourceElement : ConfigurationElement { private static readonly ConfigurationPropertyCollection _properties; private static readonly ConfigurationProperty _propName = new ConfigurationProperty("name", typeof(string), "", ConfigurationPropertyOptions.IsRequired); private static readonly ConfigurationProperty _propSwitchName = new ConfigurationProperty("switchName", typeof(string), null, ConfigurationPropertyOptions.None); private static readonly ConfigurationProperty _propSwitchValue = new ConfigurationProperty("switchValue", typeof(string), null, ConfigurationPropertyOptions.None); private static readonly ConfigurationProperty _propSwitchType = new ConfigurationProperty("switchType", typeof(string), null, ConfigurationPropertyOptions.None); private static readonly ConfigurationProperty _propListeners = new ConfigurationProperty("listeners", typeof(ListenerElementsCollection), new ListenerElementsCollection(), ConfigurationPropertyOptions.None); private Hashtable _attributes; static SourceElement() { _properties = new ConfigurationPropertyCollection(); _properties.Add(_propName); _properties.Add(_propSwitchName); _properties.Add(_propSwitchValue); _properties.Add(_propSwitchType); _properties.Add(_propListeners); } public Hashtable Attributes { get { if (_attributes == null) _attributes = new Hashtable(StringComparer.OrdinalIgnoreCase); return _attributes; } } [ConfigurationProperty("listeners")] public ListenerElementsCollection Listeners { get { return (ListenerElementsCollection) this[_propListeners]; } } [ConfigurationProperty("name", IsRequired=true, DefaultValue="")] public string Name { get { return (string) this[_propName]; } } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } [ConfigurationProperty("switchName")] public string SwitchName { get { return (string) this[_propSwitchName]; } } [ConfigurationProperty("switchValue")] public string SwitchValue { get { return (string) this[_propSwitchValue]; } } [ConfigurationProperty("switchType")] public string SwitchType { get { return (string) this[_propSwitchType]; } } protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { base.DeserializeElement(reader, serializeCollectionKey); if (!String.IsNullOrEmpty(SwitchName) && !String.IsNullOrEmpty(SwitchValue)) throw new ConfigurationErrorsException(SR.GetString(SR.Only_specify_one, Name)); } protected override bool OnDeserializeUnrecognizedAttribute(String name, String value) { ConfigurationProperty _propDynamic = new ConfigurationProperty(name, typeof(string), value); _properties.Add(_propDynamic); base[_propDynamic] = value; // Add them to the property bag Attributes.Add(name, value); return true; } internal void ResetProperties() { // blow away any UnrecognizedAttributes that we have deserialized earlier if (_attributes != null) { _attributes.Clear(); _properties.Clear(); _properties.Add(_propName); _properties.Add(_propSwitchName); _properties.Add(_propSwitchValue); _properties.Add(_propSwitchType); _properties.Add(_propListeners); } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextDecorationCollection.cs
- ErrorTableItemStyle.cs
- DataListItemCollection.cs
- XmlAttributeCollection.cs
- EpmTargetTree.cs
- Select.cs
- FontResourceCache.cs
- Size3DConverter.cs
- PrimarySelectionGlyph.cs
- IRCollection.cs
- ConnectionOrientedTransportElement.cs
- TypeReference.cs
- ProgressBarBrushConverter.cs
- IPipelineRuntime.cs
- OleDbRowUpdatedEvent.cs
- ThicknessAnimation.cs
- TypeUnloadedException.cs
- COM2FontConverter.cs
- HwndSource.cs
- BindingNavigator.cs
- Avt.cs
- AssemblyAttributes.cs
- ExpressionBuilderCollection.cs
- BinarySerializer.cs
- HwndSourceParameters.cs
- Environment.cs
- GrammarBuilderPhrase.cs
- COM2PropertyPageUITypeConverter.cs
- PowerEase.cs
- CompressEmulationStream.cs
- RoleManagerEventArgs.cs
- ProjectionPlan.cs
- __ConsoleStream.cs
- Annotation.cs
- _NtlmClient.cs
- StrokeNodeData.cs
- SecurityVersion.cs
- LocatorPartList.cs
- DataMemberConverter.cs
- SectionVisual.cs
- RenderOptions.cs
- ParameterCollection.cs
- CodeParameterDeclarationExpression.cs
- JavascriptCallbackMessageInspector.cs
- ScrollChrome.cs
- ScrollEvent.cs
- DeviceContext.cs
- ApplicationProxyInternal.cs
- SessionPageStateSection.cs
- FilterException.cs
- TypeExtensionSerializer.cs
- TextTreeRootNode.cs
- OpCopier.cs
- GridItemCollection.cs
- DataView.cs
- StoragePropertyMapping.cs
- FixedBufferAttribute.cs
- URLAttribute.cs
- SubclassTypeValidator.cs
- DataGridTablesFactory.cs
- Int16AnimationUsingKeyFrames.cs
- FontSourceCollection.cs
- RequestSecurityToken.cs
- StylusDevice.cs
- ListDataBindEventArgs.cs
- Annotation.cs
- DesigntimeLicenseContext.cs
- PeerSecurityHelpers.cs
- VisualTreeUtils.cs
- ConfigUtil.cs
- arabicshape.cs
- FocusTracker.cs
- ReliableSessionBindingElement.cs
- NameTable.cs
- PrintingPermissionAttribute.cs
- TextComposition.cs
- LabelLiteral.cs
- RepeatBehaviorConverter.cs
- EntityCommandExecutionException.cs
- PrtCap_Public_Simple.cs
- ToolStripDropDown.cs
- ConnectionPoint.cs
- DiscardableAttribute.cs
- CodeDefaultValueExpression.cs
- WmlValidationSummaryAdapter.cs
- TraceLog.cs
- SspiWrapper.cs
- AccessibleObject.cs
- QueryOperationResponseOfT.cs
- ServiceSecurityAuditElement.cs
- Event.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- WsatServiceAddress.cs
- Crypto.cs
- MetaModel.cs
- ModulesEntry.cs
- SkewTransform.cs
- TargetInvocationException.cs
- StorageComplexPropertyMapping.cs
- WhitespaceSignificantCollectionAttribute.cs