"typed" null ?

G

Guest

Hello,

I'd like to know, whether it is possible to have type information associated with "null". I am implementing a wrapper (MC++) for our legacy method that accepts variable number of arguments and I need to distinguish types of passed parameters, which can have "null" values:

int Wrapper::Call(String *method, [ParamArray] System::Object *args[])
{
// ...
// args can be null

for(int i = 0, nCount = args->Count; i < nCount; i++)
{
if(__typeof(...)->Equals(args->GetType()))
// Do something for the first type
else
if(__typeof(...)->Equals(args->GetType()))
// Do something else for the second type
...
}
}

It would be nice to allow calls like this (e.g. from C#):

wrapper.Call("Method", 10, (TypeA)null, objB, (TypeC)null, 7);
 
B

Brandon Bray [MSFT]

Stanislav said:
I'd like to know, whether it is possible to have type information
associated with "null". I am implementing a wrapper (MC++) for our legacy
method that accepts variable number of arguments and I need to
distinguish types of passed parameters, which can have "null" values:

[SNIP]

It would be nice to allow calls like this (e.g. from C#):

wrapper.Call("Method", 10, (TypeA)null, objB, (TypeC)null, 7);

It is not possible to pass type information along with the null value, but
it is possible to statically give a type to the null value expression. In
fact, that is exactly what you did. The only benefit of that is to influence
overload resolution. So in the example above, the type information TypeA and
TypeC only affect which method gets called. You'll end up with an Object
array having two null values.
 
G

Guest

It is not possible to pass type information along with the null value,

Ok, thanks for the info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top