Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / DecoderFallbackWithFailureFlag.cs / 1305600 / 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 : mleonov - 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.
//
//
// 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 : mleonov - 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IntSecurity.cs
- COM2ExtendedUITypeEditor.cs
- Evidence.cs
- uribuilder.cs
- OleDbParameter.cs
- LongAverageAggregationOperator.cs
- PropertyMapper.cs
- FrameSecurityDescriptor.cs
- ExtensionWindowHeader.cs
- SqlSupersetValidator.cs
- Point3DAnimationBase.cs
- CqlErrorHelper.cs
- FunctionCommandText.cs
- GetReadStreamResult.cs
- BaseValidator.cs
- TextBoxRenderer.cs
- Rotation3DKeyFrameCollection.cs
- FormsAuthenticationTicket.cs
- ReachBasicContext.cs
- CultureInfo.cs
- Encoder.cs
- MediaTimeline.cs
- DocobjHost.cs
- Exceptions.cs
- HttpDictionary.cs
- PersistenceProviderFactory.cs
- QueryConverter.cs
- RemotingConfiguration.cs
- WinEventQueueItem.cs
- AssociationTypeEmitter.cs
- MissingManifestResourceException.cs
- RowParagraph.cs
- ObjectContext.cs
- DataGridViewColumnHeaderCell.cs
- ConnectionsZone.cs
- RawTextInputReport.cs
- AtomicFile.cs
- WebPartConnectionsDisconnectVerb.cs
- ObjectSecurity.cs
- StandardBindingElementCollection.cs
- XmlBoundElement.cs
- XhtmlBasicImageAdapter.cs
- HttpServerChannel.cs
- InputBindingCollection.cs
- XPathNode.cs
- x509utils.cs
- ProcessInfo.cs
- OleDbMetaDataFactory.cs
- OrthographicCamera.cs
- Rect3D.cs
- Vector3D.cs
- StylusButtonEventArgs.cs
- FreezableOperations.cs
- TableSectionStyle.cs
- ReferenceEqualityComparer.cs
- CultureMapper.cs
- DateTimeConverter2.cs
- log.cs
- X500Name.cs
- UndirectedGraph.cs
- XmlSerializerSection.cs
- IDispatchConstantAttribute.cs
- SqlCharStream.cs
- SrgsToken.cs
- ToolStripPanel.cs
- TextModifierScope.cs
- GridViewRow.cs
- MediaContext.cs
- ManipulationVelocities.cs
- FontStyles.cs
- Normalization.cs
- PackUriHelper.cs
- FixedFlowMap.cs
- safemediahandle.cs
- safelink.cs
- AutomationPatternInfo.cs
- GeneralTransformGroup.cs
- Geometry.cs
- HandlerFactoryWrapper.cs
- SecurityDescriptor.cs
- BlockCollection.cs
- TriggerAction.cs
- RelationshipFixer.cs
- ConfigurationStrings.cs
- DataSourceHelper.cs
- MobileContainerDesigner.cs
- SplashScreen.cs
- ListBox.cs
- ToolStripDropDownButton.cs
- StringCollection.cs
- IndexedDataBuffer.cs
- ClientProxyGenerator.cs
- ClientBuildManager.cs
- XsltOutput.cs
- ProtectedConfiguration.cs
- KeyValuePair.cs
- SHA256Managed.cs
- BamlBinaryWriter.cs
- ListChangedEventArgs.cs
- ACE.cs