G
Guest
I am trying to use reflection to get the value of a property using Generics.
A sample property is as follows:
/// <summary>
/// Gets the collection of links rendered at the bottom of the header.
/// </summary>
/// <value>The links collection.</value>
[DefaultValue((string)null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor))]
[Category("Appearance")]
[Bindable(true)]
[ContainsLocalisationKeys(true)]
public List<CompanyNameHyperLink> Links
{
get
{
return m_links;
}
}
I am reflecting on this property to do some automatic localisation, using a
few attributes, etc.
I don't seem to be able to get .GetValue working with properties that use an
index (Collections, etc.) or Generics, such as the property above.
Can someone give me a line of code to get, for example
List<CompanyNameHyperLink> from the propertyInfo.GetValue() method?
For example (though this won't work):
PropertyInfo propertyInfo = myReflectedProperty; // Properly defined elsewhere
List<CompanyNameHyperLink> =
(List<CompanyNameHyperLink>)propertyInfo.GetValue(this, null);
I know that the propertyInfo is a List<> and I know it's attributes
(CompanyNameHyperLink) ... it's just the last little piece of pulling the
property values out of the PropertyInfo object.
Any help would be appreciated, since I've spent hours on this to no avail,
Christophe
A sample property is as follows:
/// <summary>
/// Gets the collection of links rendered at the bottom of the header.
/// </summary>
/// <value>The links collection.</value>
[DefaultValue((string)null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor))]
[Category("Appearance")]
[Bindable(true)]
[ContainsLocalisationKeys(true)]
public List<CompanyNameHyperLink> Links
{
get
{
return m_links;
}
}
I am reflecting on this property to do some automatic localisation, using a
few attributes, etc.
I don't seem to be able to get .GetValue working with properties that use an
index (Collections, etc.) or Generics, such as the property above.
Can someone give me a line of code to get, for example
List<CompanyNameHyperLink> from the propertyInfo.GetValue() method?
For example (though this won't work):
PropertyInfo propertyInfo = myReflectedProperty; // Properly defined elsewhere
List<CompanyNameHyperLink> =
(List<CompanyNameHyperLink>)propertyInfo.GetValue(this, null);
I know that the propertyInfo is a List<> and I know it's attributes
(CompanyNameHyperLink) ... it's just the last little piece of pulling the
property values out of the PropertyInfo object.
Any help would be appreciated, since I've spent hours on this to no avail,
Christophe