mathieu pretended :
Quote:
Hi there,
>
I discovered C# only last week, I need to learn at least the basis
to wrap the interface of my C++ lib in C#. To offer a nice API to my
C# user I am looking to implement something like this:
>
Convertor convertor = new Convertor();
int a = convertor.Convert( some_int_blob );
double b = convertor.Convert( some_double_blob );
>
What this is means is that only on input (eg. some_int_blob) the
convertor should be able to determine whether or not the input was
indeed of type int, and return the proper int, otherwise should throw
some exeption...
>
I was able to do it in Python, since everything derive from a
toplevel object. I was able to do it in C++, at compile time:
>
Convertor<Key1conv;
Key1::Type value = conv.Convert( some_int_blob ); // type is deduced
from a key
>
What I am looking now is to do it in C#. Should I go the Python way
and have the Convert function return an 'object', then this is up to
the application programmer to convert this object back to int/float/
string ...
>
Thanks
-Mathieu
*If* those "some_int_blob" and "some_double_blob" have different types,
you could use overloading:
int Convert(MyIntBlobType intBlob) {}
double Convert(MyDoubleBlobType doubleBlob) { }
Hans Kesting