Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Serialization / System / Xml / XmlExceptionHelper.cs / 2 / XmlExceptionHelper.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System.Runtime.Serialization; ////using System.ServiceModel.Channels; using System.Globalization; namespace System.Xml { static class XmlExceptionHelper { static void ThrowXmlException(XmlDictionaryReader reader, string res) { ThrowXmlException(reader, res, null); } static void ThrowXmlException(XmlDictionaryReader reader, string res, string arg1) { ThrowXmlException(reader, res, arg1, null); } static void ThrowXmlException(XmlDictionaryReader reader, string res, string arg1, string arg2) { ThrowXmlException(reader, res, arg1, arg2, null); } static void ThrowXmlException(XmlDictionaryReader reader, string res, string arg1, string arg2, string arg3) { string s = SR.GetString(res, arg1, arg2, arg3); IXmlLineInfo lineInfo = reader as IXmlLineInfo; if (lineInfo != null && lineInfo.HasLineInfo()) { s += " " + SR.GetString(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition); } throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s)); } static public void ThrowXmlException(XmlDictionaryReader reader, XmlException exception) { string s = exception.Message; IXmlLineInfo lineInfo = reader as IXmlLineInfo; if (lineInfo != null && lineInfo.HasLineInfo()) { s += " " + SR.GetString(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition); } throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s)); } static string GetName(string prefix, string localName) { if (prefix.Length == 0) return localName; else return string.Concat(prefix, ":", localName); } static string GetWhatWasFound(XmlDictionaryReader reader) { if (reader.EOF) return SR.GetString(SR.XmlFoundEndOfFile); switch (reader.NodeType) { case XmlNodeType.Element: return SR.GetString(SR.XmlFoundElement, GetName(reader.Prefix, reader.LocalName), reader.NamespaceURI); case XmlNodeType.EndElement: return SR.GetString(SR.XmlFoundEndElement, GetName(reader.Prefix, reader.LocalName), reader.NamespaceURI); case XmlNodeType.Text: case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: return SR.GetString(SR.XmlFoundText, reader.Value); case XmlNodeType.Comment: return SR.GetString(SR.XmlFoundComment, reader.Value); case XmlNodeType.CDATA: return SR.GetString(SR.XmlFoundCData, reader.Value); } return SR.GetString(SR.XmlFoundNodeType, reader.NodeType); } static public void ThrowStartElementExpected(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlStartElementExpected, GetWhatWasFound(reader)); } static public void ThrowStartElementExpected(XmlDictionaryReader reader, string name) { ThrowXmlException(reader, SR.XmlStartElementNameExpected, name, GetWhatWasFound(reader)); } static public void ThrowStartElementExpected(XmlDictionaryReader reader, string localName, string ns) { ThrowXmlException(reader, SR.XmlStartElementLocalNameNsExpected, localName, ns, GetWhatWasFound(reader)); } static public void ThrowStartElementExpected(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns) { ThrowStartElementExpected(reader, XmlDictionaryString.GetString(localName), XmlDictionaryString.GetString(ns)); } static public void ThrowFullStartElementExpected(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlFullStartElementExpected, GetWhatWasFound(reader)); } static public void ThrowFullStartElementExpected(XmlDictionaryReader reader, string name) { ThrowXmlException(reader, SR.XmlFullStartElementNameExpected, name, GetWhatWasFound(reader)); } static public void ThrowFullStartElementExpected(XmlDictionaryReader reader, string localName, string ns) { ThrowXmlException(reader, SR.XmlFullStartElementLocalNameNsExpected, localName, ns, GetWhatWasFound(reader)); } static public void ThrowFullStartElementExpected(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns) { ThrowFullStartElementExpected(reader, XmlDictionaryString.GetString(localName), XmlDictionaryString.GetString(ns)); } static public void ThrowEndElementExpected(XmlDictionaryReader reader, string localName, string ns) { ThrowXmlException(reader, SR.XmlEndElementExpected, localName, ns, GetWhatWasFound(reader)); } static public void ThrowMaxStringContentLengthExceeded(XmlDictionaryReader reader, int maxStringContentLength) { ThrowXmlException(reader, SR.XmlMaxStringContentLengthExceeded, maxStringContentLength.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowMaxArrayLengthExceeded(XmlDictionaryReader reader, int maxArrayLength) { ThrowXmlException(reader, SR.XmlMaxArrayLengthExceeded, maxArrayLength.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(XmlDictionaryReader reader, int maxQuota) { ThrowXmlException(reader, SR.XmlMaxArrayLengthOrMaxItemsQuotaExceeded, maxQuota.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowMaxDepthExceeded(XmlDictionaryReader reader, int maxDepth) { ThrowXmlException(reader, SR.XmlMaxDepthExceeded, maxDepth.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowMaxBytesPerReadExceeded(XmlDictionaryReader reader, int maxBytesPerRead) { ThrowXmlException(reader, SR.XmlMaxBytesPerReadExceeded, maxBytesPerRead.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowMaxNameTableCharCountExceeded(XmlDictionaryReader reader, int maxNameTableCharCount) { ThrowXmlException(reader, SR.XmlMaxNameTableCharCountExceeded, maxNameTableCharCount.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowBase64DataExpected(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlBase64DataExpected, GetWhatWasFound(reader)); } static public void ThrowUndefinedPrefix(XmlDictionaryReader reader, string prefix) { ThrowXmlException(reader, SR.XmlUndefinedPrefix, prefix); } static public void ThrowProcessingInstructionNotSupported(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlProcessingInstructionNotSupported); } static public void ThrowInvalidXml(XmlDictionaryReader reader, byte b) { ThrowXmlException(reader, SR.XmlInvalidXmlByte, b.ToString("X2", CultureInfo.InvariantCulture)); } static public void ThrowUnexpectedEndOfFile(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlUnexpectedEndOfFile, ((XmlBaseReader) reader).GetOpenElements()); } static public void ThrowUnexpectedEndElement(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlUnexpectedEndElement); } static public void ThrowTokenExpected(XmlDictionaryReader reader, string expected, char found) { ThrowXmlException(reader, SR.XmlTokenExpected, expected, found.ToString()); } static public void ThrowTokenExpected(XmlDictionaryReader reader, string expected, string found) { ThrowXmlException(reader, SR.XmlTokenExpected, expected, found); } static public void ThrowInvalidCharRef(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidCharRef); } static public void ThrowTagMismatch(XmlDictionaryReader reader, string expectedPrefix, string expectedLocalName, string foundPrefix, string foundLocalName) { ThrowXmlException(reader, SR.XmlTagMismatch, GetName(expectedPrefix, expectedLocalName), GetName(foundPrefix, foundLocalName)); } static public void ThrowDuplicateXmlnsAttribute(XmlDictionaryReader reader, string localName, string ns) { string name; if (localName.Length == 0) name = "xmlns"; else name = "xmlns:" + localName; ThrowXmlException(reader, SR.XmlDuplicateAttribute, name, name, ns); } static public void ThrowDuplicateAttribute(XmlDictionaryReader reader, string prefix1, string prefix2, string localName, string ns) { ThrowXmlException(reader, SR.XmlDuplicateAttribute, GetName(prefix1, localName), GetName(prefix2, localName), ns); } static public void ThrowInvalidBinaryFormat(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidFormat); } static public void ThrowInvalidRootData(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidRootData); } static public void ThrowMultipleRootElements(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlMultipleRootElements); } static public void ThrowDeclarationNotFirst(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlDeclNotFirst); } static public void ThrowConversionOverflow(XmlDictionaryReader reader, string value, string type) { ThrowXmlException(reader, SR.XmlConversionOverflow, value, type); } static public void ThrowXmlDictionaryStringIDOutOfRange(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlDictionaryStringIDRange, XmlDictionaryString.MinKey.ToString(NumberFormatInfo.CurrentInfo), XmlDictionaryString.MaxKey.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowXmlDictionaryStringIDUndefinedStatic(XmlDictionaryReader reader, int key) { ThrowXmlException(reader, SR.XmlDictionaryStringIDUndefinedStatic, key.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowXmlDictionaryStringIDUndefinedSession(XmlDictionaryReader reader, int key) { ThrowXmlException(reader, SR.XmlDictionaryStringIDUndefinedSession, key.ToString(NumberFormatInfo.CurrentInfo)); } static public void ThrowEmptyNamespace(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlEmptyNamespaceRequiresNullPrefix); } static public XmlException CreateConversionException(string value, string type, Exception exception) { return new XmlException(SR.GetString(SR.XmlInvalidConversion, value, type), exception); } static public XmlException CreateEncodingException(byte[] buffer, int offset, int count, Exception exception) { return CreateEncodingException(new System.Text.UTF8Encoding(false, false).GetString(buffer, offset, count), exception); } static public XmlException CreateEncodingException(string value, Exception exception) { return new XmlException(SR.GetString(SR.XmlInvalidUTF8Bytes, value), exception); } } } // 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
- DataBindingHandlerAttribute.cs
- SQLSingleStorage.cs
- Enlistment.cs
- DeviceContexts.cs
- XsltInput.cs
- DeclarativeCatalogPart.cs
- EntityProxyFactory.cs
- TextServicesCompartmentEventSink.cs
- CurrentChangingEventArgs.cs
- InteropAutomationProvider.cs
- FirewallWrapper.cs
- OpenTypeLayoutCache.cs
- XmlSchemaGroupRef.cs
- TextTreeDeleteContentUndoUnit.cs
- DesignerVerbCollection.cs
- Source.cs
- Variable.cs
- WebPartTracker.cs
- AssemblySettingAttributes.cs
- elementinformation.cs
- FamilyCollection.cs
- QilInvoke.cs
- DeferredReference.cs
- GeneralTransform3DTo2DTo3D.cs
- SafeBitVector32.cs
- basemetadatamappingvisitor.cs
- SqlComparer.cs
- Error.cs
- WebPartManagerInternals.cs
- GeneralTransform.cs
- TemplatedAdorner.cs
- LassoHelper.cs
- ListViewItemMouseHoverEvent.cs
- querybuilder.cs
- AsyncOperation.cs
- AsmxEndpointPickerExtension.cs
- CookieParameter.cs
- HitTestResult.cs
- AesCryptoServiceProvider.cs
- CompositeControl.cs
- XhtmlTextWriter.cs
- System.Data_BID.cs
- Accessors.cs
- CommandManager.cs
- RecordManager.cs
- XmlWellformedWriter.cs
- JavaScriptString.cs
- NotifyParentPropertyAttribute.cs
- ReflectionUtil.cs
- Track.cs
- Decimal.cs
- DurableServiceAttribute.cs
- ProxyManager.cs
- SolidColorBrush.cs
- IDQuery.cs
- HttpPostClientProtocol.cs
- GridViewCellAutomationPeer.cs
- bidPrivateBase.cs
- ExtensionQuery.cs
- InputMethodStateTypeInfo.cs
- AsyncDataRequest.cs
- XMLDiffLoader.cs
- ObjectKeyFrameCollection.cs
- SafeWaitHandle.cs
- ListViewGroup.cs
- DbFunctionCommandTree.cs
- DotNetATv1WindowsLogEntryDeserializer.cs
- DbConnectionOptions.cs
- PageBreakRecord.cs
- PopOutPanel.cs
- PlatformCulture.cs
- path.cs
- NavigatorOutput.cs
- TextTreeNode.cs
- MemberMaps.cs
- MissingSatelliteAssemblyException.cs
- TextEditorTyping.cs
- ElementAtQueryOperator.cs
- PartialArray.cs
- PrivilegeNotHeldException.cs
- Triangle.cs
- StrongNameIdentityPermission.cs
- SweepDirectionValidation.cs
- ButtonFieldBase.cs
- ConfigurationStrings.cs
- Msec.cs
- OutputCacheSettingsSection.cs
- ListBindableAttribute.cs
- BindingsCollection.cs
- Matrix.cs
- ValidatorCompatibilityHelper.cs
- Vector3dCollection.cs
- CharacterShapingProperties.cs
- TextAnchor.cs
- GetPageCompletedEventArgs.cs
- PathStreamGeometryContext.cs
- DefaultWorkflowSchedulerService.cs
- SQLBytesStorage.cs
- NavigationPropertyEmitter.cs
- AbandonedMutexException.cs