private static ClassDataContract ResolveDataContractFromTypeInformation(string typeName, DataContract contract, XmlObjectSerializerReadContextComplexJson context)
        {
            DataContract dataContract = context.ResolveDataContractFromType(typeName, Globals.DataContractXsdBaseNamespace, contract);

            if (dataContract == null)
            {
                XmlQualifiedName qname = XmlObjectSerializerReadContextComplexJson.ParseQualifiedName(typeName);
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DcTypeNotFoundOnDeserialize, qname.Namespace, qname.Name)));
            }
            return((ClassDataContract)dataContract);
        }
        private object ConvertObjectToPrimitiveDataContract(DataContract contract, object value, XmlObjectSerializerReadContextComplexJson context)
        {
            // Taking the right deserialized value for datetime string based on contract information
            var tuple = value as Tuple <DateTime, string>;

            if (tuple != null)
            {
                if (contract is StringDataContract || contract.UnderlyingType == typeof(object))
                {
                    value = tuple.Item2;
                }
                else
                {
                    value = tuple.Item1;
                }
            }

            if (contract is TimeSpanDataContract)
            {
                return(XmlConvert.ToTimeSpan(String.Format(CultureInfo.InvariantCulture, "{0}", value)));
            }
            else if (contract is ByteArrayDataContract)
            {
                return(ObjectToDataContractConverter.ConvertToArray(typeof(Byte), (IList)value));
            }
            else if (contract is GuidDataContract)
            {
                return(new Guid(String.Format(CultureInfo.InvariantCulture, "{0}", value)));
            }
            else if (contract is ObjectDataContract)
            {
                if (value is ICollection)
                {
                    return(ConvertObjectToDataContract(DataContract.GetDataContract(Globals.TypeOfObjectArray), value, context));
                }

                return(TryParseJsonNumber(value));
            }
            else if (contract is QNameDataContract)
            {
                return(XmlObjectSerializerReadContextComplexJson.ParseQualifiedName(value.ToString()));
            }
            else if (contract is StringDataContract)
            {
                if (value is bool)
                {
                    return(((bool)value) ? Globals.True : Globals.False);
                }
                return(value.ToString());
            }
            else if (contract is UriDataContract)
            {
                return(new Uri(value.ToString(), UriKind.RelativeOrAbsolute));
            }
            else if (contract is DoubleDataContract)
            {
                if (value is float)
                {
                    return((double)(float)value);
                }
                if (value is double)
                {
                    return((double)value);
                }
                return(double.Parse(String.Format(CultureInfo.InvariantCulture, "{0}", value), NumberStyles.Float, CultureInfo.InvariantCulture));
            }
            else if (contract is DecimalDataContract)
            {
                return(decimal.Parse(String.Format(CultureInfo.InvariantCulture, "{0}", value), NumberStyles.Float, CultureInfo.InvariantCulture));
            }

            return(Convert.ChangeType(value, contract.UnderlyingType, CultureInfo.InvariantCulture));
        }