2014-04-21 04:57:38 +08:00
using NTwain.Data ;
2014-04-17 19:11:39 +08:00
using System ;
2014-04-03 07:01:21 +08:00
using System.Runtime.Serialization ;
2014-04-17 19:11:39 +08:00
using System.Security.Permissions ;
2014-04-03 07:01:21 +08:00
namespace NTwain
{
2014-04-17 19:11:39 +08:00
/// <summary>
/// Represents a general exception with TWAIN.
/// </summary>
[Serializable]
public class TwainException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="TwainException"/> class.
/// </summary>
public TwainException ( ) { }
2014-04-03 07:01:21 +08:00
2014-04-17 19:11:39 +08:00
/// <summary>
/// Initializes a new instance of the <see cref="TwainException" /> class.
/// </summary>
/// <param name="returnCode">The return code.</param>
/// <param name="message">The message.</param>
public TwainException ( ReturnCode returnCode , string message )
: this ( returnCode , message , null ) { }
2014-04-03 07:01:21 +08:00
2014-04-17 19:11:39 +08:00
/// <summary>
/// Initializes a new instance of the <see cref="TwainException" /> class.
/// </summary>
/// <param name="returnCode">The return code.</param>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public TwainException ( ReturnCode returnCode , string message , Exception innerException )
: base ( message , innerException )
{
ReturnCode = returnCode ;
}
2014-04-03 07:01:21 +08:00
2014-04-17 19:11:39 +08:00
/// <summary>
/// Initializes a new instance of the <see cref="TwainException"/> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">
/// The <paramref name="info"/> parameter is null.
/// </exception>
/// <exception cref="T:System.Runtime.Serialization.SerializationException">
/// The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0).
/// </exception>
protected TwainException ( SerializationInfo info , StreamingContext context )
: base ( info , context )
{
if ( info ! = null )
{
ReturnCode = ( ReturnCode ) info . GetUInt16 ( "RC" ) ;
}
}
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="T:System.ArgumentNullException">
/// The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic).
/// </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
/// </PermissionSet>
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData ( SerializationInfo info , StreamingContext context )
{
if ( info ! = null )
{
info . AddValue ( "RC" , ReturnCode ) ;
}
base . GetObjectData ( info , context ) ;
}
/// <summary>
/// Gets the return code from the TWAIN operation if applicable.
/// </summary>
/// <value>
/// The return code.
/// </value>
public ReturnCode ReturnCode { get ; private set ; }
}
2014-04-03 07:01:21 +08:00
}