ExpressionContext.PresetValue Property


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

Gets the preset value of an expression.

Namespace:   System.ComponentModel.Design.Serialization
Assembly:  System.Design (in System.Design.dll)

public object PresetValue { get; }

Property Value

Type: System.Object

The preset value of this expression, or null if not assigned.

Contains the preset value of an expression, should one exist. For example, if the expression is a property reference expression referring to the Controls property of a Button, the PresetValue property contains the instance of the Controls property. This is because the property is read-only and preset by the object to contain a value. On the other hand, a property such as Text or Visible does not have a preset value and therefore the PresetValue property returns null.

The following C# code shows how serializers can use this information to guide serialization.


Padding p = new Padding();
p.Left = 5;
button1.Padding = p;

button1.Padding.Left = 5;

The serializer of the Padding structure needs to be informed if it should generate the first or second form. The first form is generated by default. The second form is only generated if there is an ExpressionContext on the context stack that contains a PresetValue equal to the value of the Padding currently being serialized.

.NET Framework
Available since 2.0
Return to top