Hello Lars,
It seems to be pretty simple:
// assume "index" is the passed variant (that is, "object" in C#)
int indexValue;
if (index is System.String)
{
string keyVal = index as System.String;
// Handle string indexation.
}
else if (index is System.Int32)
{
indexValue = index as System.Int32;
}
else if (index is System.Int16)
{
indexValue = (int)TypeConverter.ConvertTo(index,
typeof(System.Int32));
}
else
{
throw new ArgumentException();
}
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software
"Lars von Wedel" <vo******@lfpt.rwth-aachen.de> wrote in message
news:Xn**********************************@137.226. 144.7...
Hello,
I have problems to implement a C# component which is called by a VB6
application through COM. A method Item accepts a variant as a parameter
which can contain either a string or an integer (as an index) to access a
collection.
In certain cases, the integer I extract from the variant is a System.Int32
and everything works fine. In other cases, however, the content is shown
as a System.Int16 (e.g. in the debugger) and it is not possible to convert it
to an int for example (an exception is thrown).
Any ideas about this?
Lars