示例#1
0
        /// <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;
            }

            foreach (var index in Indexes)
            {
                IndexNames.AddRange(index.IndexNames);
            }
        }
示例#2
0
        /// <summary>
        /// Validates configurations and sets required fields
        /// </summary>
        public void Validate()
        {
            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 (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);
            }

            if (ConverterType != null)
            {
                if (!Utils.CanInstantiate(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.Instantiate(ConverterType) as IPropertyConverter;
            }
        }