ExpressionServices.ConvertReference<TResult> 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將工作流程環境感知表達式的參考轉換為活動樹。
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>>
這個表達正在轉換。
傳回
那個被轉化的表情。
範例
以下兩個程式碼範例說明了 和 ConvertReference的使用Convert。 第一個程式碼範例在活動ConvertReference中將 Assign lambda 表達式轉換成一個字串屬性,並被指派一個值。 接著, Convert 呼叫 將 lambda 運算式轉換成字串屬性值,並列印到活動中的 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);
}
以下的程式碼範例與前一個類似,但 convert 的運算式是多維陣列中的一個項目參考。
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 轉換方法設計用來處理工作流程中定義的變數和常數,或透過參數傳遞到工作流程中。