Edit

Share via


IIdentifierCreationService.ValidateIdentifier(Activity, String) Method

Definition

Provides a mechanism to test that an identifier is unique within an 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)

Parameters

activity
Activity

The Activity against which to test the identifier.

identifier
String

The identifier to test for validity.

Examples

The following example shows an implementation of the IIdentifierCreationService. This service ensures that each of the identifiers used within the current workflow is unique.

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

Remarks

Use ValidateIdentifier to make sure an identifier is unique and properly formatted for use within a specified Activity.

Applies to