public static IsPrimitive ( |
||
type | ||
return | bool |
public static bool IsPrimitive(Type type)
{
var typeWrapper = TypeFactory.GetTypeInfo(type);
return (
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Boolean))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Byte))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Char))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(DateTime))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Decimal))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Double))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(int))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(long))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(SByte))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(short))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Single))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(String))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(uint))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ulong))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ushort))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Guid))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(byte[]))) ||
typeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(MemoryStream))));
}
/// <summary> /// Validates configurations and sets required fields /// </summary> public void Validate(DynamoDBContext context) { if (IsVersion) { Utils.ValidateVersionType(MemberType); // no conversion is possible, so type must be a nullable primitive } if (IsHashKey && IsRangeKey) { throw new InvalidOperationException("Property " + PropertyName + " cannot be both hash and range key"); } if (ConverterType != null) { if (!Utils.CanInstantiateConverter(ConverterType) || !Utils.ImplementsInterface(ConverterType, typeof(IPropertyConverter))) { throw new InvalidOperationException("Converter for " + PropertyName + " must be instantiable with no parameters and must implement IPropertyConverter"); } this.Converter = Utils.InstantiateConverter(ConverterType, context) as IPropertyConverter; } IPropertyConverter converter; if (context.ConverterCache.TryGetValue(MemberType, out converter) && converter != null) { this.Converter = converter; } if (IsKey || IsGSIKey) { if (Converter == null && !Utils.IsPrimitive(MemberType)) { throw new InvalidOperationException("Key " + PropertyName + " must be of primitive type"); } } foreach (var index in Indexes) { IndexNames.AddRange(index.IndexNames); } }