Finding properties in dot net which return a certain type

  • Thread starter Thread starter PseudoBill
  • Start date Start date
P

PseudoBill

How would I find properties in a dot net assembly which return a
particular type?

e.g., suppose a type I'm interested in is "FooType"; how would I find
properties returning "FooType"?
 
How would I find properties in a dot net assembly which return a
particular type?

e.g., suppose a type I'm interested in is "FooType"; how would I find
properties returning "FooType"?

you have to learn how to use reflection. basically, you iterate through
assembly's types and through properties within each type. Having a
PropertyInfo object, you ask for its .PropertyType property.

foreach ( Type t in assembly.GetTypes() )
foreach ( PropertyInfo pi in t.GetProperties() )
{
if ( pi.PropertyType == typeof( FooType ) )
{
}
}

regards,
Wiktor Zychla
 
Wiktor Zychlawrote:
you have to learn how to use reflection. basically, you iterate
through
assembly's types and through properties within each type. Having a
PropertyInfo object, you ask for its .PropertyType property.

foreach ( Type t in assembly.GetTypes() )
foreach ( PropertyInfo pi in t.GetProperties() )
{
if ( pi.PropertyType == typeof( FooType ) )
{
}
}

regards,
Wiktor Zychla

Thanks Wiktor! That works very well.
 
Back
Top