ImageGear for Silverlight
Allowed Value Types for Range Containers
Send Feedback
ImageGear for Silverlight User Guide > Using ImageGear for Silverlight > Using ImageGear.TWAIN Namespace > Differences between ImageGear for Silverlight and ImageGear for .NET TWAIN > Allowed Value Types for Range Containers

Glossary Item Box

Between ImageGear for Silverlight and ImageGear .NET, there is a difference in the value types that can be used to set properties on an ImGearCapRange object. When comparing the classes from each product, the obvious difference between the classes is that the type of the properties is different. In ImageGear .NET, the property type is System.Object, but in ImageGear for Silverlight the property types are System.Single.

The difference, however, goes deeper than the property signature. First, we will look at the properties of the ImGearCapRange class in ImageGear .NET.

For any of these properties on the ImGearCapRange class of ImageGear .NET, although these are System.Object type, the property setter will throw if calling code attempts to set these values to anything other than System.Double or System.Int64 values. This results in code that must explicitly cast the value to a double or int64 value. The following code demonstrates this when setting the ICAP_CONTRAST value.

C# Copy Code
ImGearCapRange cap =
new ImGearCapRange(ImGearCapabilities.ICAP_CONTRAST);
cap.CurrentValue = 1; // this would throw at runtime, because 1 is not of the expected types
cap.CurrentValue = 1D; // this would set the CurrentValue property successfully
myImGearTWAIN.SetCapability(cap, ImGearMessages.SET);

The second line of code attempts to set cap.CurrentValue to 1, which compiles fine. However, the value 1 is not a double or an int64, so the property setter throws at runtime. The third line of code compiles fine and also executes successfully at runtime.

Now, we will look at how ImageGear for Silverlight works, and how this will effect porting between the two products. The properties of the ImGearCapRange class are shown below.

These properties are all floats. This allows the compiler to validate the code that is setting the properties and also take care of any implicit casting. However, if the code from above were ported to compile against ImageGear for Silverlight TWAIN, then there would be some issues.

C# Copy Code
ImGearCapRange cap =
new ImGearCapRange(ImGearCapabilities.ICAP_CONTRAST);
cap.CurrentValue = 1; // compiles and executes correctly
cap.CurrentValue = 1D; // this results in a compiler error
myImGearTWAIN.SetCapability(cap, ImGearMessages.SET);

So in this case, the second line of code compiles and executes correctly, but the third line of code does not compile correctly. An explicit cast is required to cast from a System.Double to a System.Single, or from a System.Int64 to a System.Single in .NET.

©2013. Accusoft Corporation. All Rights Reserved.