mirror of
https://github.com/soukoku/ntwain.git
synced 2025-07-16 23:37:12 +08:00
Fix issue #25 for bad source returning unexpected cap value types.
This commit is contained in:
parent
df80b86f71
commit
f29443a8a4
@ -58,11 +58,12 @@ namespace NTwain.Data
|
|||||||
// standard int values
|
// standard int values
|
||||||
if (returnType.IsEnum)
|
if (returnType.IsEnum)
|
||||||
{
|
{
|
||||||
|
var rawType = Enum.GetUnderlyingType(returnType);
|
||||||
|
|
||||||
if (tryUpperWord)
|
if (tryUpperWord)
|
||||||
{
|
{
|
||||||
// small routine to work with bad sources that may put
|
// small routine to work with bad sources that may put
|
||||||
// 16bit value in the upper word instead of lower word (as per the twain spec).
|
// 16bit value in the upper word instead of lower word (as per the twain spec).
|
||||||
var rawType = Enum.GetUnderlyingType(returnType);
|
|
||||||
if (typeof(ushort).IsAssignableFrom(rawType))
|
if (typeof(ushort).IsAssignableFrom(rawType))
|
||||||
{
|
{
|
||||||
var intVal = Convert.ToUInt32(value, CultureInfo.InvariantCulture);
|
var intVal = Convert.ToUInt32(value, CultureInfo.InvariantCulture);
|
||||||
@ -73,10 +74,12 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// this may work better?
|
// old method:
|
||||||
return (TEnum)Enum.ToObject(returnType, value);
|
// return (TEnum)Enum.ToObject(returnType, value);
|
||||||
//// cast to underlying type first then to the enum
|
|
||||||
//return (T)Convert.ChangeType(value, rawType);
|
// new method:
|
||||||
|
// try to convert to enum's underlying type first then cast to the enum
|
||||||
|
return (TEnum)Convert.ChangeType(value, rawType);
|
||||||
}
|
}
|
||||||
else if (typeof(IConvertible).IsAssignableFrom(returnType))
|
else if (typeof(IConvertible).IsAssignableFrom(returnType))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user