Hi Jim,
Thanks for your post.
I think "Jon Skeet [C# MVP]" has provided you the correct information.
First, Type.IsAssignableFrom Method returns true if the c parameter and the
current Type represent the same type, or if the current Type is in the
inheritance hierarchy of c, or if the current Type is an interface that c
supports. So it should meet your need of determine if the object can be
assigned to this type. However, this does not contain the casting, if you
want to cover the casting scenario, I think Convert.ChangeType() method is
your friend.
Second, I agree with "Jon Skeet [C# MVP]" that if you want to implement a
method accepting polymorphism object type for comparison, the object should
at least implement IComparable interface. Only an object implemented
IComparable interface, can it make sense for comparison in a range. In
current .Net FCL, almost all the primitive types implemented this
interface, such as System.Int32, System.Int16, System.UInt32,
System.UInt16, etc... You can use Reflector to view "Derived Types" node
under IComparable interface to get all the FCL classes implemented
IComparable interface. For your own customized class type, this class
should also implement IComparable interface for comparison.
Hope this helps
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.