Type.Missing Field

May 11, 2014

Represents a missing value in the Type information. This field is read-only.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static readonly Object Missing

Use the Missing field for invocation through reflection to obtain the default value of a parameter. If the Missing field is passed in for a parameter value and there is no default value for that parameter, an ArgumentException is thrown.

Version Notes

Windows Phone

 The Type.Missing field does not throw ArgumentException when the called method has no default value for a parameter.

The following code example shows the use of the Missing field to invoke a method with its default arguments.

There is no C# example, because C# cannot declare optional parameters.


Option Strict Off
Imports System.Reflection

Public Class OptionalArg
   Public Function MyMethod(ByVal a As Integer, _
      Optional ByVal b As Double = 1.2, Optional ByVal c As Integer = 1) As String

      Return "a = " & a & " b = " & b & " c = " & c 
   End Function
End Class

Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim o As New OptionalArg()
      Dim binding As BindingFlags = BindingFlags.Public Or BindingFlags.Instance Or _
         BindingFlags.InvokeMethod Or BindingFlags.OptionalParamBinding
      Dim t As Type = GetType(OptionalArg)
      Dim param As Object() = {10, 20, 30}

      Dim result As Object = _
         t.InvokeMember("MyMethod", binding, Nothing, o, New Object() {10, 55.3, 12})
      outputBlock.Text &= result & vbLf

      result = _
         t.InvokeMember("MyMethod", binding, Nothing, o, New Object() {10, 55.3, Type.Missing})
      outputBlock.Text &= result & vbLf

      result = _ 
         t.InvokeMember("MyMethod", binding, Nothing, o, New Object() {10, Type.Missing, Type.Missing})
      outputBlock.Text &= result & vbLf
   End Sub
End Class

' This example produces the following output:
'
'a = 10 b = 55.3 c = 12
'a = 10 b = 55.3 c = 1
'a = 10 b = 1.2 c = 1


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft