Export (0) Print
Expand All

Type.Missing Field

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
public static final Object Missing
public static final var Missing : Object
Not applicable.

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.

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

Option Strict Off
Imports System
Imports System.Reflection
Public Class OptionalArg
    Public Sub MyMethod(ByVal a As Integer, Optional ByVal b As Double = 1.2, Optional ByVal c As Integer = 1)
        Console.WriteLine("a = " & a & " b = " & b & " c = " & c)
    End Sub
End Class
Module module1
    Sub main()
        Dim o As New OptionalArg()
        Dim t As Type
        t = GetType(OptionalArg)
        Dim param As Object() = {10, 20, 30}
        t.InvokeMember("MyMethod", BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.OptionalParamBinding, Nothing, o, New Object() {10, 55.3, 12})
        t.InvokeMember("MyMethod", BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.OptionalParamBinding, Nothing, o, New Object() {10, 1.3, Type.Missing})
        t.InvokeMember("MyMethod", BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.OptionalParamBinding, Nothing, o, New Object() {10, Type.Missing, Type.Missing})
    End Sub
End Module

This code produces the following output:

a = 10 b = 55.3 c = 12

a = 10 b = 1.3 c = 1

a = 10 b = 1.2 c = 1

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft