using NTwain.Properties;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace NTwain.Data
{
///
/// The one-stop class for reading TWAIN cap values.
/// This contains all the properties for the 4 container types.
///
public class CapReadOut
{
///
/// Reads the value from a that was returned
/// from a TWAIN source.
///
/// The capability.
///
/// capability
///
/// Capability contains no data.;capability
/// or
/// capability
///
public static CapReadOut ReadValue(TWCapability capability)
{
if (capability == null) { throw new ArgumentNullException("capability"); }
if (capability.Container == IntPtr.Zero) { throw new ArgumentException(Resources.CapHasNoData, "capability"); }
IntPtr baseAddr = IntPtr.Zero;
try
{
baseAddr = Platform.MemoryManager.Lock(capability.Container);
switch (capability.ContainerType)
{
case ContainerType.Array:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadArrayValue(baseAddr);
case ContainerType.Enum:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadEnumValue(baseAddr);
case ContainerType.OneValue:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadOneValue(baseAddr);
case ContainerType.Range:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadRangeValue(baseAddr);
default:
throw new ArgumentException(string.Format(Resources.CapHasBadContainer, capability.ContainerType), "capability");
}
}
finally
{
if (baseAddr != IntPtr.Zero)
{
Platform.MemoryManager.Unlock(baseAddr);
}
}
}
#region common prop
///
/// Gets the underlying container type.
///
///
/// The container.
///
public ContainerType ContainerType { get; private set; }
///
/// Gets the type of the TWAIN value.
///
///
/// The type of the value.
///
public ItemType ItemType { get; private set; }
///
/// Gets the one value if container is .
///
///
/// The one value.
///
public object OneValue { get; private set; }
///
/// Gets the collection values if container is or .
///
///
/// The collection values.
///
public IList