0

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?

2
  • Can you expand your question to include code showing exactly what member you are trying to access dynamically (the basic structure of your Item class)? Commented Oct 29, 2015 at 17:04
  • Hi Jerren, I update my question so you could see the objects...
    – sitO
    Commented Oct 30, 2015 at 11:54

2 Answers 2

2

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

1
  • Hi Matias, the reason is, that the method is only available at this property. But I understand... more or les it is the same.. invoke the method or getValue(NewItem,null); I posted a pic. in both cases it is the same. The dynamic members I need to know...
    – sitO
    Commented Oct 29, 2015 at 17:49
0

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

1
  • Hi Jerren, first thanks for it. I will read this... and have a try
    – sitO
    Commented Nov 3, 2015 at 13:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.