Converting/casting System.Reflection.PropertyInfo to CSLA.PropertyInfo<T> object

Converting/casting System.Reflection.PropertyInfo to CSLA.PropertyInfo<T> object

Old forum URL: forums.lhotka.net/forums/t/9299.aspx


fahahm posted on Friday, July 30, 2010

HI,

In one of my model class I registered a property using CSLA.PropertyInfo<T> object.

private

 

 

static PropertyInfo<string> LastNameProperty = RegisterProperty<string>(new PropertyInfo<string>("LastName", "Last Name", string

.Empty));

Now at the client side, I am using a sliverlight grid to bind the list of records. I need to retrieve all properteis of that model object and for that I am using the following linq code.

 

var result = from res in MyGrid.SelectedItem.GetType().GetProperties()

 

where res.DeclaringType.FullName == MyGrid.SelectedItem.GetType().FullName

 

The problem is the GetProperties() method returns enumberator of System.Reflection.PropertyInfo objects and I really need to either cast/convert it to the CSLA object so that I can fetch additonal information like friendly name that I added during registering it.

Anybody have any idea how to do this?

Fahahm

select res;

select res;

The problem is the GetProperties() method returns enumberator of System.Reflection.PropertyInfo objects and I really need to either cast/convert it to the CSLA object so that I can fetch additonal information like friendly name that I added during registering it.

Anybody have any idea how to do this?

Fahahm

 

RockfordLhotka replied on Friday, July 30, 2010

.NET reflection will obviously return .NET reflection types, not CSLA types.

To get the Csla.Core.IPropertyInfo (PropertyInfo<T>) objects you'll need to call a method on FieldManager from within your object itself. If you need this information outside the object, you'll need to add a public method on your object to externalize the information.

I suppose another option is to use .NET reflection to get all static fields from the object, then filter the results so you only have Csla.Core.IPropertyInfo objects - that'd get you all the properties with public PropertyInfo<T> fields.

Copyright (c) Marimer LLC