Ticket Q504178
Visible to All Users

Get properties values from XPO Objects by Name

created 12 years ago

Dear friends:

I need a method for getting properties values of an Xpo Object. Supose i have an objet thas is a person and has a name property and a relation
of address where he has lived. I need somethin like this

GetPropertyValue("Name") and returns the value of the proptery name

GetPropertyValue("Address[0].City") and returns Ney York

GetPropertyValue("Wife.Name") Wife is another Xpo Object

Note that i need to lookup for the name property as a string because this will be a variable in a line of text. For example

Dear <<Name>> we know you have changed your city to <<Adress[0].City>> with your wife <<Wife.Name>>

Wich is the best approach?

Best Regards

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hi Manel.
You can access values of object properties using the XPBaseObject.GetMemberValue method. However, it does not support nested property paths and indexed access. You should implement parsing of such complex paths yourself.

    Other Answers

    created 8 years ago
    C#
    public static object GetNestedMemberValue(this XPBaseObject o, string PropertyName) { if (PropertyName.Contains(".")) { int i = PropertyName.IndexOf('.'); string baseProp = PropertyName.Substring(0, i); object oBO = o.GetMemberValue(baseProp); if (oBO == null || !(oBO is XPBaseObject)) return null; string subProp = PropertyName.Substring(i + 1, PropertyName.Length - i - 1); return (o.GetMemberValue(baseProp) as XPBaseObject).GetNestedMemberValue(subProp); } else return o.GetMemberValue(PropertyName); }

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.