< Summary

Class:Azure.Data.Tables.TableEntityExtensions
Assembly:Azure.Data.Tables
File(s):C:\Git\azure-sdk-for-net\sdk\tables\Azure.Data.Tables\src\Extensions\TableEntityExtensions.cs
Covered lines:20
Uncovered lines:0
Coverable lines:20
Total lines:59
Line coverage:100% (20 of 20)
Covered branches:16
Total branches:16
Branch coverage:100% (16 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ToOdataAnnotatedDictionary(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\tables\Azure.Data.Tables\src\Extensions\TableEntityExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Reflection;
 7
 8namespace Azure.Data.Tables
 9{
 10    internal static class TableEntityExtensions
 11    {
 12        /// <summary>
 13        /// Returns a new Dictionary with the appropriate Odata type annotation for a given propertyName value pair.
 14        /// The default case is intentionally unhandled as this means that no type annotation for the specified type is 
 15        /// This is because the type is naturally serialized in a way that the table service can interpret without hints
 16        /// </summary>
 17        internal static Dictionary<string, object> ToOdataAnnotatedDictionary<T>(this T entity) where T : class, ITableE
 18        {
 190819            if (entity is IDictionary<string, object> dictEntity)
 20            {
 84021                return dictEntity.ToOdataAnnotatedDictionary();
 22            }
 23
 106824            var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
 106825            var annotatedDictionary = new Dictionary<string, object>(properties.Length * 2);
 26
 4512027            foreach (var prop in properties)
 28            {
 2149229                annotatedDictionary[prop.Name] = prop.GetValue(entity);
 30
 2149231                switch (annotatedDictionary[prop.Name])
 32                {
 33                    case byte[] _:
 132034                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmBinary;
 132035                        break;
 36                    case long _:
 189637                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmInt64;
 38                        // Int64 / long should be serialized as string.
 189639                        annotatedDictionary[prop.Name] = annotatedDictionary[prop.Name].ToString();
 189640                        break;
 41                    case double _:
 218442                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmDouble;
 218443                        break;
 44                    case Guid _:
 132045                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmGuid;
 132046                        break;
 47                    case DateTimeOffset _:
 132048                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmDateTime;
 132049                        break;
 50                    case DateTime _:
 132051                        annotatedDictionary[prop.Name.ToOdataTypeString()] = TableConstants.Odata.EdmDateTime;
 52                        break;
 53                }
 54            }
 55
 106856            return annotatedDictionary;
 57        }
 58    }
 59}

Methods/Properties

ToOdataAnnotatedDictionary(...)