ContextUtil 類別

定義

取得 COM+ 物件內容的資訊。 此類別無法獲得繼承。

public ref class ContextUtil sealed
public sealed class ContextUtil
type ContextUtil = class
Public NotInheritable Class ContextUtil
繼承
ContextUtil

範例

下列程式代碼範例示範如何使用 ContextUtil 來建立交易 ServicedComponent式 。


[assembly:System::Reflection::AssemblyKeyFile("Transaction.snk")];
[Transaction]
public ref class TransactionalComponent: public ServicedComponent
{
public:
   void TransactionalMethod( String^ data )
   {
      ContextUtil::DeactivateOnReturn = true;
      ContextUtil::MyTransactionVote = TransactionVote::Abort;
      
      // do work with data
      ContextUtil::MyTransactionVote = TransactionVote::Commit;
   }

};
[Transaction]
public class TransactionalComponent : ServicedComponent
{

    public void TransactionalMethod (string data)
    {

      ContextUtil.DeactivateOnReturn = true;
      ContextUtil.MyTransactionVote = TransactionVote.Abort;

      // Do work with data. Return if any errors occur.

      // Vote to commit. If any errors occur, this code will not execute.
      ContextUtil.MyTransactionVote = TransactionVote.Commit;
    }
}
<Transaction()>  _
Public Class TransactionalComponent
    Inherits ServicedComponent
    
    
    Public Sub TransactionalMethod(ByVal data As String) 
        
        ContextUtil.DeactivateOnReturn = True
        ContextUtil.MyTransactionVote = TransactionVote.Abort
        
        ' Do work with data. Return if any errors occur.
        ' Vote to commit. If any errors occur, this code will not execute.
        ContextUtil.MyTransactionVote = TransactionVote.Commit
    
    End Sub
End Class

備註

ContextUtil 是用來取得 COM+ 內容資訊的慣用類別。 由於這個類別的成員全 static 都是在 Visual Basic) 中 (shared ,因此在使用這些成員之前不需要具現化它。

屬性

ActivityId

取得表示包含元件之活動的 GUID。

ApplicationId

取得目前應用程式的 GUID。

ApplicationInstanceId

取得目前應用程式執行個體的 GUID。

ContextId

取得目前內容的 GUID。

DeactivateOnReturn

取得或設定 COM+ 內容中的 done 位元。

IsInTransaction

取得值,指出目前內容是否可交易。

IsSecurityEnabled

取得值,指出以角色為基礎的安全性在目前內容中是否為作用中。

MyTransactionVote

取得或設定 COM+ 內容中的 consistent 位元。

PartitionId

取得目前分割的 GUID。

SystemTransaction

取得目前交易內容。

Transaction

取得描述目前 COM+ DTC 交易的物件。

TransactionId

取得目前 COM+ DTC 交易的 GUID。

方法

DisableCommit()

在 COM+ 內容中將 consistent 位元和 done 位元都設定為 false

EnableCommit()

在 COM+ 內容中將 consistent 位元設定為 true,而 done 位元設定為 false

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetNamedProperty(String)

從 COM+ 內容傳回具名屬性。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsCallerInRole(String)

判斷呼叫端是否在指定的角色中。

IsDefaultContext()

判斷在預設內容中是否啟動 Serviced 元件。 在預設內容中會啟動不具有 COM+ 目錄資訊的 Serviced 元件。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SetAbort()

在 COM+ 內容中將 consistent 位元設定為 false,而 done 位元設定為 true

SetComplete()

在 COM+ 內容中將 consistent 位元和 done 位元設定為 true

SetNamedProperty(String, Object)

設定 COM + 內容的具名屬性。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於