Message 1 of 2
Get subObject from Object by name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I would like to get a subObject from Object by name using C#. Previously, I used the VBA function: "CallByName(obj, propertyName, VbGet)".
I can get primitive objects such as strings and booleans, but I have a problem with non-primitive objects. I tried using Reflection, but I don't know why it doesn't work. Has anyone tried, retrieve elements like this? Maybe the Inventor library has a function that does this. I think it does but I can't find it.
public static void GetObjectProperties(object obj)
{
System.ComponentModel.PropertyDescriptorCollection oProps = System.ComponentModel.TypeDescriptor.GetProperties(obj);
foreach (System.ComponentModel.PropertyDescriptor oProp in oProps)
{
object propertyValue = oProp.GetValue(obj);
if(propertyValue != null)
{
if (propertyValue.GetType().IsPrimitive || propertyValue.GetType() == typeof(string))
{
}
else
{
Type mainType = obj.GetType();
PropertyInfo subObjectProperty = mainType.GetProperty(oProp.Name);
object subObjectValue = subObjectProperty.GetValue(obj);
}
}
}
return;
}