Export (0) Print
Expand All

ExpressionEditor Class

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

The ExpressionEditor type exposes the following members.

  NameDescription
Protected methodExpressionEditorInitializes a new instance of the ExpressionEditor class.
Top

  NameDescription
Public propertyExpressionPrefixGets the expression prefix that identifies expression strings that are supported by the expression editor implementation.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodEvaluateExpressionEvaluates an expression string and provides the design-time value for a control property.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberGetExpressionEditor(String, IServiceProvider)Returns an ExpressionEditor implementation that is associated with the specified expression prefix.
Public methodStatic memberGetExpressionEditor(Type, IServiceProvider)Returns an ExpressionEditor implementation that is associated with the specified expression builder type.
Public methodGetExpressionEditorSheetReturns an expression editor sheet that is associated with the current expression editor.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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
{
    [ExpressionPrefix("CustomAppSettings")]
    [ExpressionEditor(typeof(ExpressionEditorSamples.CS.CustomAppSettingsEditor))]
    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

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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