ExpressionEditor.EvaluateExpression Method (String, Object, Type, IServiceProvider)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Web.UI.Design
Assembly:  System.Design (in System.Design.dll)

public abstract object EvaluateExpression(
	string expression,
	object parseTimeData,
	Type propertyType,
	IServiceProvider serviceProvider
)

Parameters

expression
Type: System.String

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

parseTimeData
Type: System.Object

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

propertyType
Type: System.Type

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

serviceProvider
Type: System.IServiceProvider

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

Return Value

Type: System.Object

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

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 Inheritors:

Classes deriving from the ExpressionEditor class must override the EvaluateExpression method to evaluate the custom expression type at design time.

At a minimum, an EvaluateExpression 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 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 implementation can use the parseTimeData object that is supplied by the ExpressionBuilder.ParseExpression implementation to optimize or help in the evaluation of the input expression string.

.NET Framework
Available since 2.0
Return to top
Show: