Type::Missing Field

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

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

No code example is currently available or this language may not be supported.

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.

Platform Notes

Silverlight for Windows Phone Silverlight for 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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: