Usando Reflection con COM Interop

Después de una llamada de interoperabilidad, recupero un objeto COM. Sé que este objeto será una de las tres clases COM posibles (Class1, Class2, Class3), pero no sé cuál en tiempo de ejecución.

La reflexión sobre ese objeto (interopObject.GetType ()) devuelve el contenedor RCW base de System .__ ComObject.

Lo que necesito es establecer algunas propiedades en el objeto: Texto1, Texto2, ... Texto30 (nombres reales, por cierto :)), que existen en las tres clases.

Entonces, la pregunta es, ¿puedo obtener de alguna manera el tipo de tiempo de ejecución del objeto (esto resolvería mi problema, pero podría ser imposible, ya que el tiempo de ejecución .net podría no tener esa información), o puedo establecer una propiedad de un objeto COM a ciegas

este es mi código actual, que falla

for ( int i = 1; i <= 30; i++ )
{
  ProprertyInfo pi =interopObject.GetType().GetProperty("Text" +i.ToString()) 
  // this returns null for pi
  pi.GetSetMethod().Invoke(interopObject, new object[] { someValue });
}

Gracias a Marc, estos tres van en mi colección permanente de trucos:

private static object LateGetValue(object obj, string propertyName)
{
  return RuntimeHelpers.GetObjectValue(NewLateBinding.LateGet(obj, null,
            propertyName, new object[0], null, null, null));
}

private static void LateSetValue(object obj, string propertyName, object value)
{
  NewLateBinding.LateSet(obj, null, propertyName, new []{value}, null, null);
}

private static void LateCallMethod(object obj, string methodName)
{
  NewLateBinding.LateCall(obj, null, methodName, new object[0], null,
            null, null, true);
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta