views:

15

answers:

1

I searched these SO results and couldn't find anything related to my question. I doubt this could be a duplicate.

I'm currently writing a Microsoft.Office.Interop.Excel PIA wrapper in .NET C# 3.5 and was wondering about what is best to use while calling methods like opening a given workbook.

System.Type.Missing or Missing.Value?

I have performed a few Google searches, and can't find any any difference, except that one is from the System namespace (System.Type.Missing), and the other (Missing.Value) comes from the System.Reflection namespace.

  1. What is the major difference, if any, between both?
  2. Under which circumstances one is best to use than the other?
  3. Why is this so?

Both seem to be used when you want to pass a parameter's default value to the interop assembly...

Thanks for your answers! =)

+2  A: 

They are the same. In the static initializer of Type, the field Missing is set to System.Reflection.Missing.Value.

As for why there are two ways of getting at the same value: who knows. It's quite likely that this is a backward compatibility remnant, as Type.Missing is typed as object, whereas Missing.Value is typed Missing.

Ruben
@Ruben: Where did you find that they were actually the same, and more interestingly, where did you find out that Type.Missing was set to Missing.Value? Thanks! =)
Will Marcouiller
There's this wonderful tool called Reflector :-) This allows you to look at the (compiled) code of every .NET assembly. But you can also try using ILDASM (part of the SDK) and look at the **.cctor** of **Type**. It's the very first statement.
Ruben
@Ruben: Only remains to accept your answer then! =) Thanks! =)
Will Marcouiller