Cannot get Descriptor property using reflection

3 posts, 1 answers
  1. Marek
    Marek avatar
    2 posts
    Member since:
    Nov 2013

    Posted 02 Jan 2014 Link to this post

    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. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 02 Jan 2014 Link to this post

    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 >>
  3. DevCraft banner
  4. Marek
    Marek avatar
    2 posts
    Member since:
    Nov 2013

    Posted 03 Jan 2014 Link to this post

    Thanks it's work :)
Back to Top