Пример #1
0
        internal static EventParameter ReadXml(XmlReadAdaptor adaptor)
        {
            string name = adaptor.ReadName();

            EventParameter parameter = ReadNullParameter(adaptor, name);

            if (parameter != null)
            {
                return(parameter);
            }

            // Look for the type.

            parameter = ReadPrimitiveTypeParameter(adaptor, name);
            if (parameter != null)
            {
                return(parameter);
            }

            return(ReadParameter(adaptor, name));
        }
Пример #2
0
        public bool Equals(EventParameter other)
        {
            // Some shortcuts first.

            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (m_name != other.m_name)
            {
                return(false);
            }
            if (m_value == null)
            {
                return(other.m_value == null);
            }
            if (other.m_value == null)
            {
                return(false);
            }
            if (m_valueFormat == other.m_valueFormat && ReferenceEquals(m_value, other.m_value))
            {
                return(true);
            }

            // The only format that cannot be unpacked is string so explicitly check for it.

            if (m_valueFormat == ValueFormat.String)
            {
                if (other.m_valueFormat == ValueFormat.String)
                {
                    return(m_class == other.m_class && string.Equals((string)m_value, (string)other.m_value));
                }
                else
                {
                    ClassInfo info = new ClassInfo(m_class);
                    return(info.AssemblyName == other.m_value.GetType().Assembly.FullName&& info.FullName == other.m_value.GetType().FullName&& ((string)m_value).Equals(other.m_value.ToString()));
                }
            }
            else if (other.m_valueFormat == ValueFormat.String)
            {
                ClassInfo info = new ClassInfo(other.m_class);
                return(m_value.GetType().Assembly.FullName == info.AssemblyName && m_value.GetType().FullName == info.FullName && m_value.ToString().Equals(other.m_value));
            }

            // To go further unpack.

            try
            {
                Unpack();
                other.Unpack();
            }
            catch (System.Exception)
            {
                // Failed to unpack. If the format is the same try to compare them packed,
                // otherwise assume not equal.

                if (m_valueFormat != other.m_valueFormat)
                {
                    return(false);
                }

                if (m_value is string && other.m_value is string)
                {
                    return(string.Equals((string)m_value, (string)other.m_value));
                }

                if (m_value is byte[] && other.m_value is byte[])
                {
                    return(ByteArraysEqual((byte[])m_value, (byte[])other.m_value));
                }

                return(false);
            }

            return(m_value.Equals(other.m_value));
        }