Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / XmlAttributeHolder.cs / 1305376 / XmlAttributeHolder.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.Xml; struct XmlAttributeHolder { string prefix; string ns; string localName; string value; public static XmlAttributeHolder[] emptyArray = new XmlAttributeHolder[0]; public XmlAttributeHolder(string prefix, string localName, string ns, string value) { this.prefix = prefix; this.localName = localName; this.ns = ns; this.value = value; } public string Prefix { get { return prefix; } } public string NamespaceUri { get { return ns; } } public string LocalName { get { return localName; } } public string Value { get { return value; } } public void WriteTo(XmlWriter writer) { writer.WriteStartAttribute(prefix, localName, ns); writer.WriteString(value); writer.WriteEndAttribute(); } public static void WriteAttributes(XmlAttributeHolder[] attributes, XmlWriter writer) { for (int i = 0; i < attributes.Length; i++) attributes[i].WriteTo(writer); } public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader) { int maxSizeOfHeaders = int.MaxValue; return ReadAttributes(reader, ref maxSizeOfHeaders); } public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) return emptyArray; XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < attributes.Length; i++) { string ns = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string value = string.Empty; while (reader.ReadAttributeValue()) { if (value.Length == 0) value = reader.Value; else value += reader.Value; } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(ns, ref maxSizeOfHeaders); Deduct(value, ref maxSizeOfHeaders); attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value); reader.MoveToNextAttribute(); } reader.MoveToElement(); return attributes; } static void Deduct(string s, ref int maxSizeOfHeaders) { int byteCount = s.Length * sizeof(char); if (byteCount > maxSizeOfHeaders) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlBufferQuotaExceeded))); } maxSizeOfHeaders -= byteCount; } public static string GetAttribute(XmlAttributeHolder[] attributes, string localName, string ns) { for (int i = 0; i < attributes.Length; i++) if (attributes[i].LocalName == localName && attributes[i].NamespaceUri == ns) return attributes[i].Value; return null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.Xml; struct XmlAttributeHolder { string prefix; string ns; string localName; string value; public static XmlAttributeHolder[] emptyArray = new XmlAttributeHolder[0]; public XmlAttributeHolder(string prefix, string localName, string ns, string value) { this.prefix = prefix; this.localName = localName; this.ns = ns; this.value = value; } public string Prefix { get { return prefix; } } public string NamespaceUri { get { return ns; } } public string LocalName { get { return localName; } } public string Value { get { return value; } } public void WriteTo(XmlWriter writer) { writer.WriteStartAttribute(prefix, localName, ns); writer.WriteString(value); writer.WriteEndAttribute(); } public static void WriteAttributes(XmlAttributeHolder[] attributes, XmlWriter writer) { for (int i = 0; i < attributes.Length; i++) attributes[i].WriteTo(writer); } public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader) { int maxSizeOfHeaders = int.MaxValue; return ReadAttributes(reader, ref maxSizeOfHeaders); } public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) return emptyArray; XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < attributes.Length; i++) { string ns = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string value = string.Empty; while (reader.ReadAttributeValue()) { if (value.Length == 0) value = reader.Value; else value += reader.Value; } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(ns, ref maxSizeOfHeaders); Deduct(value, ref maxSizeOfHeaders); attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value); reader.MoveToNextAttribute(); } reader.MoveToElement(); return attributes; } static void Deduct(string s, ref int maxSizeOfHeaders) { int byteCount = s.Length * sizeof(char); if (byteCount > maxSizeOfHeaders) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlBufferQuotaExceeded))); } maxSizeOfHeaders -= byteCount; } public static string GetAttribute(XmlAttributeHolder[] attributes, string localName, string ns) { for (int i = 0; i < attributes.Length; i++) if (attributes[i].LocalName == localName && attributes[i].NamespaceUri == ns) return attributes[i].Value; return null; } } } // 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
- ScrollProperties.cs
- EdmTypeAttribute.cs
- IncrementalHitTester.cs
- OptimisticConcurrencyException.cs
- CodeParameterDeclarationExpressionCollection.cs
- PhysicalAddress.cs
- LocatorGroup.cs
- WebPartUtil.cs
- XmlAttributeCache.cs
- ScriptResourceInfo.cs
- VectorKeyFrameCollection.cs
- DbMetaDataColumnNames.cs
- dsa.cs
- LowerCaseStringConverter.cs
- DockingAttribute.cs
- DataBinder.cs
- ImageClickEventArgs.cs
- DecoderExceptionFallback.cs
- ModulesEntry.cs
- XmlSchemaDocumentation.cs
- FormatSettings.cs
- DefaultValueTypeConverter.cs
- DispatcherExceptionEventArgs.cs
- DesignerRegionMouseEventArgs.cs
- ParallelTimeline.cs
- FlowNode.cs
- TextElementAutomationPeer.cs
- ActivityMetadata.cs
- SimpleExpression.cs
- _UriTypeConverter.cs
- Expander.cs
- DrawItemEvent.cs
- AssertSection.cs
- DiscoveryServiceExtension.cs
- CodeNamespaceImportCollection.cs
- CollectionChangedEventManager.cs
- FragmentQueryKB.cs
- UpdateDelegates.Generated.cs
- AudioStateChangedEventArgs.cs
- EnvironmentPermission.cs
- DBCommand.cs
- DbConnectionPoolOptions.cs
- LineGeometry.cs
- EntityCommandExecutionException.cs
- TrimSurroundingWhitespaceAttribute.cs
- SmiRequestExecutor.cs
- SettingsSection.cs
- SQlBooleanStorage.cs
- StylusEditingBehavior.cs
- ResourceSet.cs
- AbandonedMutexException.cs
- RoutedEventArgs.cs
- ISAPIRuntime.cs
- ApplicationServiceHelper.cs
- AttributeSetAction.cs
- SecurityChannel.cs
- webproxy.cs
- AdRotator.cs
- InstanceLockedException.cs
- SimpleWorkerRequest.cs
- DocobjHost.cs
- CacheAxisQuery.cs
- BitmapImage.cs
- MethodBuilderInstantiation.cs
- DetailsView.cs
- HttpPostedFile.cs
- DescendentsWalkerBase.cs
- Geometry3D.cs
- GeneralTransform3D.cs
- DesignSurfaceEvent.cs
- ListView.cs
- DefaultAsyncDataDispatcher.cs
- GridViewColumnCollectionChangedEventArgs.cs
- MD5CryptoServiceProvider.cs
- BoolLiteral.cs
- SynchronousChannel.cs
- FormViewPageEventArgs.cs
- DoubleCollection.cs
- ExpressionVisitor.cs
- RestHandler.cs
- TemplateControl.cs
- Model3DCollection.cs
- TextBounds.cs
- CompilerParameters.cs
- MarkupObject.cs
- GridItemCollection.cs
- MimeTypeAttribute.cs
- ConfigLoader.cs
- XmlSchemaAnnotation.cs
- SerializationTrace.cs
- WorkingDirectoryEditor.cs
- Context.cs
- Pool.cs
- SystemIcmpV6Statistics.cs
- WsdlInspector.cs
- ToolStripProgressBar.cs
- TileBrush.cs
- SQLByte.cs
- RegexCapture.cs
- ConnectionStringsExpressionEditor.cs