public static void GetPropertiesFromDocument(IList <string> selectColumns, string serializedDocument, out IDictionary <string, EntityProperty> entityProperties, out IDictionary <string, EntityProperty> documentDBProperties)
        {
            entityProperties     = new Dictionary <string, EntityProperty>();
            documentDBProperties = new Dictionary <string, EntityProperty>();
            using (ITableEntityReader tableEntityReader = new TableEntityReader(serializedDocument))
            {
                tableEntityReader.Start();
                while (tableEntityReader.MoveNext())
                {
                    string         currentName = tableEntityReader.CurrentName;
                    EntityProperty entityProperty;
                    switch (tableEntityReader.CurrentType)
                    {
                    case DataType.Double:
                        entityProperty = new EntityProperty(tableEntityReader.ReadDouble());
                        break;

                    case DataType.String:
                        entityProperty = new EntityProperty(tableEntityReader.ReadString());
                        break;

                    case DataType.Binary:
                        entityProperty = new EntityProperty(tableEntityReader.ReadBinary());
                        break;

                    case DataType.Boolean:
                        entityProperty = new EntityProperty(tableEntityReader.ReadBoolean());
                        break;

                    case DataType.DateTime:
                        entityProperty = new EntityProperty(tableEntityReader.ReadDateTime());
                        break;

                    case DataType.Int32:
                        entityProperty = new EntityProperty(tableEntityReader.ReadInt32());
                        break;

                    case DataType.Int64:
                        entityProperty = new EntityProperty(tableEntityReader.ReadInt64());
                        break;

                    case DataType.Guid:
                        entityProperty = new EntityProperty(tableEntityReader.ReadGuid());
                        break;

                    default:
                        throw new Exception(string.Format(CultureInfo.CurrentCulture, "Unexpected Edm type '{0}'", (int)tableEntityReader.CurrentType));
                    }
                    if (!entityProperty.IsNull())
                    {
                        if (EdmSchemaMapping.IsDocumentDBProperty(currentName) || currentName == "$id" || currentName == "$pk")
                        {
                            documentDBProperties.Add(currentName, entityProperty);
                        }
                        else if (selectColumns == null || selectColumns.Count == 0 || (selectColumns != null && selectColumns.Contains(currentName)))
                        {
                            entityProperties.Add(currentName, entityProperty);
                        }
                    }
                }
                if (selectColumns != null)
                {
                    foreach (string selectColumn in selectColumns)
                    {
                        if (!entityProperties.ContainsKey(selectColumn))
                        {
                            entityProperties.Add(selectColumn, EntityProperty.GeneratePropertyForString(null));
                        }
                    }
                }
                tableEntityReader.End();
            }
        }
        private static void ReflectionRead(object entity, IDictionary <string, EntityProperty> properties, OperationContext operationContext)
        {
            foreach (PropertyInfo item in (IEnumerable <PropertyInfo>)entity.GetType().GetProperties())
            {
                if (!ShouldSkipProperty(item, operationContext))
                {
                    if (!properties.ContainsKey(item.Name))
                    {
                        Logger.LogInformational(operationContext, "Omitting property '{0}' from de-serialization because there is no corresponding entry in the dictionary provided.", item.Name);
                    }
                    else
                    {
                        EntityProperty entityProperty = properties[item.Name];
                        if (entityProperty.IsNull)
                        {
                            item.SetValue(entity, null, null);
                        }
                        else
                        {
                            switch (entityProperty.PropertyType)
                            {
                            case EdmType.String:
                                if (!(item.PropertyType != typeof(string)))
                                {
                                    item.SetValue(entity, entityProperty.StringValue, null);
                                }
                                break;

                            case EdmType.Binary:
                                if (!(item.PropertyType != typeof(byte[])))
                                {
                                    item.SetValue(entity, entityProperty.BinaryValue, null);
                                }
                                break;

                            case EdmType.Boolean:
                                if (!(item.PropertyType != typeof(bool)) || !(item.PropertyType != typeof(bool?)))
                                {
                                    item.SetValue(entity, entityProperty.BooleanValue, null);
                                }
                                break;

                            case EdmType.DateTime:
                                if (item.PropertyType == typeof(DateTime))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.Value.UtcDateTime, null);
                                }
                                else if (item.PropertyType == typeof(DateTime?))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.HasValue ? new DateTime?(entityProperty.DateTimeOffsetValue.Value.UtcDateTime) : null, null);
                                }
                                else if (item.PropertyType == typeof(DateTimeOffset))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.Value, null);
                                }
                                else if (item.PropertyType == typeof(DateTimeOffset?))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue, null);
                                }
                                break;

                            case EdmType.Double:
                                if (!(item.PropertyType != typeof(double)) || !(item.PropertyType != typeof(double?)))
                                {
                                    item.SetValue(entity, entityProperty.DoubleValue, null);
                                }
                                break;

                            case EdmType.Guid:
                                if (!(item.PropertyType != typeof(Guid)) || !(item.PropertyType != typeof(Guid?)))
                                {
                                    item.SetValue(entity, entityProperty.GuidValue, null);
                                }
                                break;

                            case EdmType.Int32:
                                if (!(item.PropertyType != typeof(int)) || !(item.PropertyType != typeof(int?)))
                                {
                                    item.SetValue(entity, entityProperty.Int32Value, null);
                                }
                                break;

                            case EdmType.Int64:
                                if (!(item.PropertyType != typeof(long)) || !(item.PropertyType != typeof(long?)))
                                {
                                    item.SetValue(entity, entityProperty.Int64Value, null);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }