ReliabilityContractAttributeとは? わかりやすく解説

ReliabilityContractAttribute クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

一部のコードの作成者とそのコードに依存している開発者の間の信頼性のコントラクトを定義します。

名前空間: System.Runtime.ConstrainedExecution
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class
 Or AttributeTargets.Struct Or AttributeTargets.Constructor
 Or AttributeTargets.Method Or AttributeTargets.Interface, Inherited:=False)> _
Public NotInheritable Class
 ReliabilityContractAttribute
    Inherits Attribute
Dim instance As ReliabilityContractAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Interface,
 Inherited=false)] 
public sealed class ReliabilityContractAttribute
 : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method|AttributeTargets::Interface,
 Inherited=false)] 
public ref class ReliabilityContractAttribute
 sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Interface,
 Inherited=false) */ 
public final class ReliabilityContractAttribute
 extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Interface,
 Inherited=false) 
public final class ReliabilityContractAttribute
 extends Attribute
解説解説
使用例使用例

ReliabilityContractAttribute 属性を使用して、アセンブリの信頼性のレベルを文書化するコード例を次に示します。

Imports System
Imports System.Runtime.ConstrainedExecution

<assembly:ReliabilityContractAttribute( _ 
   Consistency.MayCorruptInstance, Cer.None)> 
Namespace ReliabilityLibrary
   Class SomeClass
   End Class
End Namespace
using System;
using System.Runtime.ConstrainedExecution;

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

[assembly:ReliabilityContractAttribute(
   Consistency::MayCorruptInstance, Cer::None)];
namespace ReliabilityLibrary
{
   class SomeClass {};
}
継承階層継承階層
System.Object
   System.Attribute
    System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ReliabilityContractAttribute メンバ
System.Runtime.ConstrainedExecution 名前空間
Consistency 列挙体
Cer 列挙体

ReliabilityContractAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定した Consistency 保証と Cer 値を使用して、ReliabilityContractAttribute クラスの新しいインスタンスを初期化します。

名前空間: System.Runtime.ConstrainedExecution
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    consistencyGuarantee As Consistency, _
    cer As Cer _
)
Dim consistencyGuarantee As Consistency
Dim cer As Cer

Dim instance As New ReliabilityContractAttribute(consistencyGuarantee,
 cer)
public ReliabilityContractAttribute (
    Consistency consistencyGuarantee,
    Cer cer
)
public:
ReliabilityContractAttribute (
    Consistency consistencyGuarantee, 
    Cer cer
)
public ReliabilityContractAttribute (
    Consistency consistencyGuarantee, 
    Cer cer
)
public function ReliabilityContractAttribute
 (
    consistencyGuarantee : Consistency, 
    cer : Cer
)

パラメータ

consistencyGuarantee

Consistency 値の 1 つ。

cer

Cer 値の 1 つ。

使用例使用例

ReliabilityContractAttribute コンストラクタを使用して、制約された実行領域と実行が保証された finally ブロックを作成するコード例を次に示します。

using System;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;

// Demonstrate Cers using abrupt thread aborts. Demonstrate there is
 always a finally 
// invocation for any Cer that is entered.
class AbruptThreadAbort
{
    public static int Main(String[]
 args)
    {
        // Run the test a few times, it's timing dependent. The argument
 passed in is the 
        // stack depth to create.
        for (int i = 0; i < 1000; i++)
            if (!Test(i % 5))
            {
                Console.WriteLine("Failed");
                return 0;
            }

        Console.WriteLine("Succeeded");
        return 100;
    }

    // Create a thread and tell it to create a stack of the required
 depth. The first 3 levels 
    // will contain Cers, those after will not. Wait for the thread
 to startup, but abort it 
    // immediately. The thread may be in the process of setting the
 stack up at the point the 
    // abort occurs. Check a state variable after the thread exits to
 determine if there is a 
    // consistent state following the abort. Each level of the stack
 with a Cer maintains a 
    // consistency variable that is reset on entry to the try and set
 in the corresponding 
    // finally block. None of these variables should be in a reset state
 after aborting
    // the thread.
    static bool Test(int
 d)
    {
        // Create the context for the thread. This sets the stack depth
 for the thread and gives 
        // the final consistency state after the abort.
        WorkUnit wu = new WorkUnit(d);

        // Create and start the thread.
        Thread t = new Thread(new ThreadStart(wu.StackDepth1));
        t.Start();

        // Wait until the thread is ready to begin.
        wu.wait.WaitOne();

        // Abort immediately. This will occassionally interrupt the
 thread as it is setting 
        // up the stack, which is good.
        t.Abort();

        // Wait for the thread to exit.
        t.Join();

        // Check the final state for consistency.
        return wu.consistentLevel1;
    }
}

// Context class for the thread worker.
class WorkUnit
{
    public EventWaitHandle wait;
    public bool consistentLevel1;
    public bool consistentLevel2;
    public bool consistentLevel3;
    public int depth;

    public WorkUnit(int d)
    {
        wait = new EventWaitHandle(false, EventResetMode.AutoReset);
        depth = d;
    }
    public void StackDepth1()
    {
        // Declare the root Cer.
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {

            // Cannot be interrupted until the event set below, so set
 up for initial success. Level 1 consistency is
            // achieved by executing the finally, the other two levels
 are assumed consistent.
            consistentLevel1 = false;
            consistentLevel2 = true;
            consistentLevel3 = true;

            // Signal the parent thread, from this point on the thread
 can be aborted.
            wait.Set();

            // Halt now if we want a one level stack.
            if (depth == 1)
                Thread.Sleep(-1);

            // Else move to the next level.
            StackDepth2();

        }
        finally
        {
            // We should always get here. Compute consistency based
 on all the levels.
            consistentLevel1 = consistentLevel2 && consistentLevel3;
        }
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [MethodImpl(MethodImplOptions.NoInlining)]
    void StackDepth2()
    {
        try
        {
            consistentLevel2 = false;
            if (depth == 2)
                Thread.Sleep(-1);
            StackDepth3();
        }
        finally
        {
            consistentLevel2 = true;
        }
    }
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [MethodImpl(MethodImplOptions.NoInlining)]
    void StackDepth3()
    {
        try
        {
            consistentLevel3 = false;
            if (depth == 3)
                Thread.Sleep(-1);
            StackDepth4();
        }
        finally
        {
            consistentLevel3 = true;
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void StackDepth4()
    {
        if (depth == 4)
            Thread.Sleep(-1);
        StackDepth5();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void StackDepth5()
    {
        Thread.Sleep(-1);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ReliabilityContractAttribute クラス
ReliabilityContractAttribute メンバ
System.Runtime.ConstrainedExecution 名前空間

ReliabilityContractAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Cer 制約された実行領域 (CER) で呼び出されたときの、メソッド、型、またはアセンブリの動作を決定する値を取得します。
パブリック プロパティ ConsistencyGuarantee Consistency の信頼性のコントラクトの値を取得します。
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。)
参照参照

関連項目

ReliabilityContractAttribute クラス
System.Runtime.ConstrainedExecution 名前空間
Consistency 列挙体
Cer 列挙体

ReliabilityContractAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
参照参照

関連項目

ReliabilityContractAttribute クラス
System.Runtime.ConstrainedExecution 名前空間
Consistency 列挙体
Cer 列挙体

ReliabilityContractAttribute メンバ

一部のコードの作成者とそのコードに依存している開発者の間の信頼性のコントラクトを定義します。

ReliabilityContractAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ReliabilityContractAttribute 指定した Consistency 保証と Cer 値を使用して、ReliabilityContractAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cer 制約された実行領域 (CER) で呼び出されたときの、メソッド、型、またはアセンブリの動作を決定する値を取得します。
パブリック プロパティ ConsistencyGuarantee Consistency の信頼性のコントラクトの値を取得します。
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
参照参照

関連項目

ReliabilityContractAttribute クラス
System.Runtime.ConstrainedExecution 名前空間
Consistency 列挙体
Cer 列挙体



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ReliabilityContractAttribute」の関連用語

ReliabilityContractAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ReliabilityContractAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS