Amazon.DynamoDBv2.DataModel.Utils.ValidateVersionType C# (CSharp) Метод

ValidateVersionType() публичный статический Метод

public static ValidateVersionType ( Type memberType ) : void
memberType System.Type
Результат void
        public static void ValidateVersionType(Type memberType)
        {
            var memberTypeWrapper = TypeFactory.GetTypeInfo(memberType);
            if (memberTypeWrapper.IsGenericType && memberTypeWrapper.GetGenericTypeDefinition() == typeof(Nullable<>) &&
                (memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(Byte))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(SByte))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(int))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(uint))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(long))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ulong))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(short))) ||
                memberTypeWrapper.IsAssignableFrom(TypeFactory.GetTypeInfo(typeof(ushort)))))
            {
                return;
            }
            throw new InvalidOperationException("Version property must be of primitive, numeric, integer, nullable type (e.g. int?, long?, byte?)");
        }

Usage Example

Пример #1
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;
            }
        }
All Usage Examples Of Amazon.DynamoDBv2.DataModel.Utils::ValidateVersionType