4

How can I use IDynamicMetaObjectProvider to introspect COM objects? Specifically, given an arbitrary COM object, I want to return a Dictionary where the Key is the Property name, and the Value is the string value of the property in the COM object (if the property value isn't a string, skip it).

How can I get the property names and their values at runtime like this?

4
  • Just use Reflection like you normally do, dyn.GetType().GetProperties() etc. Commented Feb 10, 2011 at 22:43
  • @Hans That doesn't seem to work, it just returns the ComObject static properties Commented Feb 11, 2011 at 3:24
  • Worked fine on my machine. Make sure the reference is of type dynamic, not object. And that the COM server implements IDispatch. Commented Feb 11, 2011 at 3:36
  • @Hans That might be my problem, it was dynamic but I was casting it to object. Thanks for the tip! Commented Feb 11, 2011 at 3:44

1 Answer 1

1

You can't really; objects are not required to implement IDynamicMetaObjectProvider in order to provide dynamic functionality, it's a hook that allows them to contribute in the binding process.

For this kind of operation, you would still have to drop down to using Reflection to get the members and the values.

Sign up to request clarification or add additional context in comments.

4 Comments

System.__ComObject seems to do so, since the VS debugger view is able to evaluate it as a Dynamic object
Maybe this adds some additional help: eggheadcafe.com/software/aspnet/30919888/…
@Paul Betts: Are you saying you can cast System.__ComObject to IDynamicMetaObjectProvider? If so, then why not just perform a direct cast in code? It seems that it would have been pretty simple to do?
I think so, but what I'm asking is, how can I use IDynamicMetaObjectProvider to walk the property list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.