sitO
sitO

Reputation: 19

Get dynamic members via reflection

I have an issue on reflection.

I have an ComObject's named Item (NewItem-> Instance). (interface)

For some reason I need some properties of this object.

var Item = typeof(IItem);
var props = Item.GetProperties();
foreach (var prop in props)
{
  var property = Item.GetProperty(prop.Name);
  var Propertytype = property.GetType().Name;
  if (Propertytype == "RuntimePropertyInfo")
  {
      var method = property.GetGetMethod();
      var  spesific = method.Invoke(NewItem, null);// spesific has dynamic Members...
  }
}

And I don't know how to get the Dynamic members. there are some classes involved... so I realy do not know from where the property "Spesific" // RuntimeProperty Info comes from...

Propery after invoke Method

Within the Item Class itself there is no Property like this.

In normal way I could instantiate the spesific to an object itself.

the specific -> Method has all information for a defined Object like a Matrix or Textfield... this is the ComObject itself. The object Item includes all basic information according for placement or other things like some standard methods...

and this is the item itself enter image description here

Any ideas?

Upvotes: 0

Views: 343

Answers (2)

Jerren Saunders
Jerren Saunders

Reputation: 1435

Apparently COM Objects respond a little different to reflection than other classes. I haven't attempted to use reflection on them before and don't currently have any code to get my fingers into to experiment with, but here are some SO questions that may help get you in the right direction.

Maybe the principals from this article will also help you go in the right direction: https://support.microsoft.com/en-us/kb/320523

Upvotes: 0

Matias Cicero
Matias Cicero

Reputation: 26281

Why are you trying to invoke the get method of the property?

var method = property.GetGetMethod();
var spesific = method.Invoke(NewItem, null);// spesific has dynamic Members...

There is an easier way:

object value = property.GetValue(NewItem);

Providing that NewItem is an instance of a class that implements IItem

Upvotes: 2

Related Questions