0

I'm using telerik tools and have a tool that runs code server side from a class library on an ajax call.

This control can come from any page. And I can access the page by the telerik object that's passed in.

Now, some of these pages have a property that I want to access, but I want to keep it generic.

I can cast the page as a specific page type and expose the property, but that would require an update to the class library every time that property is added to a page.

What I'm wondering is if there is a way for me to check to see if a property exists on the page, then access it if it does?

((Telerik.Web.UI.ControlItemContainer)((RadComboBox)o)).Page

This is how I access the page, which just returns a page object. I want to check to see if that page object contains a property without casting it.

Or if I can cast the page with using gettype(), that would work as well.

Thanks

4

1 回答 1

1

你可以使用反射

System.Reflection.PropertyInfo propInfo = 
    theObjectYouWantToReflect.GetType().GetProperty("YourPropertyName");

if (propInfo != null)
{
    object value = propInfo.GetValue(Page, null);
    // ...
}
于 2012-06-08T19:03:13.097 回答