Exemplo n.º 1
0
        public static T Convert <T>(DynamoDBEntry entry)
        {
            Type type = typeof(T);

#pragma warning disable IDE0011 // Add braces
            if (type == typeof(bool))
            {
                return((T)(object)entry.AsBoolean());
            }
            if (type == typeof(byte))
            {
                return((T)(object)entry.AsByte());
            }
            if (type == typeof(byte[]))
            {
                return((T)(object)entry.AsByteArray());
            }
            if (type == typeof(char))
            {
                return((T)(object)entry.AsChar());
            }
            if (type == typeof(DateTime))
            {
                return((T)(object)entry.AsDateTime());
            }
            if (type == typeof(decimal))
            {
                return((T)(object)entry.AsDecimal());
            }
            if (type == typeof(double))
            {
                return((T)(object)entry.AsDouble());
            }
            if (type == typeof(Guid))
            {
                return((T)(object)entry.AsGuid());
            }
            if (type == typeof(int))
            {
                return((T)(object)entry.AsInt());
            }
            if (type == typeof(long))
            {
                return((T)(object)entry.AsLong());
            }
            if (type == typeof(MemoryStream))
            {
                return((T)(object)entry.AsMemoryStream());
            }
            if (type == typeof(sbyte))
            {
                return((T)(object)entry.AsSByte());
            }
            if (type == typeof(short))
            {
                return((T)(object)entry.AsShort());
            }
            if (type == typeof(float))
            {
                return((T)(object)entry.AsSingle());
            }
            if (type == typeof(string))
            {
                return((T)(object)entry.AsString());
            }
            if (type == typeof(uint))
            {
                return((T)(object)entry.AsUInt());
            }
            if (type == typeof(ulong))
            {
                return((T)(object)entry.AsULong());
            }
            if (type == typeof(ushort))
            {
                return((T)(object)entry.AsUShort());
            }
#pragma warning restore IDE0011 // Add braces
            throw new InvalidOperationException($"{type.FullName} is not supported as aggregate key in DynamoDB");
        }