Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Serialization / System / Xml / XmlDictionary.cs / 1305376 / XmlDictionary.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Xml { using System; using System.IO; using System.Xml; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Runtime.Serialization; public class XmlDictionary : IXmlDictionary { static IXmlDictionary empty; Dictionarylookup; XmlDictionaryString[] strings; int nextId; static public IXmlDictionary Empty { get { if (empty == null) empty = new EmptyDictionary(); return empty; } } public XmlDictionary() { this.lookup = new Dictionary (); this.strings = null; this.nextId = 0; } public XmlDictionary(int capacity) { this.lookup = new Dictionary (capacity); this.strings = new XmlDictionaryString[capacity]; this.nextId = 0; } public virtual XmlDictionaryString Add(string value) { XmlDictionaryString str; if (!this.lookup.TryGetValue(value, out str)) { if (this.strings == null) { this.strings = new XmlDictionaryString[4]; } else if (this.nextId == this.strings.Length) { int newSize = this.nextId * 2; if (newSize == 0) newSize = 4; Array.Resize(ref this.strings, newSize); } str = new XmlDictionaryString(this, value, this.nextId); this.strings[this.nextId] = str; this.lookup.Add(value, str); this.nextId++; } return str; } public virtual bool TryLookup(string value, out XmlDictionaryString result) { return this.lookup.TryGetValue(value, out result); } public virtual bool TryLookup(int key, out XmlDictionaryString result) { if (key < 0 || key >= this.nextId) { result = null; return false; } result = this.strings[key]; return true; } public virtual bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result) { if (value == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("value")); if (value.Dictionary != this) { result = null; return false; } result = value; return true; } class EmptyDictionary : IXmlDictionary { public bool TryLookup(string value, out XmlDictionaryString result) { result = null; return false; } public bool TryLookup(int key, out XmlDictionaryString result) { result = null; return false; } public bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result) { result = null; return false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Xml { using System; using System.IO; using System.Xml; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Runtime.Serialization; public class XmlDictionary : IXmlDictionary { static IXmlDictionary empty; Dictionary lookup; XmlDictionaryString[] strings; int nextId; static public IXmlDictionary Empty { get { if (empty == null) empty = new EmptyDictionary(); return empty; } } public XmlDictionary() { this.lookup = new Dictionary (); this.strings = null; this.nextId = 0; } public XmlDictionary(int capacity) { this.lookup = new Dictionary (capacity); this.strings = new XmlDictionaryString[capacity]; this.nextId = 0; } public virtual XmlDictionaryString Add(string value) { XmlDictionaryString str; if (!this.lookup.TryGetValue(value, out str)) { if (this.strings == null) { this.strings = new XmlDictionaryString[4]; } else if (this.nextId == this.strings.Length) { int newSize = this.nextId * 2; if (newSize == 0) newSize = 4; Array.Resize(ref this.strings, newSize); } str = new XmlDictionaryString(this, value, this.nextId); this.strings[this.nextId] = str; this.lookup.Add(value, str); this.nextId++; } return str; } public virtual bool TryLookup(string value, out XmlDictionaryString result) { return this.lookup.TryGetValue(value, out result); } public virtual bool TryLookup(int key, out XmlDictionaryString result) { if (key < 0 || key >= this.nextId) { result = null; return false; } result = this.strings[key]; return true; } public virtual bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result) { if (value == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("value")); if (value.Dictionary != this) { result = null; return false; } result = value; return true; } class EmptyDictionary : IXmlDictionary { public bool TryLookup(string value, out XmlDictionaryString result) { result = null; return false; } public bool TryLookup(int key, out XmlDictionaryString result) { result = null; return false; } public bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result) { result = null; return false; } } } } // 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
- PathData.cs
- WebContext.cs
- PartitionResolver.cs
- ListViewDataItem.cs
- ClientUrlResolverWrapper.cs
- MaterialGroup.cs
- Rect.cs
- Vector3dCollection.cs
- InfoCardTraceRecord.cs
- TrackingRecord.cs
- ActivityDesignerHelper.cs
- ConfigXmlWhitespace.cs
- DataRowCollection.cs
- CatalogPartChrome.cs
- CustomAttributeSerializer.cs
- MinMaxParagraphWidth.cs
- MessageHeaders.cs
- ColorMatrix.cs
- EventlogProvider.cs
- ResXDataNode.cs
- _ShellExpression.cs
- CallInfo.cs
- MessageCredentialType.cs
- ResourceBinder.cs
- CodeDirectionExpression.cs
- Identifier.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- StorageMappingFragment.cs
- InstanceOwner.cs
- WindowsListView.cs
- TextAnchor.cs
- WindowsRichEditRange.cs
- DefaultPropertyAttribute.cs
- StringDictionaryWithComparer.cs
- StylusDevice.cs
- IApplicationTrustManager.cs
- RunWorkerCompletedEventArgs.cs
- Switch.cs
- PeerReferralPolicy.cs
- EntityDesignerBuildProvider.cs
- AbsoluteQuery.cs
- BrushMappingModeValidation.cs
- ConstructorArgumentAttribute.cs
- DataViewSettingCollection.cs
- XamlToRtfWriter.cs
- OperandQuery.cs
- webbrowsersite.cs
- Double.cs
- EncodingInfo.cs
- KeyInterop.cs
- ComUdtElement.cs
- SqlFunctionAttribute.cs
- LocalizedNameDescriptionPair.cs
- ThousandthOfEmRealPoints.cs
- RtfControls.cs
- DataControlHelper.cs
- IntranetCredentialPolicy.cs
- AttachInfo.cs
- CancelEventArgs.cs
- complextypematerializer.cs
- TemplateModeChangedEventArgs.cs
- GridViewColumnHeader.cs
- EventWaitHandleSecurity.cs
- TextBoxLine.cs
- RSAPKCS1SignatureDeformatter.cs
- RequestQueryProcessor.cs
- VectorCollectionValueSerializer.cs
- PropertyGeneratedEventArgs.cs
- XamlReaderHelper.cs
- BindingList.cs
- UnaryNode.cs
- StringSorter.cs
- ColorConvertedBitmapExtension.cs
- EncoderNLS.cs
- MapPathBasedVirtualPathProvider.cs
- indexingfiltermarshaler.cs
- InkCanvasFeedbackAdorner.cs
- CodeAccessPermission.cs
- XmlElementList.cs
- PanelStyle.cs
- BinaryFormatterWriter.cs
- MetadataItemCollectionFactory.cs
- WebControlsSection.cs
- XmlExpressionDumper.cs
- CommandHelpers.cs
- ThreadSafeList.cs
- ComponentCommands.cs
- ItemCheckedEvent.cs
- SmiXetterAccessMap.cs
- AsymmetricAlgorithm.cs
- CombinedGeometry.cs
- InternalBufferOverflowException.cs
- TagPrefixAttribute.cs
- SubqueryRules.cs
- StructureChangedEventArgs.cs
- GridView.cs
- FieldAccessException.cs
- LogConverter.cs
- FixedBufferAttribute.cs
- DbBuffer.cs