CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Reflection

  1. #1
    Join Date
    Apr 2005
    Posts
    172

    Reflection

    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:

    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

  2. #2
    Join Date
    Apr 2005
    Posts
    172

    Re: Reflection

    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

  3. #3
    Join Date
    Mar 2007
    Posts
    69

    Re: Reflection

    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

  4. #4
    Join Date
    Aug 2007
    Location
    Minneapolis
    Posts
    155

    Smile Re: Reflection

    Try this:
    Code:
    foreach (Type type in assembly.GetTypes())
        foreach (PropertyInfo propInfo in type.GetProperties())
            if (propInfo.CanRead && propInfo.CanWrite)
                Console.WriteLine(propInfo.Name);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured