mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
#37 CapabilityReader should not throw for no data
This commit is contained in:
@@ -35,55 +35,61 @@ namespace NTwain
|
|||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="memoryManager">The memory manager.</param>
|
/// <param name="memoryManager">The memory manager.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="System.ArgumentNullException">capability
|
/// <exception cref="System.ArgumentNullException">
|
||||||
|
/// capability
|
||||||
/// or
|
/// or
|
||||||
/// platformInfo</exception>
|
/// memoryManager
|
||||||
/// <exception cref="System.ArgumentException">Capability contains no data.;capability
|
/// </exception>
|
||||||
/// or
|
/// <exception cref="System.ArgumentException">capability</exception>
|
||||||
/// capability</exception>
|
|
||||||
public static CapabilityReader ReadValue(TWCapability capability, IMemoryManager memoryManager)
|
public static CapabilityReader ReadValue(TWCapability capability, IMemoryManager memoryManager)
|
||||||
{
|
{
|
||||||
if (capability == null) { throw new ArgumentNullException("capability"); }
|
if (capability == null) { throw new ArgumentNullException("capability"); }
|
||||||
if (capability.Container == IntPtr.Zero) { throw new ArgumentException(Resources.CapHasNoData, "capability"); }
|
|
||||||
if (memoryManager == null) { throw new ArgumentNullException("memoryManager"); }
|
if (memoryManager == null) { throw new ArgumentNullException("memoryManager"); }
|
||||||
|
|
||||||
IntPtr baseAddr = IntPtr.Zero;
|
if (capability.Container != IntPtr.Zero)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
baseAddr = memoryManager.Lock(capability.Container);
|
IntPtr baseAddr = IntPtr.Zero;
|
||||||
switch (capability.ContainerType)
|
try
|
||||||
{
|
{
|
||||||
case ContainerType.Array:
|
baseAddr = memoryManager.Lock(capability.Container);
|
||||||
return new CapabilityReader
|
switch (capability.ContainerType)
|
||||||
{
|
{
|
||||||
ContainerType = capability.ContainerType,
|
case ContainerType.Array:
|
||||||
}.ReadArrayValue(baseAddr);
|
return new CapabilityReader
|
||||||
case ContainerType.Enum:
|
{
|
||||||
return new CapabilityReader
|
ContainerType = capability.ContainerType,
|
||||||
{
|
}.ReadArrayValue(baseAddr);
|
||||||
ContainerType = capability.ContainerType,
|
case ContainerType.Enum:
|
||||||
}.ReadEnumValue(baseAddr);
|
return new CapabilityReader
|
||||||
case ContainerType.OneValue:
|
{
|
||||||
return new CapabilityReader
|
ContainerType = capability.ContainerType,
|
||||||
{
|
}.ReadEnumValue(baseAddr);
|
||||||
ContainerType = capability.ContainerType,
|
case ContainerType.OneValue:
|
||||||
}.ReadOneValue(baseAddr);
|
return new CapabilityReader
|
||||||
case ContainerType.Range:
|
{
|
||||||
return new CapabilityReader
|
ContainerType = capability.ContainerType,
|
||||||
{
|
}.ReadOneValue(baseAddr);
|
||||||
ContainerType = capability.ContainerType,
|
case ContainerType.Range:
|
||||||
}.ReadRangeValue(baseAddr);
|
return new CapabilityReader
|
||||||
default:
|
{
|
||||||
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.CapHasBadContainer, capability.ContainerType), "capability");
|
ContainerType = capability.ContainerType,
|
||||||
|
}.ReadRangeValue(baseAddr);
|
||||||
|
default:
|
||||||
|
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.CapHasBadContainer, capability.ContainerType), "capability");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (baseAddr != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
//memoryManager.Unlock(baseAddr);
|
||||||
|
memoryManager.Unlock(capability.Container);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
else
|
||||||
{
|
{
|
||||||
if (baseAddr != IntPtr.Zero)
|
return new CapabilityReader();
|
||||||
{
|
|
||||||
//memoryManager.Unlock(baseAddr);
|
|
||||||
memoryManager.Unlock(capability.Container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The build release version number.
|
/// The build release version number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Build = "3.2.8"; // change this for each nuget release
|
public const string Build = "3.3.0"; // change this for each nuget release
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user