ExpressionServices.ConvertReference<TResult> メソッド

定義

ワークフロー環境対応式への参照をアクティビティ ツリーに変換します。

public:
generic <typename TResult>
 static System::Activities::Activity<System::Activities::Location<TResult> ^> ^ ConvertReference(System::Linq::Expressions::Expression<Func<System::Activities::ActivityContext ^, TResult> ^> ^ expression);
public static System.Activities.Activity<System.Activities.Location<TResult>> ConvertReference<TResult> (System.Linq.Expressions.Expression<Func<System.Activities.ActivityContext,TResult>> expression);
static member ConvertReference : System.Linq.Expressions.Expression<Func<System.Activities.ActivityContext, 'Result>> -> System.Activities.Activity<System.Activities.Location<'Result>>
Public Shared Function ConvertReference(Of TResult) (expression As Expression(Of Func(Of ActivityContext, TResult))) As Activity(Of Location(Of TResult))

型パラメーター

TResult

式の変換先にする型。

パラメーター

expression
Expression<Func<ActivityContext,TResult>>

変換する式。

戻り値

Activity<Location<TResult>>

変換後の式。

次の 2 つのコード例は、ConvertReferenceConvert の使用例を示しています。 最初のコード例では、ConvertReferenceAssign アクティビティで使用して、値が割り当てられた文字列プロパティにラムダ式を変換します。 次に、Convert が呼び出されてラムダ式が文字列プロパティ値に変換され、WriteLine アクティビティのコンソールに値が出力されます。

// Define a struct with a property named AProperty.  
struct StructWithProperty  
{  
    public string AProperty { get; set; }  
}  

public static void ConvertReferenceForValueTypePropertyReferenceSample()  
{              
    // Create a variable of type StructWithProperty to store the property.  
    var swpvar = new Variable<StructWithProperty>("swpvar", new StructWithProperty());  

    Activity myActivity = new Sequence  
    {  
        Variables = { swpvar },  
        Activities =   
        {                      
            // Create an Assign activity to assign a value to the AProperty property.  
            new Assign<string>  
            {  
                To = ExpressionServices.ConvertReference<string>(ctx => swpvar.Get(ctx).AProperty),  
                // Assign a string literal to AProperty.  
                Value = "Hello",  
            },  
            // Print the new property value to the console.  
            new WriteLine()  
            {  
                Text = ExpressionServices.Convert<string>(ctx => swpvar.Get(ctx).AProperty),  
            }  
        }  
    };  

    // Invoke the Sequence activity.  
    WorkflowInvoker.Invoke(myActivity);  
}  

次のコード例は前の例と似ていますが、変換するための式が多次元配列内の項目への参照である点が異なります。

public static void ConvertReferenceForMultidimensionalArrayItemReferenceSample()  
{  
    // Create a variable to store a multidimensional array.  
    var arrayvar = new Variable<int[,]>("arrayvar", new int[4, 5]);  

    Activity myActivity = new Sequence  
    {  
        Variables = { arrayvar },  
        Activities =   
        {                      
            // Create an Assign activity to assign a value to the array item at index [1,2].  
            new Assign<int>  
            {  
                To = ExpressionServices.ConvertReference<int>(ctx => arrayvar.Get(ctx)[1, 2]),  
                // Assign an integer value to the array item at row 1 column 2.  
                Value = 1,  
            },  
            // Print the array item value to the console.  
            new WriteLine()  
            {  
                Text = ExpressionServices.Convert<string>(ctx => arrayvar.Get(ctx)[1, 2].ToString()),  
            }  
        }  
    };  

    // Invoke the Sequence activity.  
    WorkflowInvoker.Invoke(myActivity);  
}  

注釈

ExpressionServices の変換メソッドは、ワークフロー内で定義されているか、引数経由でワークフローに渡された変数および定数で使用できるように設計されています。

適用対象