共用方式為


IIdentifierCreationService.ValidateIdentifier(Activity, String) 方法

定義

提供一個機制來測試 Activity 中的識別項是唯一的。

public:
 void ValidateIdentifier(System::Workflow::ComponentModel::Activity ^ activity, System::String ^ identifier);
public void ValidateIdentifier (System.Workflow.ComponentModel.Activity activity, string identifier);
abstract member ValidateIdentifier : System.Workflow.ComponentModel.Activity * string -> unit
Public Sub ValidateIdentifier (activity As Activity, identifier As String)

參數

activity
Activity

用來測試識別項的 Activity

identifier
String

要測試有效性的識別項。

範例

下列範例將示範 IIdentifierCreationService 的實作。 這個服務可確保目前工作流程中所使用的每一個識別項都是唯一的。

void IIdentifierCreationService.ValidateIdentifier(Activity activity, string identifier)
{
    if (identifier == null)
        throw new ArgumentNullException("identifier");
    if (activity == null)
        throw new ArgumentNullException("activity");

    if (activity.Name.ToLower().Equals(identifier.ToLower()))
        return;

    ArrayList identifiers = new ArrayList();
    Activity rootActivity = GetRootActivity(activity);
    identifiers.AddRange(GetIdentifiersInCompositeActivity(rootActivity as CompositeActivity));
    identifiers.Sort();
    if (identifiers.BinarySearch(identifier.ToLower(), StringComparer.OrdinalIgnoreCase) >= 0)
        throw new ArgumentException(string.Format("Duplicate Component Identifier {0}", identifier));
}
Sub ValidateIdentifier(ByVal activity As Activity, ByVal identifier As String) Implements IIdentifierCreationService.ValidateIdentifier
    If identifier Is Nothing Then
        Throw New ArgumentNullException("identifier")
    End If
    If activity Is Nothing Then
        Throw New ArgumentNullException("activity")
    End If
    If activity.Name.ToLower().Equals(identifier.ToLower()) Then
        Return
    End If
    Dim identifiers As New ArrayList()
    Dim rootActivity As Activity = GetRootActivity(activity)
    identifiers.AddRange(GetIdentifiersInCompositeActivity(CType(rootActivity, CompositeActivity)))
    identifiers.Sort()
    If identifiers.BinarySearch(identifier.ToLower(), StringComparer.OrdinalIgnoreCase) >= 0 Then
        Throw New ArgumentException(String.Format("Duplicate Component Identifier 0}", identifier))
    End If
End Sub

備註

使用 ValidateIdentifier 來確保使用在指定的 Activity 識別項是唯一且格式正確的。

適用於