Redigera

Dela via


ExpressionEditor.EvaluateExpression Method

Definition

Evaluates an expression string and provides the design-time value for a control property.

public:
 abstract System::Object ^ EvaluateExpression(System::String ^ expression, System::Object ^ parseTimeData, Type ^ propertyType, IServiceProvider ^ serviceProvider);
public abstract object EvaluateExpression (string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider);
abstract member EvaluateExpression : string * obj * Type * IServiceProvider -> obj
Public MustOverride Function EvaluateExpression (expression As String, parseTimeData As Object, propertyType As Type, serviceProvider As IServiceProvider) As Object

Parameters

expression
String

An expression string to evaluate. The expression does not include the expression prefix.

parseTimeData
Object

An object containing additional parsing information for evaluating expression. This typically is provided by the expression builder.

propertyType
Type

The type of the control property to which expression is bound.

serviceProvider
IServiceProvider

A service provider implementation supplied by the designer host, used to obtain additional design-time services.

Returns

The object referenced by the evaluated expression string, if the expression evaluation succeeded; otherwise, null.

Remarks

The visual designer host uses the EvaluateExpression method to evaluate an expression and provide the design-time value for an associated control property.

The visual designer uses the ExpressionBuilder.ParseExpression method to parse the expression string at design time, and then calls the EvaluateExpression method with the parsed expression data. The visual designer uses the evaluated expression result to assign control property values that are rendered on the design surface.

Notes to Implementers

Classes deriving from the ExpressionEditor class must override the EvaluateExpression(String, Object, Type, IServiceProvider) method to evaluate the custom expression type at design time.

At a minimum, an EvaluateExpression(String, Object, Type, IServiceProvider) implementation must use the following steps:

  1. Evaluate the expression string and determine the object that is referenced by the expression.

  2. Return null, if the expression string cannot be evaluated.

  3. Use the IsAssignableFrom(Type) method on propertyType to determine whether the referenced object can be assigned directly to the control property type, and then, depending on the result, complete one of the following actions:

    • If the referenced object can be assigned directly to the control property, return the referenced object for the expression.

    • If the referenced object is a simple type, such as a string, return the referenced object.

    • Otherwise, determine whether the referenced object can be assigned to or converted to the property type.

  4. Use the CanConvertFrom method on the TypeConverter object for propertyType to determine whether the referenced object can be converted to the control property type, and then, depending on the result, complete one of the following actions:

    • If the object can be converted to the control property type, return the converted object using the ConvertFrom method.

    • If the referenced object cannot be assigned or converted to propertyType, return the referenced object.

Optionally, the EvaluateExpression(String, Object, Type, IServiceProvider) implementation can use the parseTimeData object that is supplied by the ParseExpression(String, Type, ExpressionBuilderContext) implementation to optimize or help in the evaluation of the input expression string.

Applies to

See also