Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Text / DecoderExceptionFallback.cs / 1 / DecoderExceptionFallback.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // DecoderExceptionFallback.cs // namespace System.Text { using System; using System.Runtime.Serialization; using System.Globalization; [Serializable] public sealed class DecoderExceptionFallback : DecoderFallback { // Construction public DecoderExceptionFallback() { } public override DecoderFallbackBuffer CreateFallbackBuffer() { return new DecoderExceptionFallbackBuffer(); } // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount { get { return 0; } } public override bool Equals(Object value) { DecoderExceptionFallback that = value as DecoderExceptionFallback; if (that != null) { return (true); } return (false); } public override int GetHashCode() { return 879; } } public sealed class DecoderExceptionFallbackBuffer : DecoderFallbackBuffer { public override bool Fallback(byte[] bytesUnknown, int index) { Throw(bytesUnknown, index); return true; } public override char GetNextChar() { return (char)0; } public override bool MovePrevious() { // Exception fallback doesn't have anywhere to back up to. return false; } // Exceptions are always empty public override int Remaining { get { return 0; } } private void Throw(byte[] bytesUnknown, int index) { // Create a string representation of our bytes. StringBuilder strBytes = new StringBuilder(bytesUnknown.Length * 3); int i; for (i = 0; i < bytesUnknown.Length && i < 20; i++) { strBytes.Append("["); strBytes.Append(bytesUnknown[i].ToString("X2", CultureInfo.InvariantCulture)); strBytes.Append("]"); } // In case the string's really long if (i == 20) strBytes.Append(" ..."); // Known index throw new DecoderFallbackException( Environment.GetResourceString("Argument_InvalidCodePageBytesIndex", strBytes, index), bytesUnknown, index); } } // Exception for decoding unknown byte sequences. [Serializable] public sealed class DecoderFallbackException : ArgumentException { byte[] bytesUnknown = null; int index = 0; public DecoderFallbackException() : base(Environment.GetResourceString("Arg_ArgumentException")) { SetErrorCode(__HResults.COR_E_ARGUMENT); } public DecoderFallbackException(String message) : base(message) { SetErrorCode(__HResults.COR_E_ARGUMENT); } public DecoderFallbackException(String message, Exception innerException) : base(message, innerException) { SetErrorCode(__HResults.COR_E_ARGUMENT); } internal DecoderFallbackException(SerializationInfo info, StreamingContext context) : base(info, context) { } public DecoderFallbackException( String message, byte[] bytesUnknown, int index) : base(message) { this.bytesUnknown = bytesUnknown; this.index = index; } public byte[] BytesUnknown { get { return (bytesUnknown); } } public int Index { get { return this.index; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // DecoderExceptionFallback.cs // namespace System.Text { using System; using System.Runtime.Serialization; using System.Globalization; [Serializable] public sealed class DecoderExceptionFallback : DecoderFallback { // Construction public DecoderExceptionFallback() { } public override DecoderFallbackBuffer CreateFallbackBuffer() { return new DecoderExceptionFallbackBuffer(); } // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount { get { return 0; } } public override bool Equals(Object value) { DecoderExceptionFallback that = value as DecoderExceptionFallback; if (that != null) { return (true); } return (false); } public override int GetHashCode() { return 879; } } public sealed class DecoderExceptionFallbackBuffer : DecoderFallbackBuffer { public override bool Fallback(byte[] bytesUnknown, int index) { Throw(bytesUnknown, index); return true; } public override char GetNextChar() { return (char)0; } public override bool MovePrevious() { // Exception fallback doesn't have anywhere to back up to. return false; } // Exceptions are always empty public override int Remaining { get { return 0; } } private void Throw(byte[] bytesUnknown, int index) { // Create a string representation of our bytes. StringBuilder strBytes = new StringBuilder(bytesUnknown.Length * 3); int i; for (i = 0; i < bytesUnknown.Length && i < 20; i++) { strBytes.Append("["); strBytes.Append(bytesUnknown[i].ToString("X2", CultureInfo.InvariantCulture)); strBytes.Append("]"); } // In case the string's really long if (i == 20) strBytes.Append(" ..."); // Known index throw new DecoderFallbackException( Environment.GetResourceString("Argument_InvalidCodePageBytesIndex", strBytes, index), bytesUnknown, index); } } // Exception for decoding unknown byte sequences. [Serializable] public sealed class DecoderFallbackException : ArgumentException { byte[] bytesUnknown = null; int index = 0; public DecoderFallbackException() : base(Environment.GetResourceString("Arg_ArgumentException")) { SetErrorCode(__HResults.COR_E_ARGUMENT); } public DecoderFallbackException(String message) : base(message) { SetErrorCode(__HResults.COR_E_ARGUMENT); } public DecoderFallbackException(String message, Exception innerException) : base(message, innerException) { SetErrorCode(__HResults.COR_E_ARGUMENT); } internal DecoderFallbackException(SerializationInfo info, StreamingContext context) : base(info, context) { } public DecoderFallbackException( String message, byte[] bytesUnknown, int index) : base(message) { this.bytesUnknown = bytesUnknown; this.index = index; } public byte[] BytesUnknown { get { return (bytesUnknown); } } public int Index { get { return this.index; } } } } // 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
- WebPartEditorCancelVerb.cs
- AnimationLayer.cs
- SystemException.cs
- LifetimeServices.cs
- TemplateControlParser.cs
- Vector3DValueSerializer.cs
- GlyphRunDrawing.cs
- DataListDesigner.cs
- BindingCompleteEventArgs.cs
- WindowsScrollBar.cs
- PipelineDeploymentState.cs
- ITreeGenerator.cs
- MetadataItemEmitter.cs
- BatchParser.cs
- NativeActivityContext.cs
- ClientSettingsSection.cs
- SqlDataSourceEnumerator.cs
- ManagedWndProcTracker.cs
- NestedContainer.cs
- TextTrailingWordEllipsis.cs
- PropertyOverridesDialog.cs
- SecureUICommand.cs
- DBDataPermission.cs
- IconConverter.cs
- OleDbConnectionFactory.cs
- UnsafeNativeMethods.cs
- Rect.cs
- SqlDuplicator.cs
- ListItemCollection.cs
- _emptywebproxy.cs
- EnterpriseServicesHelper.cs
- ClassicBorderDecorator.cs
- DataGridViewCellCancelEventArgs.cs
- EncoderParameter.cs
- ExpressionTable.cs
- BitmapEffect.cs
- ClipboardProcessor.cs
- DoubleAnimation.cs
- PasswordPropertyTextAttribute.cs
- OrderingInfo.cs
- TableParaClient.cs
- wgx_render.cs
- MaskDescriptors.cs
- StylusPointProperty.cs
- IntegerValidator.cs
- TextServicesDisplayAttributePropertyRanges.cs
- ByteAnimation.cs
- Int16Storage.cs
- PenLineCapValidation.cs
- ProfileService.cs
- DetailsViewPagerRow.cs
- LinqDataSourceEditData.cs
- SetUserLanguageRequest.cs
- CustomAttributeSerializer.cs
- QilTypeChecker.cs
- HiddenField.cs
- SmtpLoginAuthenticationModule.cs
- FixedPosition.cs
- ToolStripInSituService.cs
- TemplateInstanceAttribute.cs
- XmlCustomFormatter.cs
- GridViewPageEventArgs.cs
- FrameworkContentElement.cs
- TreeNode.cs
- ConfigXmlSignificantWhitespace.cs
- SerializationEventsCache.cs
- AnyReturnReader.cs
- DataServiceQuery.cs
- lengthconverter.cs
- AdornerLayer.cs
- RuleProcessor.cs
- InvalidOperationException.cs
- ToolStripItemTextRenderEventArgs.cs
- InkCanvasInnerCanvas.cs
- TextLine.cs
- XamlBrushSerializer.cs
- Trigger.cs
- Internal.cs
- PartEditor.cs
- CodeThrowExceptionStatement.cs
- ToolStripDesignerAvailabilityAttribute.cs
- DriveInfo.cs
- ImplicitInputBrush.cs
- MSHTMLHostUtil.cs
- DbModificationClause.cs
- TreeView.cs
- DocumentSequence.cs
- InputEventArgs.cs
- Matrix3DValueSerializer.cs
- WebPartEditorOkVerb.cs
- Overlapped.cs
- _CacheStreams.cs
- ScrollPattern.cs
- MessageSecurityProtocol.cs
- COM2ColorConverter.cs
- RtType.cs
- EntityProviderFactory.cs
- Page.cs
- RawStylusSystemGestureInputReport.cs
- ProxyGenerationError.cs