< Summary

Class:Azure.Data.Tables.Queryable.ClientConvert
Assembly:Azure.Data.Tables
File(s):C:\Git\azure-sdk-for-net\sdk\tables\Azure.Data.Tables\src\Queryable\ClientConvert.cs
Covered lines:39
Uncovered lines:5
Coverable lines:44
Total lines:123
Line coverage:88.6% (39 of 44)
Covered branches:7
Total branches:10
Branch coverage:70% (7 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
IsBinaryValue(...)-100%100%
TryKeyBinaryToString(...)-0%100%
TryKeyPrimitiveToString(...)-71.43%66.67%
CreateKnownPrimitives()-100%100%
IndexOfStorage(...)-100%100%
IndexOfReference(...)-75%75%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Data.Tables.Queryable
 7{
 8    internal static class ClientConvert
 9    {
 210        private static readonly Type[] s_knownTypes = CreateKnownPrimitives();
 11
 12
 13        internal enum StorageType
 14        {
 15            Boolean,
 16            Byte,
 17            ByteArray,
 18            Char,
 19            CharArray,
 20            DateTime,
 21            DateTimeOffset,
 22            Decimal,
 23            Double,
 24            Guid,
 25            Int16,
 26            Int32,
 27            Int64,
 28            Single,
 29            String,
 30            SByte,
 31            TimeSpan,
 32            Type,
 33            UInt16,
 34            UInt32,
 35            UInt64,
 36            Uri,
 37            XDocument,
 38            XElement,
 39            Binary,
 40        }
 41
 42        internal static bool IsBinaryValue(object value)
 43        {
 80844            return StorageType.Binary == (StorageType)IndexOfStorage(value.GetType());
 45        }
 46
 47        internal static bool TryKeyBinaryToString(object binaryValue, out string result)
 48        {
 49            const System.Reflection.BindingFlags Flags = System.Reflection.BindingFlags.Public | System.Reflection.Bindi
 050            byte[] bytes = (byte[])binaryValue.GetType().InvokeMember("ToArray", Flags, null, binaryValue, null, null /*
 051            return WebConvert.TryKeyPrimitiveToString(bytes, out result);
 52        }
 53
 54        internal static bool TryKeyPrimitiveToString(object value, out string result)
 55        {
 80856            if (IsBinaryValue(value))
 57            {
 058                return TryKeyBinaryToString(value, out result);
 59            }
 60            // Support DateTimeOffset
 80861            if (value is DateTimeOffset)
 62            {
 5263                value = ((DateTimeOffset)value).UtcDateTime;
 64            }
 75665            else if (value is DateTimeOffset?)
 66            {
 067                value = ((DateTimeOffset?)value).Value.UtcDateTime;
 68            }
 69
 80870            return WebConvert.TryKeyPrimitiveToString(value, out result);
 71        }
 72
 73        private static Type[] CreateKnownPrimitives()
 74        {
 275            Type[] types = new Type[1 + (int)StorageType.Binary];
 276            types[(int)StorageType.Boolean] = typeof(bool);
 277            types[(int)StorageType.Byte] = typeof(byte);
 278            types[(int)StorageType.ByteArray] = typeof(byte[]);
 279            types[(int)StorageType.Char] = typeof(char);
 280            types[(int)StorageType.CharArray] = typeof(char[]);
 281            types[(int)StorageType.DateTime] = typeof(DateTime);
 282            types[(int)StorageType.DateTimeOffset] = typeof(DateTimeOffset);
 283            types[(int)StorageType.Decimal] = typeof(decimal);
 284            types[(int)StorageType.Double] = typeof(double);
 285            types[(int)StorageType.Guid] = typeof(Guid);
 286            types[(int)StorageType.Int16] = typeof(short);
 287            types[(int)StorageType.Int32] = typeof(int);
 288            types[(int)StorageType.Int64] = typeof(long);
 289            types[(int)StorageType.Single] = typeof(float);
 290            types[(int)StorageType.String] = typeof(string);
 291            types[(int)StorageType.SByte] = typeof(sbyte);
 292            types[(int)StorageType.TimeSpan] = typeof(TimeSpan);
 293            types[(int)StorageType.Type] = typeof(Type);
 294            types[(int)StorageType.UInt16] = typeof(ushort);
 295            types[(int)StorageType.UInt32] = typeof(uint);
 296            types[(int)StorageType.UInt64] = typeof(ulong);
 297            types[(int)StorageType.Uri] = typeof(Uri);
 298            types[(int)StorageType.XDocument] = typeof(System.Xml.Linq.XDocument);
 299            types[(int)StorageType.XElement] = typeof(System.Xml.Linq.XElement);
 2100            types[(int)StorageType.Binary] = null;
 2101            return types;
 102        }
 103
 104        private static int IndexOfStorage(Type type)
 105        {
 808106            int index = ClientConvert.IndexOfReference(ClientConvert.s_knownTypes, type);
 808107            return index;
 108        }
 109
 110        internal static int IndexOfReference<T>(T[] array, T value) where T : class
 111        {
 18344112            for (int i = 0; i < array.Length; ++i)
 113            {
 9172114                if (object.ReferenceEquals(array[i], value))
 115                {
 808116                    return i;
 117                }
 118            }
 119
 0120            return -1;
 121        }
 122    }
 123}