Click to See Complete Forum and Search --> : Reflection


Suzi167
September 12th, 2007, 10:09 AM
Hi I am using reflection and I need to get the properties out of my type
But I only want to get the properties that have both Get and Set Accessors.

How can I accomplish that using the BindingFlags enum?
Here is my code:




foreach (Type type in assembly.GetTypes())
{

foreach (PropertyInfo propInfo in type.GetProperties(BindingFlags.SetProperty | BindingFlags.GetProperty))
{

//do some stuff here.

}

}



This does not quite work. I need to go inside the second loop only if the specific Property has both Get and Set.

Thanks very much in advance

Susan

Suzi167
September 12th, 2007, 08:53 PM
hm....it sounds like it's a tough topic.

Does anyone know at least a good reference where I can find information on Reflection?

I have checked out MSDN already.

Thanks

Susan

Anti-Rich
September 12th, 2007, 08:58 PM
hi,

not too sure about your question, but i would highly recommend that wonderful site known as google :P seriously, just google 'reflection tutorial' or 'reflection whatever' and something will come up.

god bless the almighty power of google :P :)

good luck! :)

adam

trenches
September 12th, 2007, 11:42 PM
Try this:foreach (Type type in assembly.GetTypes())
foreach (PropertyInfo propInfo in type.GetProperties())
if (propInfo.CanRead && propInfo.CanWrite)
Console.WriteLine(propInfo.Name);