Switch<T> 類別

定義

根據此物件類型規範中指定類型的特定運算式值,從活動成員中選取要執行的一個選項。Selects one choice from a number of activities to execute, based on the value of a given expression of the type specified in this object's type specifier.

generic <typename T>
public ref class Switch sealed : System::Activities::NativeActivity
[System.Windows.Markup.ContentProperty("Cases")]
public sealed class Switch<T> : System.Activities.NativeActivity
type Switch<'T> = class
    inherit NativeActivity
Public NotInheritable Class Switch(Of T)
Inherits NativeActivity

類型參數

T

Cases 集合中提供的值型別。The type of the values provided in the Cases collection.

繼承
屬性

範例

下列程式碼範例將示範如何建立 Switch<T> 活動。The following code sample demonstrates creating a Switch<T> activity. 這個範例來自使用程式活動範例。This example is from the Using Procedural Activities sample.

// check if the number is ok...
new Switch<int>()
{
    DisplayName = "Verify Value from User",
    Expression = ExpressionServices.Convert<int>( env => numberFromUser.Get(env).CompareTo(numberToGuess.Get(env)) ),
    Cases = 
    {
        { 0, new Assign<bool>()
            {
                To = new OutArgument<bool>(finished),
                Value = true
            }
        },
        {  1, new WriteLine() { Text = "    Try a lower number number..." } }, 
        { -1, new WriteLine() { Text = "    Try a higher number" } }
    }
}

備註

Cases 字典中的每個案例都是由值 (做為字典的索引鍵) 與活動 (做為字典的值) 構成。Each case in the Cases dictionary consists of a value (serving as the key for the dictionary) and an activity (serving as the value for the dictionary). Expression 會進行評估,並與 Cases 字典中的索引鍵進行比較。The Expression is evaluated and compared against the keys in the Cases dictionary. 如果找到符合的項目,則會執行對應的活動。If a match is found, the corresponding activity is executed. 根據字典的相等Cases比較子, 字典中的每個索引鍵都必須是唯一的。Every key in the Cases dictionary must be unique according to the dictionary's equality comparer.

建構函式

Switch<T>()

建立 Switch<T> 類別的新執行個體。Creates a new instance of the Switch<T> class.

Switch<T>(Activity<T>)

使用指定的運算式來建立 Switch<T> 類別的新執行個體。Creates a new instance of the Switch<T> class with the specified expression.

Switch<T>(Expression<Func<ActivityContext,T>>)

使用指定的運算式來建立 Switch<T> 類別的新執行個體。Creates a new instance of the Switch<T> class with the specified expression.

Switch<T>(InArgument<T>)

使用指定的運算式來建立 Switch<T> 類別的新執行個體。Creates a new instance of the Switch<T> class with the specified expression.

屬性

CacheId

取得工作流程定義範圍內的唯一快取識別碼。Gets the identifier of the cache that is unique within the scope of the workflow definition.

(繼承來源 Activity)
CanInduceIdle

取得或設定值,這個值指出此活動是否會造成工作流程變為閒置。Gets or sets a value that indicates whether the activity can cause the workflow to become idle.

(繼承來源 NativeActivity)
Cases

表示可能之執行路徑的字典。Represents the dictionary of potential execution paths. 每個項目都會包含當運算式結果符合索引鍵時執行的索引鍵與活動。Each entry contains a key and an activity that is executed when the result of the expression matches the key.

Constraints

取得 Constraint 活動的集合,這些活動可以設定為提供 Activity 的驗證。Gets a collection of Constraint activities that can be configured to provide validation for the Activity.

(繼承來源 Activity)
Default

表示如果 Cases 集合中沒有符合 Expression 屬性的項目索引鍵時執行的活動。Represents the activity that is executed if no keys of entries in the Cases collection match the Expression property.

DisplayName

取得或設定選擇性的易記名稱,這個名稱會用於偵錯、驗證、例外狀況處理及追蹤。Gets or sets an optional friendly name that is used for debugging, validation, exception handling, and tracking.

(繼承來源 Activity)
Expression

取得與 Cases 集合中索引鍵比較的物件。Gets the object to compare to the keys in the Cases collection.

Id

取得工作流程定義範圍內的唯一識別碼。Gets an identifier that is unique in the scope of the workflow definition.

(繼承來源 Activity)
Implementation

活動的執行邏輯。The execution logic of the activity.

(繼承來源 NativeActivity)
ImplementationVersion

取得或設定活動的實作版本。Gets or sets the implementation version of the activity.

(繼承來源 NativeActivity)

方法

Abort(NativeActivityAbortContext)

在衍生類別中實作時,會採取動作以回應中止的活動。When implemented in a derived class, takes actions in response to the activity being aborted.

(繼承來源 NativeActivity)
CacheMetadata(ActivityMetadata)

未實作。Not implemented. 請改用 CacheMetadata(NativeActivityMetadata) 方法。Use the CacheMetadata(NativeActivityMetadata) method instead.

(繼承來源 NativeActivity)
CacheMetadata(NativeActivityMetadata)

建立並驗證活動引數、變數、子活動和活動委派的描述。Creates and validates a description of the activity's arguments, variables, child activities, and activity delegates.

(繼承來源 NativeActivity)
Cancel(NativeActivityContext)

在衍生類別中實作時,執行邏輯以便在非失誤性的狀況下及早完成活動。When implemented in a derived class, runs logic to cause graceful early completion of the activity.

(繼承來源 NativeActivity)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Execute(NativeActivityContext)

在衍生類別中實作時,執行活動的執行邏輯。When implemented in a derived class, runs the activity's execution logic.

(繼承來源 NativeActivity)
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)
OnCreateDynamicUpdateMap(NativeActivityUpdateMapMetadata, Activity)

建立動態更新的對應時引發事件。Raises an event when creating a map for the dynamic update.

(繼承來源 NativeActivity)
OnCreateDynamicUpdateMap(UpdateMapMetadata, Activity)

建立動態更新的對應時引發事件。Raises an event when creating a map for the dynamic update.

(繼承來源 NativeActivity)
ShouldSerializeDisplayName()

指出是否應序列化 DisplayName 屬性。Indicates whether the DisplayName property should be serialized.

(繼承來源 Activity)
ToString()

傳回包含 StringIdDisplayNameActivityReturns a String that contains the Id and DisplayName of the Activity.

(繼承來源 Activity)
UpdateInstance(NativeActivityUpdateContext)

更新 NativeActivity 的執行個體。Updates the instance of NativeActivity.

(繼承來源 NativeActivity)

適用於