internal static string ReadAndUpdateTableEntity(ITableEntity entity, ODataEntry entry, OperationContext ctx)
        {
            entity.ETag = entry.ETag;


            Dictionary <string, EntityProperty> entityProperties = new Dictionary <string, EntityProperty>();

            foreach (ODataProperty prop in entry.Properties)
            {
                if (prop.Name == "PartitionKey")
                {
                    entity.PartitionKey = (string)prop.Value;
                }
                else if (prop.Name == "RowKey")
                {
                    entity.RowKey = (string)prop.Value;
                }
                else if (prop.Name == "Timestamp")
                {
                    entity.Timestamp = (DateTime)prop.Value;
                }
                else
                {
                    entityProperties.Add(prop.Name, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                }
            }


            entity.ReadEntity(entityProperties, ctx);



            return(entry.ETag);
        }
Beispiel #2
0
        public async Task <Result> MergeOne(string pk, string rk, IDictionary <string, object> props)
        {
            var dte = new DynamicTableEntity(pk, rk)
            {
                ETag = "*"
            };

            foreach (var kv in props)
            {
                dte.Properties.Add(kv.Key, EntityProperty.CreateEntityPropertyFromObject(kv.Value));
            }
            var op = TableOperation.Merge(dte);

            try
            {
                var r = await table.ExecuteAsync(op);

                return(Result.EmptyOk);
            }
            catch (StorageException ex)
            {
                int status = ex.RequestInformation.HttpStatusCode;
                if (status == (int)HttpStatusCode.PreconditionFailed ||
                    status == (int)HttpStatusCode.Conflict
                    )
                {
                    return(Result.Error(status));
                }
                throw;
            }
        }
        private static T ReadAndResolve <T>(string etag, Dictionary <string, object> props, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, T> resolver, TableRequestOptions options)
        {
            string         arg  = null;
            string         arg2 = null;
            DateTimeOffset arg3 = default(DateTimeOffset);
            Dictionary <string, EntityProperty> dictionary = new Dictionary <string, EntityProperty>();

            foreach (KeyValuePair <string, object> prop in props)
            {
                string key = prop.Key;
                if (key == "PartitionKey")
                {
                    arg = (string)prop.Value;
                }
                else if (key == "RowKey")
                {
                    arg2 = (string)prop.Value;
                }
                else if (key == "Timestamp")
                {
                    arg3 = new DateTimeOffset((DateTime)prop.Value);
                }
                else
                {
                    dictionary.Add(key, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                }
            }
            return(resolver(arg, arg2, arg3, dictionary, etag));
        }
Beispiel #4
0
        public virtual DynamicTableEntity Write(T data)
        {
            if (data == null)
            {
                return(null);
            }
            DynamicTableEntity e = new DynamicTableEntity(data.PartitionKey, data.RowKey);

            foreach (var propInfo in typeof(T).GetProperties())
            {
                var tblColumnAttr = propInfo.GetCustomAttribute <TableColumnAttribute>();
                if (tblColumnAttr != null)
                {
                    var columnName = tblColumnAttr.Name;
                    var val        = propInfo.GetValue(data);
                    if (propInfo.PropertyType.IsEnum)
                    {
                        var intval = (int)val;
                        e.Properties[columnName] = EntityProperty.GeneratePropertyForInt(intval);
                    }
                    else
                    {
                        e.Properties[columnName] = EntityProperty.CreateEntityPropertyFromObject(val);
                    }
                }
            }

            return(e);
        }
Beispiel #5
0
        private static T ReadAndResolve <T>(string etag, Dictionary <string, object> props, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, T> resolver, TableRequestOptions options)
        {
            string         pk = null;
            string         rk = null;
            DateTimeOffset ts = new DateTimeOffset();
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();

            foreach (KeyValuePair <string, object> prop in props)
            //foreach (ODataProperty prop in entry.Properties)
            {
                if (prop.Key == TableConstants.PartitionKey)
                {
                    pk = (string)prop.Value;
                }
                else if (prop.Key == TableConstants.RowKey)
                {
                    rk = (string)prop.Value;
                }
                else if (prop.Key == TableConstants.Timestamp)
                {
                    ts = new DateTimeOffset((DateTime)prop.Value);
                }
                else
                {
                    properties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                }
            }

            return(resolver(pk, rk, ts, properties, etag));
        }
Beispiel #6
0
        private static object ReadAndResolve(ODataEntry entry, EntityResolver resolver)
        {
            string         pk = null;
            string         rk = null;
            DateTimeOffset ts = new DateTimeOffset();
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();

            foreach (ODataProperty prop in entry.Properties)
            {
                if (prop.Name == TableConstants.PartitionKey)
                {
                    pk = (string)prop.Value;
                }
                else if (prop.Name == TableConstants.RowKey)
                {
                    rk = (string)prop.Value;
                }
                else if (prop.Name == TableConstants.Timestamp)
                {
                    ts = new DateTimeOffset((DateTime)prop.Value);
                }
                else
                {
                    properties.Add(prop.Name, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                }
            }

            return(resolver(pk, rk, ts, properties, entry.ETag));
        }
Beispiel #7
0
        // Below method is altered to adhere with the service fabric.
        private DynamicTableEntity ToTableEntity(EventData eventData, string partitionKey, string rowKeyPrefix)
        {
            DynamicTableEntity result = new DynamicTableEntity
            {
                PartitionKey = partitionKey,
                RowKey       =
                    rowKeyPrefix + KeySegmentSeparator + this.GetEntitySequenceId().ToString() + KeySegmentSeparator +
                    this.instanceId
            };

            var eventLevel = (int)Enum.Parse(typeof(EventLevel), eventData.Level);

            result.Properties.Add(nameof(eventData.Timestamp), new EntityProperty(eventData.Timestamp));
            result.Properties.Add(nameof(eventData.ProviderName), new EntityProperty(eventData.ProviderName));
            result.Properties.Add(nameof(eventData.EventId), new EntityProperty(eventData.EventId));
            result.Properties.Add(nameof(eventData.Level), new EntityProperty(eventLevel));
            result.Properties.Add(nameof(eventData.KeywordName), new EntityProperty(eventData.Keywords));
            result.Properties.Add(nameof(eventData.TaskName), new EntityProperty(eventData.EventName));

            foreach (KeyValuePair <string, object> item in eventData.Payload)
            {
                result.Properties.Add(nameof(eventData.Message), EntityProperty.CreateEntityPropertyFromObject(item.Value));
                result.Properties.Add(nameof(eventData.EventMessage), EntityProperty.CreateEntityPropertyFromObject(item.Value));
            }

            return(result);
        }
Beispiel #8
0
        public static bool Update(T item)
        {
            if (table == null)
            {
                return(false);
            }

            try
            {
                PropertyInfo[] properties = item.GetType().GetProperties();

                ElasticTableEntity record = new ElasticTableEntity();

                BaseTable tbitem = item as BaseTable;
                record.RowKey       = tbitem.Id;
                record.PartitionKey = tbitem.Partition;
                record.ETag         = tbitem.Tag;

                foreach (PropertyInfo info in properties)
                {
                    record.Properties.Add(info.Name, EntityProperty.CreateEntityPropertyFromObject(info.GetValue(item, null)));
                }

                TableOperation replaceOperation = TableOperation.Replace(record);

                table.Execute(replaceOperation);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
        private static void AddProperties(IDictionary <string, EntityProperty> properties, ExpandoObject expando, string prefix = "")
        {
            foreach (var kvp in expando)
            {
                var key = prefix + kvp.Key;

                switch (kvp.Value)
                {
                case ExpandoObject child:
                    AddProperties(properties, child, key + PropertyDelimiter);
                    break;

                case IEnumerable <object> objCollection:
                    var objArray = objCollection.ToArray();
                    for (var i = 0; i < objArray.Length; i++)
                    {
                        if (objArray[i] is ExpandoObject expandoItem)
                        {
                            AddProperties(properties, expandoItem, key + $"{OpenArrayIndexer}{i}{CloseArrayIndexer}{PropertyDelimiter}");
                        }
                        else
                        {
                            properties[$"{key}{OpenArrayIndexer}{i}{CloseArrayIndexer}"] = EntityProperty.CreateEntityPropertyFromObject(objArray[i]);
                        }
                    }
                    break;

                default:
                    properties[key] = EntityProperty.CreateEntityPropertyFromObject(kvp.Value);
                    break;
                }
            }
        }
        public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            var map      = new Dictionary <string, EntityProperty>();
            var accessor = ReadAccessor.Create(_entity, AccessorMemberTypes.Properties, AccessorMemberScope.Public,
                                               out var members);

            foreach (var member in members)
            {
                if (ShouldSkipProperty(member, operationContext))
                {
                    continue;
                }
                if (!accessor.TryGetValue(_entity, member.Name, out var value))
                {
                    continue;
                }

                var entityValue = EntityProperty.CreateEntityPropertyFromObject(value);
                if (entityValue != null)
                {
                    map.Add(member.Name, entityValue);
                }
            }

            return(map);
        }
        public override void WriteProperty(PropertyInfo propertyInfo, Object obj, Dictionary <string, EntityProperty> targetList)
        {
            // get the value
            var arrayValue = propertyInfo.GetValue(obj);

            // check if enumerable
            if ((arrayValue as IList) == null)
            {
                return;
            }


            // visit every element
            for (int idx = 0; idx < (arrayValue as IList).Count; idx++)
            {
                // get the element
                var element = (arrayValue as IList)[idx];

                // generate the property name
                var propertyName = TemplateFunction(new { index = idx.ToString(DigitFormat) });

                // generate the property object
                EntityProperty newProperty = EntityProperty.CreateEntityPropertyFromObject(element);
                if (newProperty != null)
                {
                    targetList.Add(propertyName, newProperty);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Writes the entity.
        /// </summary>
        /// <param name="operationContext">The operation context.</param>
        /// <returns></returns>
        public override IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            if (operationContext is null)
            {
                throw new ArgumentNullException(nameof(operationContext));
            }

            var properties = WriteUserObject(this, operationContext);

            foreach (var complexProperty in ComplexProperties)
            {
                var value = complexProperty.GetValue(this);

                if (value != null)
                {
                    properties[complexProperty.Name] = new EntityProperty(JsonConvert.SerializeObject(value, Formatting.None));
                }
            }

            foreach (var enumProperty in EnumProperties)
            {
                properties[enumProperty.Name] = new EntityProperty(Enum.GetName(enumProperty.PropertyType, enumProperty.GetValue(this)));
            }

            foreach (var readOnlyProperty in ReadOnlyProperties)
            {
                properties[readOnlyProperty.Name] = EntityProperty.CreateEntityPropertyFromObject(readOnlyProperty.GetValue(this));
            }

            return(ColumnOrder
                   .Intersect(properties.Keys)
                   .Concat(properties.Keys.Except(ColumnOrder))
                   .ToDictionary(column => column, column => properties[column]));
        }
Beispiel #13
0
        private DynamicTableEntity GetEntity(T t, bool storeEntity = false)
        {
            var cwt         = t as IConcurrencyAware;
            var tableEntity = new DynamicTableEntity()
            {
                PartitionKey = t.Id,
                RowKey       = t.RangeKey,
                ETag         = cwt == null || cwt.ETag == null ? "*" : cwt.ETag,
                Timestamp    = cwt == null || cwt.LastModified == null ? DateTimeOffset.UtcNow : cwt.LastModified.Value
            };

            if (storeEntity)
            {
                foreach (var simpleProperty in _simpleProperties.Values)
                {
                    tableEntity.Properties[simpleProperty.Name] =
                        EntityProperty.CreateEntityPropertyFromObject(simpleProperty.GetGetMethod().Invoke(t, null));
                }

                foreach (var complexProperty in _complexProperties.Values)
                {
                    tableEntity.Properties[complexProperty.Name] =
                        EntityProperty.CreateEntityPropertyFromObject(
                            JsonConvert.SerializeObject(complexProperty.GetGetMethod().Invoke(t, null)));
                }
            }

            return(tableEntity);
        }
Beispiel #14
0
        public static bool Insert(T item)
        {
            if (table == null)
            {
                return(false);
            }

            try
            {
                PropertyInfo[] properties = item.GetType().GetProperties();

                ElasticTableEntity record = new ElasticTableEntity();
                BaseTable          tbitem = item as BaseTable;
                record.RowKey       = (tbitem.Id == null) ? Guid.NewGuid().ToString() : tbitem.Id;
                record.PartitionKey = tbitem.Partition;
                record.ETag         = tbitem.Tag;

                foreach (PropertyInfo info in properties)
                {
                    var value = info.GetValue(item, null);
                    record.Properties.Add(info.Name, EntityProperty.CreateEntityPropertyFromObject(value));
                }


                TableOperation insertOrReplaceOperation = TableOperation.Insert(record);

                table.Execute(insertOrReplaceOperation);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Beispiel #15
0
        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <typeparam name="T">The type of return value.</typeparam>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>true if the DictionaryTableEntity contains an element with the specified key; otherwise, false.</returns>
        public bool TryGetValue <T>(string key, out T value)
        {
            var entity = EntityProperty.CreateEntityPropertyFromObject(null);
            var result = this._properties.TryGetValue(key, out entity);

            value = entity.ToObject <T>();
            return(result);
        }
Beispiel #16
0
 private IDictionary <string, EntityProperty> GetProperties(object values)
 {
     if (values != null)
     {
         var props = values.GetType().GetProperties();
         return(props.ToDictionary(k => k.Name, v => EntityProperty.CreateEntityPropertyFromObject(v.GetValue(values, null))));
     }
     return(null);
 }
Beispiel #17
0
        public void ValidCases(string filter, object value, bool result)
        {
            var entity = new DynamicTableEntity("", "");

            entity.Properties.Add(PropertyName, EntityProperty.CreateEntityPropertyFromObject(value));
            var simpleFilter = new SimpleFilter(filter);

            Assert.True(simpleFilter.HasValidExpression);
            Assert.Equal(result, simpleFilter.Satisfies(entity));
        }
 private static void CreateEntityPropertyFromObject(Dictionary <string, EntityProperty> properties, HashSet <string> encryptedPropertyDetailsSet, KeyValuePair <string, string> prop, EdmType edmType)
 {
     if (encryptedPropertyDetailsSet != null && encryptedPropertyDetailsSet.Contains(prop.Key))
     {
         properties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value, EdmType.Binary));
     }
     else
     {
         properties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value, edmType));
     }
 }
        // returns etag
        internal static string ReadAndUpdateTableEntity(ITableEntity entity, ODataEntry entry, EntityReadFlags flags, OperationContext ctx)
        {
            if ((flags & EntityReadFlags.Etag) > 0)
            {
                entity.ETag = entry.ETag;
            }

            Dictionary <string, EntityProperty> entityProperties = (flags & EntityReadFlags.Properties) > 0 ? new Dictionary <string, EntityProperty>() : null;

            if (flags > 0)
            {
                foreach (ODataProperty prop in entry.Properties)
                {
                    if (prop.Name == TableConstants.PartitionKey)
                    {
                        if ((flags & EntityReadFlags.PartitionKey) == 0)
                        {
                            continue;
                        }

                        entity.PartitionKey = (string)prop.Value;
                    }
                    else if (prop.Name == TableConstants.RowKey)
                    {
                        if ((flags & EntityReadFlags.RowKey) == 0)
                        {
                            continue;
                        }

                        entity.RowKey = (string)prop.Value;
                    }
                    else if (prop.Name == TableConstants.Timestamp)
                    {
                        if ((flags & EntityReadFlags.Timestamp) == 0)
                        {
                            continue;
                        }

                        entity.Timestamp = (DateTime)prop.Value;
                    }
                    else if ((flags & EntityReadFlags.Properties) > 0)
                    {
                        entityProperties.Add(prop.Name, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                    }
                }

                if ((flags & EntityReadFlags.Properties) > 0)
                {
                    entity.ReadEntity(entityProperties, ctx);
                }
            }

            return(entry.ETag);
        }
        public static void Apply(this DynamicTableEntity instance, object source, params string[] skipProperties)
        {
            foreach (var property in source.GetType().GetProperties())
            {
                if (skipProperties.Contains(property.Name))
                {
                    continue;
                }

                instance.Properties.Add(property.Name, EntityProperty.CreateEntityPropertyFromObject(property.GetValue(source, null)));
            }
        }
        /// <summary>
        /// Converts object to the EntityProperty.
        /// </summary>
        /// <param name="source">The source object.</param>
        /// <returns>EntityProperty instance.</returns>
        public static EntityProperty ToEntityProperty(this object source)
        {
            if (source is EntityProperty)
            {
                return((EntityProperty)source);
            }

            return(EntityProperty.CreateEntityPropertyFromObject(
                       source.IsEntityPropertyKnownType()
                ? source
                : JsonConvert.SerializeObject(source)));
        }
Beispiel #22
0
        public static DynamicTableEntity ToStorage(this Study study)
        {
            var entry = new DynamicTableEntity
            {
                PartitionKey = study.Culture,
                RowKey       = study.Title,
            };

            entry.Properties["Lessons"] = EntityProperty.CreateEntityPropertyFromObject(JsonConvert.SerializeObject(study.Lessons));

            return(entry);
        }
Beispiel #23
0
        public static DynamicTableEntity ToStorage(this Feedback feedback)
        {
            var entry = new DynamicTableEntity
            {
                PartitionKey = DateTime.UtcNow.ToString("yyyyMMdd"),
                RowKey       = Guid.NewGuid().ToString(),
            };

            entry.Properties["Comment"] = EntityProperty.CreateEntityPropertyFromObject(feedback.Comment);

            return(entry);
        }
Beispiel #24
0
        public static DynamicTableEntity ToStorage(this BibleBook book)
        {
            var entry = new DynamicTableEntity
            {
                PartitionKey = book.Culture,
                RowKey       = book.Order.ToString(),
            };

            entry.Properties["Name"]      = EntityProperty.CreateEntityPropertyFromObject(book.Name);
            entry.Properties["Shorthand"] = EntityProperty.CreateEntityPropertyFromObject(book.Shorthand);

            return(entry);
        }
Beispiel #25
0
        private static EntityProperty BuildNewProperty(DynamicTableEntity entity, JProperty jsonProperty, object value)
        {
            EntityProperty entityProperty;

            if (entity.Properties.TryGetValue(jsonProperty.Name, out entityProperty))
            {
                // this is a special case as Json does not recognize ints
                if (entityProperty.PropertyType == EdmType.Int32)
                {
                    return(new EntityProperty((int)(long)value));
                }
            }
            return(EntityProperty.CreateEntityPropertyFromObject(value));
        }
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            var property = FindProperty(binder.Name);

            if (property != null)
            {
                property.SetValue(this, value);
            }
            else
            {
                _tableData[binder.Name] = EntityProperty.CreateEntityPropertyFromObject(value);
            }

            return(true);
        }
Beispiel #27
0
        public async Task <IEnumerable <ITableEntity> > PeckAsync(PeckSource source)
        {
            if (_query == null)
            {
                _query = GetQuery();
            }


            var results    = new List <ITableEntity>();
            var connection = new SqlConnection(source.SourceConnectionString);

            try
            {
                await connection.OpenAsync();

                var command = new SqlCommand(_query, connection);
                var reader  = await command.ExecuteReaderAsync();

                var columnNames = Enumerable.Range(0, reader.FieldCount).Select(x => reader.GetName(x)).ToDictionary(s => s);

                while (reader.Read())
                {
                    // row key
                    var rowKeyParams = GetRowKeyFieldNames().Select(x => columnNames.ContainsKey(x) ? reader[x].ToString() : x).ToArray();
                    var rowKey       = rowKeyParams.Length == 0 ? Guid.NewGuid().ToString("N") : string.Join("_", rowKeyParams);

                    // par key
                    var ofsted       = new DateTimeOffset(reader.GetDateTime(reader.GetOrdinal(GetUtcTimestampFieldName())), TimeSpan.Zero);
                    var minuteOffset = new DateTimeOffset(DateTime.Parse(ofsted.UtcDateTime.ToString("yyyy-MM-dd HH:mm:00")), TimeSpan.Zero);
                    var shardKey     = (DateTimeOffset.MaxValue.Ticks - minuteOffset.Ticks).ToString("D19");

                    var entity = new DynamicTableEntity(shardKey, rowKey);
                    foreach (var columnName in columnNames.Keys)
                    {
                        entity.Properties.Add(columnName, EntityProperty.CreateEntityPropertyFromObject(reader[columnName]));
                    }

                    results.Add(entity);
                }


                return(results);
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #28
0
    /// <summary>
    /// A convenience method to set/insert a single entity in an Azure table.
    /// </summary>
    /// <param name="table">The name of the table that will contain the new entity.</param>
    /// <param name="partitionKey">The partition key of the entity.</param>
    /// <param name="rowKey">The row key of the entity.</param>
    /// <param name="properties">An object containing all of the other properties of the entity.</param>
    /// <returns>The result of the operation.</returns>
    public static TableResult Set(string table, string partitionKey, string rowKey, object properties = null)
    {
        var entity = new DynamicTableEntity(partitionKey, rowKey);

        if (properties != null)
        {
            foreach (var property in HtmlHelper.AnonymousObjectToHtmlAttributes(properties))
            {
                entity.Properties.Add(property.Key.Replace('-', '_'), EntityProperty.CreateEntityPropertyFromObject(property.Value));
            }
        }
        var storage   = CloudStorageAccount.Parse(StorageConnectionString);
        var client    = storage.CreateCloudTableClient();
        var reference = client.GetTableReference(table);

        return(reference.Execute(TableOperation.InsertOrReplace(entity)));
    }
        internal static string ReadAndUpdateTableEntity(ITableEntity entity, string etag, Dictionary <string, object> props, EntityReadFlags flags, OperationContext ctx)
        {
            if ((flags & EntityReadFlags.Etag) > (EntityReadFlags)0)
            {
                entity.ETag = etag;
            }
            Dictionary <string, EntityProperty> dictionary = ((flags & EntityReadFlags.Properties) > (EntityReadFlags)0) ? new Dictionary <string, EntityProperty>() : null;

            if (flags > (EntityReadFlags)0)
            {
                foreach (KeyValuePair <string, object> prop in props)
                {
                    if (prop.Key == "PartitionKey")
                    {
                        if ((flags & EntityReadFlags.PartitionKey) != 0)
                        {
                            entity.PartitionKey = (string)prop.Value;
                        }
                    }
                    else if (prop.Key == "RowKey")
                    {
                        if ((flags & EntityReadFlags.RowKey) != 0)
                        {
                            entity.RowKey = (string)prop.Value;
                        }
                    }
                    else if (prop.Key == "Timestamp")
                    {
                        if ((flags & EntityReadFlags.Timestamp) != 0)
                        {
                            entity.Timestamp = (DateTime)prop.Value;
                        }
                    }
                    else if ((flags & EntityReadFlags.Properties) > (EntityReadFlags)0)
                    {
                        dictionary.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value));
                    }
                }
                if ((flags & EntityReadFlags.Properties) > (EntityReadFlags)0)
                {
                    entity.ReadEntity(dictionary, ctx);
                }
            }
            return(etag);
        }
        private static IDictionary <string, EntityProperty> ReflectionWrite(object entity, OperationContext operationContext)
        {
            Dictionary <string, EntityProperty> retVals = new Dictionary <string, EntityProperty>();

            IEnumerable <PropertyInfo> objectProperties = entity.GetType().GetTypeInfo().GetProperties();

            foreach (PropertyInfo property in objectProperties)
            {
                if (ShouldSkipProperty(property, operationContext))
                {
                    continue;
                }

                // check if we have a special convert attached via attribute if so generate the required target
                // properties with the correct converter
                if (property.GetCustomAttribute <VirtualTypeAttribute>() != null)
                {
                    var typeConvert = property.GetCustomAttribute <VirtualTypeAttribute>();
                    typeConvert.WriteProperty(property, entity, retVals);
                }
                else if (property.GetCustomAttribute <StoreAsAttribute>() != null)
                {
                    var typeConvert = property.GetCustomAttribute <StoreAsAttribute>();
                    var newProperty = typeConvert.ConvertToEntityProperty(property, entity);

                    if (newProperty != null)
                    {
                        retVals.Add(property.Name, newProperty);
                    }
                }
                else
                {
                    EntityProperty newProperty = EntityProperty.CreateEntityPropertyFromObject(property.GetValue(entity, null));

                    // property will be null if unknown type
                    if (newProperty != null)
                    {
                        retVals.Add(property.Name, newProperty);
                    }
                }
            }

            return(retVals);
        }