שתף באמצעות


how to get value of property in system.__ComObject

Question

Tuesday, April 28, 2009 5:14 PM

Hi Everyone.

I have been working with System.reflection namespace and i have problems to get value of properties in system.__ComObject

My objective is:
obtain a collection
for each object in collection get the propertie (example ID)

My problem is:
 the object in collection come with the type system.__ComObject
 i think this is the problem to obtain a propertie(ID)

'code

 Dim collection As VBA.Collection = myObject.GetCollection()
  For Each element In collection

  Dim obj As Object = GetPropertyByNamedValue(element, "propertyName")
  response.write(obj.ToString)

 Next
 

'the Method GetPropertyByNamedValue() use System.Reflection
   Private Function GetPropertyByNamedValue(ByVal obj As Object, ByVal PropertyName As String) AS Object
                
    'the type is System.__ComObject
    Dim objType As Type = obj.GetType()

       Dim prop As PropertyInfo = objType.GetProperty(PropertyName)

       If Not prop Is Nothing Then
                    myValue = prop.GetValue(obj, Nothing)
       End If

       Return myValue
 End Function

any help would be appreciated.

All replies (2)

Thursday, April 30, 2009 6:40 AM

Hi Fjvf,

I am moving this thread from Base ".Net Framework Setup" forum to the "Visual Basic General" forum, since the issue is related to VB programming. There are more VB experts in the "Visual Basic General" forum.

ThanksPlease remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


Wednesday, May 6, 2009 6:54 AM | 1 vote

Hi fjvf,

Based on your post, using PropertyInfo.GetValue() method cannot return the indexed property of System.__ComObject type. I would like to provide you the suggestions as follows:

  1. The System.__ComObject is a class internal to the .NET Framework that can be used to hold a reference to any kind of COM object; its purpose is to act as the RCW for an unknown type of COM object. The GetType.Type method for a COM object will return the System.__ComObject class. Here is an example on KB320523 that provides you an example to check the type of a COM object. This can help you to understand the meaning of ComObject.

  2. You can also solve this problem by casting the System.__ComObject to strongly typed Runtime Callable Wrapper, then you can use the GetValue method in System.Reflection namespace. Here is an example on the casting issue in the link below:

http://edndoc.esri.com/arcobjects/9.0/ArcGISDevHelp/DevelopmentEnvs/DotNet/SystemComObject.htm

  1. A Better example on checking the ComObject type by querying interop interfaces against the object Here...

In a word, this problem is close to the Com Interop issue. If you are clear about the COM Interop concepts, you can easily solve this kind of issues very soon.

Hope that can provide you some idea.

Please remember to mark the replies as answers if they help and unmark them if they provide no help.