ExpressionServices.ConvertReference<TResult> Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Konverterar en referens till ett miljömedvetent arbetsflödesuttryck till ett aktivitetsträd.
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))
Typparametrar
- TResult
Typen som uttrycket konverteras till.
Parametrar
- expression
- Expression<Func<ActivityContext,TResult>>
Uttrycket som konverteras.
Returer
Det konverterade uttrycket.
Exempel
Följande två kodexempel illustrerar användningen av ConvertReference och Convert. Det första kodexemplet används ConvertReference i en Assign aktivitet för att konvertera ett lambda-uttryck till en strängegenskap som har tilldelats ett värde.
Convert Därefter anropas för att konvertera ett lambda-uttryck till ett strängegenskapsvärde som skrivs ut till konsolen i WriteLine aktiviteten.
// 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);
}
Följande kodexempel liknar det föregående, förutom att uttrycket som ska konverteras är en referens till ett objekt i en flerdimensionell matris.
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);
}
Kommentarer
Konverteringsmetoderna i ExpressionServices är utformade för att fungera med variabler och konstanter som definieras i arbetsflödet eller skickas till arbetsflödet via argument.