ReliabilityContractAttribute 类


定义某些代码的作者和依赖于这些代码的开发人员之间的可靠性协定。Defines a contract for reliability between the author of some code, and the developers who have a dependency on that code.

public ref class ReliabilityContractAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Struct, Inherited=false)]
public sealed class ReliabilityContractAttribute : Attribute
type ReliabilityContractAttribute = class
    inherit Attribute
Public NotInheritable Class ReliabilityContractAttribute
Inherits Attribute


下面的代码示例演示如何使用ReliabilityContractAttribute属性来记录程序集的可靠性级别。The following code example demonstrates the use of the ReliabilityContractAttribute attribute to document the level of reliability of an assembly.

using namespace System;
using namespace System::Runtime::ConstrainedExecution;

   Consistency::MayCorruptInstance, Cer::None)];
namespace ReliabilityLibrary
   class SomeClass {};
using System;
using System.Runtime.ConstrainedExecution;

   Consistency.MayCorruptInstance, Cer.None)]
namespace ReliabilityLibrary
   class SomeClass {}
Imports System.Runtime.ConstrainedExecution

<assembly:ReliabilityContractAttribute( _ 
   Consistency.MayCorruptInstance, Cer.None)> 
Namespace ReliabilityLibrary
   Class SomeClass
   End Class
End Namespace


ReliabilityContractAttribute属性提供了一种机制,用于记录代码,以及指示可以在可能导致不一致状态的异常情况下执行的可靠性保证类型。The ReliabilityContractAttribute attribute provides a mechanism for you to document your code, and to indicate what type of reliability guarantees you can make in the face of exceptional conditions that could potentially lead to an inconsistent state. 在此上下文中,异常条件定义为可在运行时由公共语言运行时生成的异步异常,如中止的线程、内存不足的情况和堆栈溢出。In this context, exceptional conditions are defined as asynchronous exceptions that can be generated at run time by the common language runtime, such as aborted threads, out-of-memory situations, and stack overflows. 您可以将ReliabilityContractAttribute特性应用于程序集、类型和方法。You can apply the ReliabilityContractAttribute attribute to assemblies, types, and methods.

将此属性与Consistency枚举结合使用,通过记录特定代码段中的可靠性级别来定义可靠性协定。Use this attribute with the Consistency enumeration to define a reliability contract by documenting the level of reliability in a particular piece of code.


ReliabilityContractAttribute(Consistency, Cer)

使用指定 Consistency 保证和 Cer 值初始化 ReliabilityContractAttribute 类的新实例。Initializes a new instance of the ReliabilityContractAttribute class with the specified Consistency guarantee and Cer value.



获取确定在受约束的执行区域 (CER) 下调用时方法、类型或程序集的行为的值。Gets the value that determines the behavior of a method, type, or assembly when called under a Constrained Execution Region (CER).


获取 Consistency 可靠性协定的值。Gets the value of the Consistency reliability contract.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

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

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

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

(继承自 Object)

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

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)