Type.Missing Field
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Represents a missing value in the Type information. This field is read-only.
Assembly: mscorlib (in mscorlib.dll)
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.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
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
Note: