< Summary

Class:Microsoft.Azure.ServiceBus.Amqp.SerializationUtilities
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\SerializationUtilities.cs
Covered lines:27
Uncovered lines:2
Coverable lines:29
Total lines:67
Line coverage:93.1% (27 of 29)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
GetTypeId(...)-80%75%
IsSupportedPropertyType(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\SerializationUtilities.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus.Amqp
 5{
 6    using System;
 7    using System.Collections.Generic;
 8
 9    // WARNING: Consult filter engine owner before modifying this enum.
 10    // Introducing a new member here has impact to filtering engine in data type precedence and data conversion.
 11    // ALWAYS insert new types before Unknown!
 12    enum PropertyValueType
 13    {
 14        Null,
 15        Byte, SByte, Char, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal, // Numeric types
 16        Boolean, Guid, String, Uri, DateTime, DateTimeOffset, TimeSpan,
 17        Stream,
 18        Unknown,
 19    }
 20
 21    class SerializationUtilities
 22    {
 223        static readonly Dictionary<Type, PropertyValueType> TypeToIntMap = new Dictionary<Type, PropertyValueType>
 224        {
 225            { typeof(byte), PropertyValueType.Byte },
 226            { typeof(sbyte), PropertyValueType.SByte },
 227            { typeof(char), PropertyValueType.Char },
 228            { typeof(short), PropertyValueType.Int16 },
 229            { typeof(ushort), PropertyValueType.UInt16 },
 230            { typeof(int), PropertyValueType.Int32 },
 231            { typeof(uint), PropertyValueType.UInt32 },
 232            { typeof(long), PropertyValueType.Int64 },
 233            { typeof(ulong), PropertyValueType.UInt64 },
 234            { typeof(float), PropertyValueType.Single },
 235            { typeof(double), PropertyValueType.Double },
 236            { typeof(decimal), PropertyValueType.Decimal },
 237            { typeof(bool), PropertyValueType.Boolean },
 238            { typeof(Guid), PropertyValueType.Guid },
 239            { typeof(string), PropertyValueType.String },
 240            { typeof(Uri), PropertyValueType.Uri },
 241            { typeof(DateTime), PropertyValueType.DateTime },
 242            { typeof(DateTimeOffset), PropertyValueType.DateTimeOffset },
 243            { typeof(TimeSpan), PropertyValueType.TimeSpan },
 244            ////{ typeof(BufferedInputStream), PropertyValueType.Stream },
 245        };
 46
 47        public static PropertyValueType GetTypeId(object value)
 48        {
 1249            if (value == null)
 50            {
 051                return PropertyValueType.Null;
 52            }
 53
 1254            if (TypeToIntMap.TryGetValue(value.GetType(), out var propertyValueType))
 55            {
 456                return propertyValueType;
 57            }
 58
 859            return PropertyValueType.Unknown;
 60        }
 61
 62        public static bool IsSupportedPropertyType(Type type)
 63        {
 064            return TypeToIntMap.ContainsKey(type);
 65        }
 66    }
 67}