This is a migrated thread and some comments may be shown as answers.

Cannot get Descriptor property using reflection

2 Answers 39 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Marek
Top achievements
Rank 1
Marek asked on 02 Jan 2014, 02:02 PM
Hi,
I cannot get Descriptor property using reflection:

PropertyInfo[] propertiesInfo;
PropertyInfo attributePropertyInfo;
 
foreach (var propertyDefinition in infrastructureItemPropertyGrid.PropertyDefinitions)
{
            propertiesInfo = propertyDefinition.SourceProperty.Descriptor.GetType().GetProperties();
            attributePropertyInfo = propertiesInfo.FirstOrDefault(x => x.Name == "Attributes");
 
            (Attribute[])(attributePropertyInfo.GetValue(propertyDefinition.SourceProperty.Descriptor, null));
}

i get exception in IE Console:

Message: System.MethodAccessException: Attempt by method 'ProIntegra.UDC.Frontend.GUI.DCRoom.Controls.DCObjectPropertiesControl.SetUnitsInRadPropertyGriditems(System.Tuple`3<ProIntegra.Frameworks.GlobalHelpers.CapacityUnits,ProIntegra.Frameworks.GlobalHelpers.LengthUnits,ProIntegra.Frameworks.GlobalHelpers.WeightUnits>)' to access method 'Telerik.SilverlightExtensions.PropertyDescriptor.get_Attributes()' failed.
   w System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
   w System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
   w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   w System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   w System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)

Anyone can help me?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 02 Jan 2014, 04:13 PM
Hi,

Due to security limitations, reflection API in Silverlight cannot acces any non-public members and in your scenario "Attributes" is a property derived from an internal class. However, you should be able to use something like this:
(sender as RadPropertyGrid).Item.GetType().GetProperty(e.PropertyDefinition.SourceProperty.Name).GetCustomAttributes(true);


Regards,
Ivan Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Marek
Top achievements
Rank 1
answered on 03 Jan 2014, 09:56 AM
Thanks it's work :)
Tags
PropertyGrid
Asked by
Marek
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Marek
Top achievements
Rank 1
Share this question
or