Skip Ribbon Commands
Skip to main content

Ondrej Sevecek's English Pages

:

Comments: One further change

Engineering and troubleshooting by Directory Master!
MCM: Directory

Sorry comments are disable due to the constant load of spam

2

Title

One further change

Author

Doug Kaye (douglas.kaye@outlook.com)

Body

Actually if one of o1 and o2 is a value type and the other is not then my code throws an exception. The following solves that issue;

          static new bool Equals(object o1, object o2)
        {
            if (o1?.GetType().IsValueType.Equals(o2?.GetType().IsValueType) ?? false)
            {
                System.Reflection.MethodInfo method = o1.GetType().GetMethod("Equals", new Type[] { o1.GetType() });
                if (method == null) method = o1.GetType().GetMethod("Equals");
                if (method != null)
                {
                    return (bool)method.Invoke(o1, new object[] { o2 });
                }
                else
                    return false;
            }
            else
                return (o1 is null && o2 is null);
        }

Attachments

Created at 28/09/2018 21:44 by  
Last modified at 28/09/2018 21:44 by