ReliabilityContractAttribute ReliabilityContractAttribute ReliabilityContractAttribute ReliabilityContractAttribute Class

定义

定义某些代码的作者和依赖于这些代码的开发人员之间的可靠性协定。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
继承
ReliabilityContractAttributeReliabilityContractAttributeReliabilityContractAttributeReliabilityContractAttribute
属性

示例

下面的代码示例演示如何使用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;

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

[assembly:ReliabilityContractAttribute(
   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) ReliabilityContractAttribute(Consistency, Cer) ReliabilityContractAttribute(Consistency, Cer) ReliabilityContractAttribute(Consistency, Cer)

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

属性

Cer Cer Cer Cer

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

ConsistencyGuarantee ConsistencyGuarantee ConsistencyGuarantee ConsistencyGuarantee

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

TypeId TypeId TypeId TypeId

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

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

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

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

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

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

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

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

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

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

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(Inherited from Attribute)

适用于

另请参阅