/// <summary>
        /// This writes the public contents of the Entity in the properties element.
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>XElement representation of the properties element</returns>
        XElement WriteEntityContents(IOfflineEntity entity)
        {
            XElement contentElement = new XElement(FormatterConstants.ODataMetadataNamespace + FormatterConstants.PropertiesElementName);

            // Write only the primary keys if its an tombstone
            PropertyInfo[] properties = ReflectionUtility.GetPropertyInfoMapping(entity.GetType());

            // Write individual properties to the feed,
            foreach (PropertyInfo fi in properties)
            {
                string edmType  = FormatterUtilities.GetEdmType(fi.PropertyType);
                object value    = fi.GetValue(entity, null);
                Type   propType = fi.PropertyType;
                if (fi.PropertyType.IsGenericType && fi.PropertyType.Name.Equals(FormatterConstants.NullableTypeName, StringComparison.InvariantCulture))
                {
                    // Its a Nullable<T> property
                    propType = fi.PropertyType.GetGenericArguments()[0];
                }

                if (value == null)
                {
                    contentElement.Add(
                        new XElement(FormatterConstants.ODataDataNamespace + fi.Name,
                                     new XAttribute(FormatterConstants.ODataMetadataNamespace + FormatterConstants.AtomPubTypeElementName, edmType),
                                     new XAttribute(FormatterConstants.ODataMetadataNamespace + FormatterConstants.AtomPubIsNullElementName, true)));
                }
                else if (propType == FormatterConstants.DateTimeType ||
                         propType == FormatterConstants.TimeSpanType)
                {
                    contentElement.Add(
                        new XElement(FormatterConstants.ODataDataNamespace + fi.Name,
                                     new XAttribute(FormatterConstants.ODataMetadataNamespace + FormatterConstants.AtomPubTypeElementName, edmType),
                                     FormatterUtilities.ConvertDateTimeForType_Atom(value, propType)));
                }
                else if (propType != FormatterConstants.ByteArrayType)
                {
                    contentElement.Add(
                        new XElement(FormatterConstants.ODataDataNamespace + fi.Name,
                                     new XAttribute(FormatterConstants.ODataMetadataNamespace + FormatterConstants.AtomPubTypeElementName, edmType),
                                     value));
                }
                else
                {
                    byte[] bytes = (byte[])value;
                    contentElement.Add(
                        new XElement(FormatterConstants.ODataDataNamespace + fi.Name,
                                     new XAttribute(FormatterConstants.ODataMetadataNamespace + FormatterConstants.AtomPubTypeElementName, edmType),
                                     Convert.ToBase64String(bytes)));
                }
            }

            return(contentElement);
        }
        private static object GetValueFromType(Type type, string value)
        {
            if (value == null)
            {
                if (type.IsGenericType)
                {
                    return(null);
                }
                else if (!type.IsPrimitive)
                {
                    return(null);
                }
                else
                {
                    // Error case. Value cannot be null for a non nullable primitive type
                    throw new InvalidOperationException("Error in deserializing type " + type.FullName);
                }
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition() == FormatterConstants.NullableType)
            {
                type = type.GetGenericArguments()[0];
            }

            if (FormatterConstants.StringType.IsAssignableFrom(type))
            {
                return(value);
            }
            else if (FormatterConstants.ByteArrayType.IsAssignableFrom(type))
            {
                return(Convert.FromBase64String(value));
            }
            else if (FormatterConstants.GuidType.IsAssignableFrom(type))
            {
                return(new Guid(value));
            }
            else if (FormatterConstants.DateTimeType.IsAssignableFrom(type) ||
                     FormatterConstants.TimeSpanType.IsAssignableFrom(type))
            {
                return(FormatterUtilities.ParseDateTimeFromString(value, type));
            }
            else if (type.IsPrimitive ||
                     FormatterConstants.DecimalType.IsAssignableFrom(type) ||
                     FormatterConstants.FloatType.IsAssignableFrom(type))
            {
                return(Convert.ChangeType(value, type, null));
            }
            return(value);
        }