public static object AsType(this DynamoDBEntry entry, Type type) { if (type == stringType) { return(entry.AsString()); } else if (type == intType) { return(entry.AsInt()); } else if (type == boolType) { return(entry.AsBoolean()); } else if (type == longType) { return(entry.AsLong()); } else if (type == dateTimeType) { return(entry.AsDateTime()); } else if (type == doubleType) { return(entry.AsDouble()); } else if (type == floatType) { return(entry.AsSingle()); } else if (type == listOfStringType) { return(entry.AsListOfString()); } else if (type == listOfByteArrayType) { return(entry.AsListOfString()); } return(null); }
public object FromEntry(DynamoDBEntry entry) { var ticks = entry.AsLong(); return(new DateTimeOffset(ticks, DateTimeOffset.UtcNow.Offset)); }
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"); }