Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Shared / MS / Internal / DecoderFallbackWithFailureFlag.cs / 1 / DecoderFallbackWithFailureFlag.cs
//---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // Description: DecoderFallbackWithFailureFlag is used when the developer wants Encoding.GetChars() method to fail // without throwing an exception when decoding cannot be performed. // Usage pattern is: // DecoderFallbackWithFailureFlag fallback = new DecoderFallbackWithFailureFlag(); // Encoding e = Encoding.GetEncoding(codePage, EncoderFallback.ExceptionFallback, fallback); // e.GetChars(bytesToDecode); // if (fallback.HasFailed) // { // // Perform fallback and reset the failure flag. // fallback.HasFailed = false; // } // // History: // 05/03/2005 : [....] - Created // //--------------------------------------------------------------------------- using System.Text; namespace MS.Internal { ////// This class is similar to the standard DecoderExceptionFallback class, /// except that for performance reasons it sets a Boolean failure flag /// instead of throwing exception. /// internal class DecoderFallbackWithFailureFlag : DecoderFallback { public DecoderFallbackWithFailureFlag() { } public override DecoderFallbackBuffer CreateFallbackBuffer() { return new FallbackBuffer(this); } ////// The maximum number of characters this instance can return. /// public override int MaxCharCount { get { return 0; } } ////// Returns whether decoding failed. /// public bool HasFailed { get { return _hasFailed; } set { _hasFailed = value; } } private bool _hasFailed; // false by default ////// A special implementation of DecoderFallbackBuffer that sets the failure flag /// in the parent DecoderFallbackWithFailureFlag class. /// private class FallbackBuffer : DecoderFallbackBuffer { public FallbackBuffer(DecoderFallbackWithFailureFlag parent) { _parent = parent; } ////// Indicates whether a substitute string can be emitted if an input byte sequence cannot be decoded. /// Parameters specify an input byte sequence, and the index position of a byte in the input. /// /// An input array of bytes. /// The index position of a byte in bytesUnknown. ///true if a string exists that can be inserted in the output /// instead of decoding the byte specified in bytesUnknown; /// false if the input byte should be ignored. public override bool Fallback(byte[] bytesUnknown, int index) { _parent.HasFailed = true; return false; } ////// Retrieves the next character in the fallback buffer. /// ///The next Unicode character in the fallback buffer. public override char GetNextChar() { return (char)0; } ////// Prepares the GetNextChar method to retrieve the preceding character in the fallback buffer. /// ///true if the MovePrevious operation was successful; otherwise, false. public override bool MovePrevious() { return false; } ////// Gets the number of characters in this instance of DecoderFallbackBuffer that remain to be processed. /// public override int Remaining { get { return 0; } } private DecoderFallbackWithFailureFlag _parent; } } } // 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
- validationstate.cs
- SerializationStore.cs
- CanExpandCollapseAllConverter.cs
- EmptyElement.cs
- PublisherMembershipCondition.cs
- View.cs
- DependencyObject.cs
- ServiceThrottle.cs
- FileLoadException.cs
- WindowsSpinner.cs
- RequestSecurityTokenForRemoteTokenFactory.cs
- MediaPlayerState.cs
- StringValidatorAttribute.cs
- LightweightCodeGenerator.cs
- MsmqUri.cs
- XNodeValidator.cs
- CellConstantDomain.cs
- StaticContext.cs
- MimeParameter.cs
- Itemizer.cs
- InputLanguageEventArgs.cs
- EntityDataSourceWrapper.cs
- MdiWindowListItemConverter.cs
- TextRunTypographyProperties.cs
- IncrementalReadDecoders.cs
- HtmlTableCell.cs
- LogicalExpr.cs
- DoubleAnimationClockResource.cs
- WebPartHelpVerb.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- LocalBuilder.cs
- NetDataContractSerializer.cs
- WorkItem.cs
- HttpHeaderCollection.cs
- ComponentResourceManager.cs
- DbMetaDataCollectionNames.cs
- X509Extension.cs
- GridViewUpdatedEventArgs.cs
- XmlSerializableReader.cs
- SmiMetaData.cs
- ToolStripSplitButton.cs
- OleDragDropHandler.cs
- ApplicationSecurityInfo.cs
- ValueHandle.cs
- BinaryMethodMessage.cs
- JsonServiceDocumentSerializer.cs
- BindingSource.cs
- SvcFileManager.cs
- filewebresponse.cs
- TextElementEditingBehaviorAttribute.cs
- ReflectionTypeLoadException.cs
- Column.cs
- OrderByLifter.cs
- clipboard.cs
- TreeWalkHelper.cs
- CommandValueSerializer.cs
- PostBackOptions.cs
- TextServicesLoader.cs
- VirtualDirectoryMappingCollection.cs
- ConfigXmlSignificantWhitespace.cs
- CompatibleComparer.cs
- Group.cs
- RC2CryptoServiceProvider.cs
- COM2ComponentEditor.cs
- ListItemCollection.cs
- DataFieldConverter.cs
- XmlDocumentFragment.cs
- CatalogZoneBase.cs
- TraceAsyncResult.cs
- CheckBox.cs
- DataGridToolTip.cs
- TypeElement.cs
- CreateUserWizardStep.cs
- _ShellExpression.cs
- ProfilePropertySettingsCollection.cs
- SourceChangedEventArgs.cs
- PointF.cs
- CngKeyBlobFormat.cs
- ClientBuildManager.cs
- AudioFormatConverter.cs
- SchemaElementDecl.cs
- FileSystemInfo.cs
- XmlSchemaType.cs
- BitmapEffectInputConnector.cs
- XmlBindingWorker.cs
- UInt16.cs
- ToolStrip.cs
- StrokeFIndices.cs
- BasicKeyConstraint.cs
- RightsManagementEncryptionTransform.cs
- HtmlInputText.cs
- RegexGroup.cs
- Serializer.cs
- ClientScriptManagerWrapper.cs
- ClientTarget.cs
- SqlReorderer.cs
- TypeInitializationException.cs
- ThreadNeutralSemaphore.cs
- ExceptionHandler.cs
- MasterPageCodeDomTreeGenerator.cs