Reply
Solved! Go to solution

PropertyInfo is always Nothing

[ Edited ]

I am checking if a selected Solid Edge object has the "Key" property.

For this I am using:

 

Dim oSelSet As SelectSet = oDoc.SelectSet
Dim o As Object = oSelSet.Item(1)
 
Dim oPIinfo As _PropertyInfo = o.GetType().GetProperty("Key")
If oPIinfo IsNot Nothing Then
  MessageBox.Show(o.Key.ToString)
End If

 

For eg. a Line2d has a Key property but a CoordinateSystem does not.

But oPInfo is always Nothing.

 

Kindly suggest how to overcome this problem.

Thanks.

 

~Tushar

 

This does not seem to happen with non-SE objects like, say a TextBox, which returns the info when seeking the "Text" property and Nothing for a property called "Tex" using GetProperty.

 

2 REPLIES
Solution
Solution
Accepted by topic author Tushar
‎08-27-2015 11:34 AM

Re: PropertyInfo is always Nothing

Tushar,

 

Because of the way .NET COM Interop works, your o.GetType() will always return System.__ComObject. To check yourself, simply assign the return value of GetType() to a variable and look in the watch window.

 

This issue is already addressed in the SolidEdge.Community NuGet package as shown below.

 

[STAThread]
static void Main(string[] args)
{
    var application = SolidEdgeCommunity.SolidEdgeUtils.Connect();
    var selectSet = application.ActiveSelectSet;
    var item = selectSet.Item(1);
            
    // Because of .NET COM Interop, this will always be System.__ComObject.
    var rcwType = item.GetType();

    // Use the following approach to resolve the actual runtime type.
    var type = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(item);

    var propertyInfo = type.GetProperty("Key");

    if (propertyInfo != null)
    {
        // Property exists.
    }
}

 

If you don't want to use that NuGet package, you can always figure out how to do it yourself by looking at my ComObject.cs on GitHub. If you need help converting the C# code to VB, I use Instant VB from Tangible Software Solutions.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: PropertyInfo is always Nothing

Thanks Jason, I did suspect the System.__ComObject must be hiding the property.

 

~Tushar