Back to Devexpress

XPBaseObject.EvaluateAlias(String) Method

xpo-devexpress-dot-xpo-dot-xpbaseobject-dot-evaluatealias-x28-system-dot-string-x29.md

latest4.5 KB
Original Source

XPBaseObject.EvaluateAlias(String) Method

Evaluates an expression specified by the PersistentAliasAttribute attribute for the specified property.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public object EvaluateAlias(
    [CallerMemberName] string memberName = null
)
vb
Public Function EvaluateAlias(
    memberName As String = Nothing
) As Object

Optional Parameters

NameTypeDefaultDescription
memberNameStringnull

A string that specifies the name of the property that is declared with the PersistentAliasAttribute attribute.

|

Returns

TypeDescription
Object

A value evaluated.

|

Remarks

The PersistentAliasAttribute attribute indicates that a property is not persistent and it’s value is calculated based upon the values of a specific persistent field(s). A parameter of this attribute can specify an expression and the result of this expression can represent the property’s value.

Use the EvaluateAlias method to evaluate an expression specified by the PersistentAliasAttribute attribute. For instance, it can be used in a property’s implementation as shown in the example below.

Example

The following code shows how to define a property as non-persistent and calculate its value based upon the values of specific persistent fields. The ExtendedPrice property is marked as a non-persistent, using the PersistentAliasAttribute attribute. The expression to evaluate the property’s value is specified as the attribute’s parameter. In addition, the property’s getter evaluates this expression using the XPBaseObject.EvaluateAlias method.

csharp
using DevExpress.Xpo;

public class Order : XPObject {
   public Order() {}
   public decimal UnitPrice {
       get { return fUnitPrice; }
       set { SetPropertyValue(nameof(UnitPrice), ref fUnitPrice, value); }
   }
   decimal fUnitPrice;

   public int Qty {
       get { return fQty; }
       set { SetPropertyValue(nameof(Qty), ref fQty, value); }
   }
   int fQty;

   public decimal Discount {
       get { return fDiscount; }
       set { SetPropertyValue(nameof(Discount), ref fDiscount, value); }
   }
   decimal fDiscount;

   [PersistentAlias("UnitPrice*Qty*(1-Discount)")]
   public decimal ExtendedPrice {
      get { return Convert.ToDecimal(EvaluateAlias(nameof(ExtendedPrice))); }
   }
}
vb
Imports DevExpress.Xpo

Public Class Order
   Inherits XPObject
   Public Sub New()
   End Sub
   Public Property UnitPrice() As Decimal
       Get
           Return fUnitPrice
       End Get
       Set(ByVal value as Decimal)
           SetPropertyValue(NameOf(UnitPrice), fUnitPrice, value)
       End Set
   End Property
   Private fUnitPrice As Decimal

   Public Property Qty() As Integer
       Get
           Return fQty
       End Get
       Set(ByVal value as Integer)
           SetPropertyValue(NameOf(Qty), fQty, value)
       End Set
   End Property
   Private fQty As Integer

   Public Property Discount() As Decimal
       Get
           Return fDiscount
       End Get
       Set(ByVal value as Decimal)
           SetPropertyValue(NameOf(Discount), fDiscount, value)
       End Set
   End Property
   Private fDiscount As Decimal

   <PersistentAlias("UnitPrice*Qty*(1-Discount)")> _
   Public ReadOnly Property ExtendedPrice() As Decimal
      Get
         Return Convert.ToDecimal(EvaluateAlias(NameOf(ExtendedPrice)))
      End Get
   End Property
End Class

See Also

Evaluate

XPBaseObject Class

XPBaseObject Members

DevExpress.Xpo Namespace