Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ExpressionEditor Class


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

Defines a set of properties and methods for evaluating an expression that is associated with a control property at design time and to provide an expression editor sheet to the visual design host for use in the expression editor dialog box. This class is abstract.

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

public abstract class ExpressionEditor


Initializes a new instance of the ExpressionEditor class.


Gets the expression prefix that identifies expression strings that are supported by the expression editor implementation.


Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodEvaluateExpression(String, Object, Type, IServiceProvider)

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


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticGetExpressionEditor(String, IServiceProvider)

Returns an ExpressionEditor implementation that is associated with the specified expression prefix.

System_CAPS_pubmethodSystem_CAPS_staticGetExpressionEditor(Type, IServiceProvider)

Returns an ExpressionEditor implementation that is associated with the specified expression builder type.

System_CAPS_pubmethodGetExpressionEditorSheet(String, IServiceProvider)

Returns an expression editor sheet that is associated with the current expression editor.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

A visual designer host, such as Visual Studio 2005, uses the ExpressionEditor class to present custom expression editor sheets to the user, and then evaluate the selected expression for design-time rendering.

When you browse the Expressions property for a control in the design-time Properties grid, the visual designer displays a dialog box to set expressions for a control property. You can select the expression type based on a list of expression prefixes. When you select an expression prefix from the list, the visual designer uses the associated ExpressionEditor and ExpressionEditorSheet objects to set, evaluate, and convert the expression string based on the syntax for that type of expression. The visual designer sets the expression for the associated control property, and then uses the evaluated expression result to assign control property values that are rendered on the design surface.

The static GetExpressionEditor methods get the expression editor that is associated with a particular expression prefix or expression builder. The ExpressionPrefix property for an ExpressionEditor object returns the configured expression prefix. The EvaluateExpression method evaluates an input expression string. The GetExpressionEditorSheet method returns the ExpressionEditorSheet implementation that is used to prompt for the custom expression properties in the expressions dialog box.

Typically, to support a new expression type at design time, you define a unique expression prefix and provide custom ExpressionBuilder and ExpressionEditor implementations. Optionally, you can provide a custom ExpressionEditorSheet implementation that defines properties that are used to form the expression in the expressions dialog box.

The expression prefix identifies the custom expression type and associates an expression with the expression builder and expression editor. When custom expressions are parsed in a page, the expression prefix is used to create instances of the associated ExpressionBuilder and ExpressionEditor classes. To associate an expression prefix with an expression builder and expression editor, apply the ExpressionEditorAttribute and ExpressionPrefixAttribute attributes to the custom ExpressionBuilder class and configure the expression prefix for an expression builder in the expressionBuilders element in the Web configuration file. The prefix is not required, but highly recommended.

Notes to Inheritors:

The following steps are required in deriving a custom ExpressionEditor class:

  • Override the EvaluateExpression method to evaluate the custom expression type at design time.

  • Optionally, override the GetExpressionEditorSheet method to return a custom class that defines properties that are combined to form the custom expression.

  • Apply the ExpressionEditorAttribute attribute on the ExpressionBuilder class declaration to associate the custom expression builder with the derived expression editor class.

For example, the ResourceExpressionEditor class derives from the ExpressionEditor class and provides an implementation for evaluating and associating a resource string reference with a control property at design time. The ResourceExpressionBuilder class is associated with the expression prefix Resources and the ResourceExpressionEditor implementation. The GetExpressionEditorSheet method returns a ResourceExpressionEditorSheet, which defines the individual properties that form a resource reference expression.

The following code example demonstrates how to derive from the ExpressionEditor class to define a custom expression editor.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.CodeDom;
using System.Configuration;
using System.Web.UI.Design;
using System.Web.Compilation;

namespace ExpressionEditorSamples.CS
    public class CustomAppSettingsBuilder : AppSettingsExpressionBuilder
        // Use the built-in AppSettingsExpressionBuilder class,
        // but associate it with a custom expression editor class.


    public class CustomAppSettingsEditor : System.Web.UI.Design.ExpressionEditor
        public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider)
            KeyValueConfigurationCollection customSettings = null;

            if (serviceProvider != null)
                IWebApplication webApp = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));
                if (webApp != null)
                    Configuration config = webApp.OpenWebConfiguration(true);
                    if (config != null)
                        AppSettingsSection settingsSection = config.AppSettings;
                        if (settingsSection != null)
                            customSettings = settingsSection.Settings;


            if (customSettings != null)
                return customSettings[expression];

            return expression;


.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2018 Microsoft