| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Reflection; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Runtime |
| | | 8 | | { |
| | | 9 | | public static class ReflectionExtensions |
| | | 10 | | { |
| | | 11 | | public static TypeCode GetTypeCode(this Type type) |
| | | 12 | | { |
| | 6764 | 13 | | if (type == null) |
| | | 14 | | { |
| | 0 | 15 | | return TypeCode.Empty; |
| | | 16 | | } |
| | | 17 | | |
| | 6764 | 18 | | if (type == typeof(bool)) |
| | | 19 | | { |
| | 179 | 20 | | return TypeCode.Boolean; |
| | | 21 | | } |
| | | 22 | | |
| | 6585 | 23 | | if (type == typeof(char)) |
| | | 24 | | { |
| | 2 | 25 | | return TypeCode.Char; |
| | | 26 | | } |
| | | 27 | | |
| | 6583 | 28 | | if (type == typeof(sbyte)) |
| | | 29 | | { |
| | 2 | 30 | | return TypeCode.SByte; |
| | | 31 | | } |
| | | 32 | | |
| | 6581 | 33 | | if (type == typeof(byte)) |
| | | 34 | | { |
| | 108 | 35 | | return TypeCode.Byte; |
| | | 36 | | } |
| | | 37 | | |
| | 6473 | 38 | | if (type == typeof(short)) |
| | | 39 | | { |
| | 2 | 40 | | return TypeCode.Int16; |
| | | 41 | | } |
| | | 42 | | |
| | 6471 | 43 | | if (type == typeof(ushort)) |
| | | 44 | | { |
| | 2 | 45 | | return TypeCode.UInt16; |
| | | 46 | | } |
| | | 47 | | |
| | 6469 | 48 | | if (type == typeof(int)) |
| | | 49 | | { |
| | 245 | 50 | | return TypeCode.Int32; |
| | | 51 | | } |
| | | 52 | | |
| | 6224 | 53 | | if (type == typeof(uint)) |
| | | 54 | | { |
| | 2 | 55 | | return TypeCode.UInt32; |
| | | 56 | | } |
| | | 57 | | |
| | 6222 | 58 | | if (type == typeof(long)) |
| | | 59 | | { |
| | 10 | 60 | | return TypeCode.Int64; |
| | | 61 | | } |
| | | 62 | | |
| | 6212 | 63 | | if (type == typeof(ulong)) |
| | | 64 | | { |
| | 2 | 65 | | return TypeCode.UInt64; |
| | | 66 | | } |
| | | 67 | | |
| | 6210 | 68 | | if (type == typeof(float)) |
| | | 69 | | { |
| | 9 | 70 | | return TypeCode.Single; |
| | | 71 | | } |
| | | 72 | | |
| | 6201 | 73 | | if (type == typeof(double)) |
| | | 74 | | { |
| | 6 | 75 | | return TypeCode.Double; |
| | | 76 | | } |
| | | 77 | | |
| | 6195 | 78 | | if (type == typeof(decimal)) |
| | | 79 | | { |
| | 6 | 80 | | return TypeCode.Decimal; |
| | | 81 | | } |
| | | 82 | | |
| | 6189 | 83 | | if (type == typeof(DateTime)) |
| | | 84 | | { |
| | 6 | 85 | | return TypeCode.DateTime; |
| | | 86 | | } |
| | | 87 | | |
| | 6183 | 88 | | if (type == typeof(string)) |
| | | 89 | | { |
| | 5420 | 90 | | return TypeCode.String; |
| | | 91 | | } |
| | | 92 | | |
| | 763 | 93 | | if (type.GetTypeInfo().IsEnum) |
| | | 94 | | { |
| | 0 | 95 | | return GetTypeCode(Enum.GetUnderlyingType(type)); |
| | | 96 | | } |
| | | 97 | | |
| | 763 | 98 | | return TypeCode.Object; |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |