< Summary

Class:Azure.Messaging.EventHubs.Amqp.TypeExtensions
Assembly:Azure.Messaging.EventHubs
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Amqp\TypeExtensions.cs
Covered lines:27
Uncovered lines:0
Coverable lines:27
Total lines:63
Line coverage:100% (27 of 27)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
ToAmqpPropertyType(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Amqp\TypeExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6
 7namespace Azure.Messaging.EventHubs.Amqp
 8{
 9    /// <summary>
 10    ///   The set of extension methods for the <see cref="Type" /> class.
 11    /// </summary>
 12    ///
 13    internal static class TypeExtensions
 14    {
 15        /// <summary>The set of mappings from CLR types to AMQP types for property values.</summary>
 216        private static readonly IReadOnlyDictionary<Type, AmqpProperty.Type> AmqpPropertyTypeMap = new Dictionary<Type, 
 217        {
 218            { typeof(byte), AmqpProperty.Type.Byte },
 219            { typeof(sbyte), AmqpProperty.Type.SByte },
 220            { typeof(char), AmqpProperty.Type.Char },
 221            { typeof(short), AmqpProperty.Type.Int16 },
 222            { typeof(ushort), AmqpProperty.Type.UInt16 },
 223            { typeof(int), AmqpProperty.Type.Int32 },
 224            { typeof(uint), AmqpProperty.Type.UInt32 },
 225            { typeof(long), AmqpProperty.Type.Int64 },
 226            { typeof(ulong), AmqpProperty.Type.UInt64 },
 227            { typeof(float), AmqpProperty.Type.Single },
 228            { typeof(double), AmqpProperty.Type.Double },
 229            { typeof(decimal), AmqpProperty.Type.Decimal },
 230            { typeof(bool), AmqpProperty.Type.Boolean },
 231            { typeof(Guid), AmqpProperty.Type.Guid },
 232            { typeof(string), AmqpProperty.Type.String },
 233            { typeof(Uri), AmqpProperty.Type.Uri },
 234            { typeof(DateTime), AmqpProperty.Type.DateTime },
 235            { typeof(DateTimeOffset), AmqpProperty.Type.DateTimeOffset },
 236            { typeof(TimeSpan), AmqpProperty.Type.TimeSpan },
 237        };
 38
 39        /// <summary>
 40        ///   Translates the given <see cref="Type" /> to the corresponding
 41        ///   <see cref="AmqpProperty.Type" />.
 42        /// </summary>
 43        ///
 44        /// <param name="instance">The instance that this method was invoked on.</param>
 45        ///
 46        /// <returns>The AMQP property type that best matches the specified <paramref name="instance"/>.</returns>
 47        ///
 48        public static AmqpProperty.Type ToAmqpPropertyType(this Type instance)
 49        {
 21450            if (instance == null)
 51            {
 252                return AmqpProperty.Type.Null;
 53            }
 54
 21255            if (AmqpPropertyTypeMap.TryGetValue(instance, out AmqpProperty.Type amqpType))
 56            {
 17457                return amqpType;
 58            }
 59
 3860            return AmqpProperty.Type.Unknown;
 61        }
 62    }
 63}

Methods/Properties

.cctor()
ToAmqpPropertyType(...)