Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Serialization / System / Xml / XmlBinaryReaderSession.cs / 1 / XmlBinaryReaderSession.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using StringHandle = System.Int64; namespace System.Xml { using System.Xml; using System.Collections.Generic; using System.Runtime.Serialization; public class XmlBinaryReaderSession : IXmlDictionary { const int MaxArrayEntries = 2048; XmlDictionaryString[] strings; DictionarystringDict; public XmlBinaryReaderSession() { } public XmlDictionaryString Add(int id, string value) { if (id < 0) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(SR.GetString(SR.XmlInvalidID))); if (value == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); XmlDictionaryString xmlString; if (TryLookup(id, out xmlString)) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlIDDefined))); xmlString = new XmlDictionaryString(this, value, id); if (id >= MaxArrayEntries) { if (stringDict == null) this.stringDict = new Dictionary (); this.stringDict.Add(id, xmlString); } else { if (strings == null) { strings = new XmlDictionaryString[Math.Max(id + 1, 16)]; } else if (id >= strings.Length) { XmlDictionaryString[] newStrings = new XmlDictionaryString[Math.Min(Math.Max(id + 1, strings.Length * 2), MaxArrayEntries)]; Array.Copy(strings, newStrings, strings.Length); strings = newStrings; } strings[id] = xmlString; } return xmlString; } public bool TryLookup(int key, out XmlDictionaryString result) { if (strings != null && key >= 0 && key < strings.Length) { result = strings[key]; return result != null; } else if (key >= MaxArrayEntries) { if (this.stringDict != null) return this.stringDict.TryGetValue(key, out result); } result = null; return false; } public bool TryLookup(string value, out XmlDictionaryString result) { if (value == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); if (strings != null) { for (int i = 0; i < strings.Length; i++) { XmlDictionaryString s = strings[i]; if (s != null && s.Value == value) { result = s; return true; } } } if (this.stringDict != null) { foreach (XmlDictionaryString s in this.stringDict.Values) { if (s.Value == value) { result = s; return true; } } } result = null; return false; } public 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; } public void Clear() { if (strings != null) Array.Clear(strings, 0, strings.Length); if (this.stringDict != null) this.stringDict.Clear(); } } } // 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
- ImageKeyConverter.cs
- AsnEncodedData.cs
- HtmlInputSubmit.cs
- InheritanceContextHelper.cs
- WrappedIUnknown.cs
- IPAddressCollection.cs
- UpWmlMobileTextWriter.cs
- DefaultValueAttribute.cs
- PackageRelationshipCollection.cs
- XmlWrappingReader.cs
- _SslState.cs
- WebUtil.cs
- DetailsViewRow.cs
- NonClientArea.cs
- RequestCacheManager.cs
- PageCatalogPartDesigner.cs
- OutputCacheSection.cs
- UmAlQuraCalendar.cs
- BadImageFormatException.cs
- IndexedString.cs
- HostingEnvironment.cs
- ApplicationServiceHelper.cs
- JoinSymbol.cs
- Transform3D.cs
- FileSystemEventArgs.cs
- IncrementalReadDecoders.cs
- IisTraceListener.cs
- DataServiceHostWrapper.cs
- TypeUtils.cs
- TreeViewDesigner.cs
- StylusPointProperty.cs
- XmlNamedNodeMap.cs
- DispatchOperationRuntime.cs
- UpDownEvent.cs
- InstanceLockLostException.cs
- ContextMenu.cs
- CompilerErrorCollection.cs
- CompilerInfo.cs
- Transform3D.cs
- SecurityCriticalDataForSet.cs
- OLEDB_Enum.cs
- EditingCoordinator.cs
- VScrollProperties.cs
- SerializationInfoEnumerator.cs
- ExtensibleSyndicationObject.cs
- MsmqInputMessage.cs
- FlowDocumentReaderAutomationPeer.cs
- SecurityProtocolFactory.cs
- BeginEvent.cs
- InternalBufferManager.cs
- CompositeScriptReferenceEventArgs.cs
- TriggerAction.cs
- SchemaNamespaceManager.cs
- TemplatePropertyEntry.cs
- HttpModule.cs
- LayoutDump.cs
- SequenceDesigner.cs
- LambdaCompiler.Expressions.cs
- ellipse.cs
- InplaceBitmapMetadataWriter.cs
- WmpBitmapDecoder.cs
- AppliesToBehaviorDecisionTable.cs
- DataGridTable.cs
- TextTreeExtractElementUndoUnit.cs
- XmlSchemaImporter.cs
- Matrix3DStack.cs
- FormsAuthenticationModule.cs
- EncodingDataItem.cs
- UseLicense.cs
- HttpPostServerProtocol.cs
- ComIntegrationManifestGenerator.cs
- Matrix3D.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- StringInfo.cs
- HtmlButton.cs
- BamlResourceSerializer.cs
- LocalizationComments.cs
- TimeoutException.cs
- TextTrailingWordEllipsis.cs
- ConfigXmlCDataSection.cs
- CryptoConfig.cs
- TempEnvironment.cs
- DragDeltaEventArgs.cs
- SafeHandle.cs
- oledbconnectionstring.cs
- FastPropertyAccessor.cs
- SpecularMaterial.cs
- StringReader.cs
- UrlParameterWriter.cs
- ContextMenu.cs
- EmptyStringExpandableObjectConverter.cs
- AuthenticationService.cs
- DataContractSerializerMessageContractImporter.cs
- XAMLParseException.cs
- ArglessEventHandlerProxy.cs
- MaskedTextProvider.cs
- NetworkInformationException.cs
- XamlRtfConverter.cs
- HtmlTernaryTree.cs
- SplashScreenNativeMethods.cs