YAXLib.YAXSerializer.DeserializeKeyValuePair C# (CSharp) Method

DeserializeKeyValuePair() private method

Deserializes the XML reperesentation of a key-value pair, as specified, and returns a KeyValuePair instance containing the deserialized data.
private DeserializeKeyValuePair ( System.Xml.Linq.XElement baseElement ) : object
baseElement System.Xml.Linq.XElement The element contating the XML reperesentation of a key-value pair.
return object
        private object DeserializeKeyValuePair(XElement baseElement)
        {
            Type[] genArgs = m_type.GetGenericArguments();
            Type keyType = genArgs[0];
            Type valueType = genArgs[1];

            XName xnameKey = TypeNamespace.IfEmptyThenNone() + "Key";
            XName xnameValue = TypeNamespace.IfEmptyThenNone() + "Value";

            object keyValue, valueValue;
            if (ReflectionUtils.IsBasicType(keyType))
            {
                try
                {
                    keyValue = ReflectionUtils.ConvertBasicType(
                        baseElement.Element(xnameKey).Value, keyType);
                }
                catch (NullReferenceException)
                {
                    keyValue = null;
                }
            }
            else if (ReflectionUtils.IsStringConvertibleIFormattable(keyType))
            {
                keyValue = keyType.InvokeMember(string.Empty,
                    BindingFlags.CreateInstance,
                    null, null,
                    new object[] { baseElement.Element(xnameKey).Value });
            }
            else if (ReflectionUtils.IsCollectionType(keyType))
            {
                keyValue = DeserializeCollectionValue(keyType,
                    baseElement.Element(xnameKey), xnameKey, null);
            }
            else
            {
                var ser = NewInternalSerializer(keyType, xnameKey.Namespace.IfEmptyThenNone(), null);
                keyValue = ser.DeserializeBase(baseElement.Element(xnameKey));
                FinalizeNewSerializer(ser, false);
            }

            if (ReflectionUtils.IsBasicType(valueType))
            {
                try
                {
                    valueValue = ReflectionUtils.ConvertBasicType(baseElement.Element(xnameValue).Value, valueType);
                }
                catch (NullReferenceException)
                {
                    valueValue = null;
                }
            }
            else if (ReflectionUtils.IsStringConvertibleIFormattable(valueType))
            {
                valueValue = valueType.InvokeMember(string.Empty, BindingFlags.CreateInstance,
                    null, null, new object[] { baseElement.Element(xnameValue).Value });
            }
            else if (ReflectionUtils.IsCollectionType(valueType))
            {
                valueValue = DeserializeCollectionValue(valueType,
                    baseElement.Element(xnameValue), xnameValue, null);
            }
            else
            {
                var ser = NewInternalSerializer(valueType, xnameValue.Namespace.IfEmptyThenNone(), null);
                valueValue = ser.DeserializeBase(baseElement.Element(xnameValue));
                FinalizeNewSerializer(ser, false);
            }

            object pair = m_type.InvokeMember(string.Empty,
                BindingFlags.CreateInstance,
                null, null, new object[] { keyValue, valueValue });

            return pair;
        }