Reflection usage and InvokeMember vs. GetProperty with COM objects

  • Thread starter Rick Strahl [MVP]
  • Start date
R

Rick Strahl [MVP]

A while back I've built a bunch of generic Reflection routines that
simplify
the process of access properties/fields and methods a bit easier by creating
wrappers around Property/Field/Method info members.

For example:

public const BindingFlags MemberAccess =

BindingFlags.Public | BindingFlags.NonPublic |

BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase;

public static object GetProperty(object Object,string Property)

{

return Object.GetType().GetProperty(Property,wwUtils.MemberAccess |
BindingFlags.GetProperty).GetValue(Object,null);

}

There are versions for Get/Set and fields and properties as well as versions
that can nest references. All works fine with .Net types.

Today I tried to use this same code with a COM object and promptly it fell
flat. In the above example, GetProperty() fails to find the property.
However, the following works:

return Object.GetType().InvokeMember(Property,wwUtils.MemberAccess |
BindingFlags.GetProperty,null,Object,null);

So now I'm wondering what is InvokeMember doing that is different here? I
seem to remember a discussion here that InvokeMember is a bit less
efficient, so if possible I'd like to avoid this.

Any ideas if it's possible to get the code to run with GetProperty et al.?



+++ Rick ---




--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web



--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top