| | 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 | |
|
| | 4 | | namespace 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 | | { |
| 2 | 23 | | static readonly Dictionary<Type, PropertyValueType> TypeToIntMap = new Dictionary<Type, PropertyValueType> |
| 2 | 24 | | { |
| 2 | 25 | | { typeof(byte), PropertyValueType.Byte }, |
| 2 | 26 | | { typeof(sbyte), PropertyValueType.SByte }, |
| 2 | 27 | | { typeof(char), PropertyValueType.Char }, |
| 2 | 28 | | { typeof(short), PropertyValueType.Int16 }, |
| 2 | 29 | | { typeof(ushort), PropertyValueType.UInt16 }, |
| 2 | 30 | | { typeof(int), PropertyValueType.Int32 }, |
| 2 | 31 | | { typeof(uint), PropertyValueType.UInt32 }, |
| 2 | 32 | | { typeof(long), PropertyValueType.Int64 }, |
| 2 | 33 | | { typeof(ulong), PropertyValueType.UInt64 }, |
| 2 | 34 | | { typeof(float), PropertyValueType.Single }, |
| 2 | 35 | | { typeof(double), PropertyValueType.Double }, |
| 2 | 36 | | { typeof(decimal), PropertyValueType.Decimal }, |
| 2 | 37 | | { typeof(bool), PropertyValueType.Boolean }, |
| 2 | 38 | | { typeof(Guid), PropertyValueType.Guid }, |
| 2 | 39 | | { typeof(string), PropertyValueType.String }, |
| 2 | 40 | | { typeof(Uri), PropertyValueType.Uri }, |
| 2 | 41 | | { typeof(DateTime), PropertyValueType.DateTime }, |
| 2 | 42 | | { typeof(DateTimeOffset), PropertyValueType.DateTimeOffset }, |
| 2 | 43 | | { typeof(TimeSpan), PropertyValueType.TimeSpan }, |
| 2 | 44 | | ////{ typeof(BufferedInputStream), PropertyValueType.Stream }, |
| 2 | 45 | | }; |
| | 46 | |
|
| | 47 | | public static PropertyValueType GetTypeId(object value) |
| | 48 | | { |
| 12 | 49 | | if (value == null) |
| | 50 | | { |
| 0 | 51 | | return PropertyValueType.Null; |
| | 52 | | } |
| | 53 | |
|
| 12 | 54 | | if (TypeToIntMap.TryGetValue(value.GetType(), out var propertyValueType)) |
| | 55 | | { |
| 4 | 56 | | return propertyValueType; |
| | 57 | | } |
| | 58 | |
|
| 8 | 59 | | return PropertyValueType.Unknown; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public static bool IsSupportedPropertyType(Type type) |
| | 63 | | { |
| 0 | 64 | | return TypeToIntMap.ContainsKey(type); |
| | 65 | | } |
| | 66 | | } |
| | 67 | | } |