Ticket T1005449
Visible to All Users

Blazor - The performance of XPMemberInfo.GetValue and XPMemberInfo.SetValue can be better than the performance of reflection classes (PropertyInfo, FieldInfo)

created 4 years ago (modified 4 years ago)

[DevExpress Support Team: CLONED FROM T1003220: Blazor - How to implement a Progress Bar in Grid List Editor cells]

Hi,

This is pretty cool !
May propose something more generic that works with all objects.
I saw in this ticket that the performance of XPMemberInfo.GetValue and XPMemberInfo.SetValue may be better than the performance of reflection classes (PropertyInfo, FieldInfo) because XPMemberInfo makes special accessors to properties by ILGenerator class.

So should we use XPMemberInfo (commented part) ? Both solution are working just curious about performance here.

C#
[PropertyEditor(typeof(int), TestProgressBusinessObject.ProgressPropertyAlias, false)] public class ProgressBarEditor : BlazorPropertyEditorBase, IComplexViewItem { private BlazorApplication application; private IObjectSpace objectSpace; public ProgressBarEditor(Type objectType, IModelMemberViewItem model) : base(objectType, model) { } void IComplexViewItem.Setup(IObjectSpace objectSpace, XafApplication application) { this.objectSpace = objectSpace; this.application = (BlazorApplication)application; } protected override IComponentAdapter CreateComponentAdapter() => new ProgressBarAdapter(new ProgressBarModel()); protected override RenderFragment CreateViewComponentCore(object dataContext) { //var testProgressBusinessObject = (TestProgressBusinessObject)dataContext; //XPClassInfo classInfo = ((XPObjectSpace)objectSpace).Session.GetClassInfo(dataContext.GetType()); //var value = classInfo.GetMember(PropertyName).GetValue(dataContext); var value = this.ObjectTypeInfo.FindMember(PropertyName).GetValue(dataContext); ProgressBarModel progressBarModel = new ProgressBarModel() { Value = (int)value }; return ProgressBarRenderer.Create(progressBarModel); } }

Answers approved by DevExpress Support

created 4 years ago

Hello Isa_Tahiri,

Thank you for sharing your code with us. In the case of using XPO, the following code works with XPMemberInfo.GetValue and XPMemberInfo.SetValue methods: this.ObjectTypeInfo.FindMember(PropertyName).GetValue(dataContext);. So, you can use both solutions without worrying about the performance.

    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.