05-22-2023
03:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-22-2023
03:40 AM
Hi Adam,
Thanks for your suggestion! In general, am not that fond of using the dynamic keyword, but I will definitely review your solution for replacement of my current solution. As mine has downsides as well.
As with the solution of Rodney, I am currently using reflection to get the ObjectTypeEnum:
public static ObjectTypeEnum GetObjectTypeEnum(object comObject)
{
const string propertyName = "Type";
if (comObject is null)
{
throw new ArgumentNullException(nameof(comObject), "Argument cannot be null.");
}
try
{
return (ObjectTypeEnum)comObject.GetType().InvokeMember(propertyName,
BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
null, comObject, null);
}
catch
{
throw new MissingMemberException($"Property '{propertyName}' is not found on object.");
}
}