Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
alain_miltenburg
in reply to: rjay75

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.");
            }
        }