Missing 类

定义

表示缺少的 ObjectRepresents a missing Object. 此类不能被继承。This class cannot be inherited.

public ref class Missing sealed : System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class Missing : System.Runtime.Serialization.ISerializable
type Missing = class
    interface ISerializable
Public NotInheritable Class Missing
Implements ISerializable
继承
Missing
属性
实现

示例

下面的示例演示如何通过使用反射Missing来使用对象调用具有默认参数的方法。The following example shows how to use the Missing object to invoke a method with a default argument by using reflection.

using System;
using System.Reflection;

[assembly:CLSCompliant(true)]

public class MissingClass
{
   public static void MethodWithDefault(int value = 33)
   {
      Console.WriteLine("value = {0}", value);
   } 
}

public class Example
{
   public static void Main()
   {
      // Invoke without reflection
      MissingClass.MethodWithDefault();
      
      // Invoke by using reflection.
      Type t = typeof(MissingClass);
      MethodInfo mi = t.GetMethod("MethodWithDefault");
      mi.Invoke(null, new object[] { Missing.Value });
   }
}
// The example displays the following output:
//       value = 33  
//       value = 33  
Imports System.Reflection

<Assembly:CLSCompliant(True)>

Public Class MissingClass
   Public Shared Sub MethodWithDefault(Optional value As Integer = 33)
      Console.WriteLine("value = {0}", value)
   End Sub 
End Class   

Public Module Example
   Public Sub Main()
      ' Invoke without reflection.
      MissingClass.MethodWithDefault()
      
      ' Invoke by using reflection.
      Dim t As Type = GetType(MissingClass)
      Dim mi As MethodInfo = t.GetMethod("MethodWithDefault")
      mi.Invoke(Nothing, { Missing.Value })
   End Sub
End Module
' The example displays the following output:
'       value = 33 
'       value = 33 

注解

Missing类用于调用具有默认参数的方法 (通常使用反射时)。The Missing class is used to invoke a method with a default argument, typically when using reflection.

只有Value字段返回的Missing一个实例存在。Only one instance of Missing, which is returned by the Value field, ever exists.

字段

Value

表示 Missing 类的唯一实例。Represents the sole instance of the Missing class.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用重新创建 SerializationInfo 对象的唯一实例所需的逻辑上下文信息设置 Missing 对象。Sets a SerializationInfo object with the logical context information needed to recreate the sole instance of the Missing object.

适用于

另请参阅