public override object GetValue(PropertyInfo propertyInfo)
        {
            MemoryUniqueValueGenerator.Logger.Debug($"Entering GetValue. propertyInfo: {propertyInfo.GetExtendedMemberInfoString()}");

            if (propertyInfo.PropertyType == typeof (Guid))
            {
                MemoryUniqueValueGenerator.Logger.Debug("Property type is Guid. Returning new Guid.");
                Guid result = Guid.NewGuid();

                MemoryUniqueValueGenerator.Logger.Debug($"result: {result}");
                return result;
            }

            var primaryKeyAttribute = this.attributeDecorator.GetSingleAttribute<PrimaryKeyAttribute>(propertyInfo);

            if (primaryKeyAttribute == null)
            {
                MemoryUniqueValueGenerator.Logger.Debug("primaryKeyAttribute == null");
                object result = base.GetValue(propertyInfo);

                MemoryUniqueValueGenerator.Logger.Debug($"result fom base: {result}");
                return result ?? Helper.GetDefaultValue(propertyInfo.PropertyType);
            }

            if (primaryKeyAttribute.KeyType == PrimaryKeyAttribute.KeyTypeEnum.Manual
                || primaryKeyAttribute.KeyType == PrimaryKeyAttribute.KeyTypeEnum.Auto)
            {
                MemoryUniqueValueGenerator.Logger.Debug("Deferring value");
                this.DeferValue(propertyInfo);
            }

            MemoryUniqueValueGenerator.Logger.Debug("Exiting GetValue.");
            return Helper.GetDefaultValue(propertyInfo.PropertyType);
        }
コード例 #2
0
        public object GetArray(PropertyInfo propertyInfo, Type type)
        {
            StandardArrayRandomizer.Logger.Debug($"Entering GetArray. propertyInfo: {propertyInfo.GetExtendedMemberInfoString()}, type: {type}");

            Array resultArray;

            int rank = type.GetArrayRank();
            Type basicType = type.GetElementType();

            if (rank > 1)
            {
                StandardArrayRandomizer.Logger.Debug($"rank > 1: {rank}");

                var dimensionSizes = new int[rank];

                for (int i = 0; i < dimensionSizes.Length; i++)
                {
                    StandardArrayRandomizer.Logger.Debug($"dimensionSize {i}: {dimensionSizes[i]}");
                    dimensionSizes[i] = this.random.Next(StandardArrayRandomizer.MaxDimensionLength) + 1;
                }

                EmptyArrayResult emptyArrayResult = StandardArrayRandomizer.GetEmptyArray(type, dimensionSizes);

                do
                {
                    object resultElement = this.valueGenerator.GetValue(propertyInfo, basicType);
                    StandardArrayRandomizer.Logger.Debug($"Result element: {resultElement}");
                    emptyArrayResult.Array.SetValue(resultElement, emptyArrayResult.Indices.Value);
                    emptyArrayResult.Indices++;

                } while (!emptyArrayResult.Indices.Overflow);

                resultArray = emptyArrayResult.Array;
            }
            else
            {
                StandardArrayRandomizer.Logger.Debug($"rank <= 1: {rank}");

                int dimensionLength = this.random.Next(StandardArrayRandomizer.MaxDimensionLength) + 1;
                ConstructorInfo constructor = type.GetConstructor(new[] { typeof(int) });
                resultArray = (Array)constructor.Invoke(new object[] { dimensionLength });

                for (int i = 0; i < dimensionLength; i++)
                {
                    object value = this.valueGenerator.GetValue(propertyInfo, basicType);
                    StandardArrayRandomizer.Logger.Debug($"Element value: {value}");
                    resultArray.SetValue(value, i);
                }
            }

            StandardArrayRandomizer.Logger.Debug("Exiting GetArray");

            return resultArray;
        }
コード例 #3
0
        protected override void SetProperty(object objectToFill, PropertyInfo targetPropertyInfo)
        {
            UniqueValueTypeGenerator.Logger.Debug("Entering SetProperty. targetPropertyInfo: " +
                                                  targetPropertyInfo.GetExtendedMemberInfoString());

            if (!targetPropertyInfo.PropertyType.IsValueLikeType())
            {
                UniqueValueTypeGenerator.Logger.Debug("Property type is value like. Calling base.");

                base.SetProperty(objectToFill, targetPropertyInfo);
                return;
            }

            object targetPropertyValue = this.accumulatorValueGenerator.GetValue(targetPropertyInfo);
            UniqueValueTypeGenerator.Logger.Debug($"targetPropertyValue: {targetPropertyValue}");
            targetPropertyInfo.SetValue(objectToFill, targetPropertyValue);

            UniqueValueTypeGenerator.Logger.Debug("Exiting SetProperty");
        }
        public override object GetValue(PropertyInfo propertyInfo)
        {
            KeyTypeUniqueValueGenerator.Logger.Debug(
                $"Entering GetValue. propertyInfo: {propertyInfo.GetExtendedMemberInfoString()}");

            var primaryKeyAttribute = this.attributeDecorator.GetSingleAttribute<PrimaryKeyAttribute>(propertyInfo);

            if (primaryKeyAttribute == null)
            {
                KeyTypeUniqueValueGenerator.Logger.Debug("primaryKeyAttribute == null");

                object result = base.GetValue(propertyInfo);

                KeyTypeUniqueValueGenerator.Logger.Debug($"result fom base: {result}");

                return result ?? Helper.GetDefaultValue(propertyInfo.PropertyType);
            }

            KeyTypeUniqueValueGenerator.Logger.Debug($"primaryKeyAttribute.KeyType: {primaryKeyAttribute.KeyType}");

            if (this.attributeDecorator.GetSingleAttribute<ForeignKeyAttribute>(propertyInfo) != null ||
                primaryKeyAttribute.KeyType != PrimaryKeyAttribute.KeyTypeEnum.Manual || !new[]
                {
                    typeof (byte), typeof (int), typeof (short), typeof (long), typeof (string),
                    typeof (uint), typeof (ushort), typeof (ulong),
                }.Contains(propertyInfo.PropertyType))
            {
                KeyTypeUniqueValueGenerator.Logger.Debug("Not deferring value. Exiting GetValue.");
                return Helper.GetDefaultValue(propertyInfo.PropertyType);
            }

            KeyTypeUniqueValueGenerator.Logger.Debug("Deferring value");

            this.DeferValue(propertyInfo);

            KeyTypeUniqueValueGenerator.Logger.Debug("Exiting GetValue");
            return Helper.GetDefaultValue(propertyInfo.PropertyType);
        }
コード例 #5
0
 public PopulatePrimaryKeyException(string message, PropertyInfo propertyInfo)
     : base(string.Format(message, propertyInfo.GetExtendedMemberInfoString()))
 {
 }
        private string Write(PropertyInfo propertyInfo, GetSelectDelegate getSelectDelegate)
        {
            SqlWriterCommandTextGenerator.Logger.Debug("Entering Write. propertyInfo: " + propertyInfo.GetExtendedMemberInfoString());

            TableName tableName = Helper.GetTableName(propertyInfo.DeclaringType, this.attributeDecorator);
            string columnName = Helper.GetColumnName(propertyInfo, this.attributeDecorator);

            string result = getSelectDelegate(tableName.CatalogueName, tableName.Schema, tableName.Name, columnName);

            SqlWriterCommandTextGenerator.Logger.Debug($"Result statement: {result}");

            SqlWriterCommandTextGenerator.Logger.Debug("Exiting Write");
            return result;
        }
コード例 #7
0
        private DecoderDelegate WriteStringCommand(PropertyInfo propertyInfo)
        {
            SqlWriterDictionary.Logger.Debug("Entering WriteStringCommand. propertyInfo: " + propertyInfo.GetExtendedMemberInfoString());

            string commandText = this.commandTextGenerator.WriteString(propertyInfo);

            this.writePrimitives.AddSqlCommand(commandText);

            SqlWriterDictionary.Logger.Debug("Exiting WriteStringCommand");

            return this.DecodeString;
        }
コード例 #8
0
        private LargeInteger DecodeString(PropertyInfo propertyInfo, object input)
        {
            SqlWriterDictionary.Logger.Debug($"Entering DecodeString. propertyInfo: {propertyInfo.GetExtendedMemberInfoString()}, input: {input}");

            if (input is DBNull)
            {
                SqlWriterDictionary.Logger.Debug("input is DBNull");
                return 0;
            }

            if (input.GetType() != typeof(string))
            {
                throw new UnexpectedTypeException(string.Format(Messages.UnexpectedHandlerType, propertyInfo, input));
            }

            LargeInteger result = this.encoder.Decode(((string)input).ToUpper());

            SqlWriterDictionary.Logger.Debug("Exiting DecodeString");

            return result;
        }
コード例 #9
0
        private static LargeInteger DecodeNumber(PropertyInfo propertyInfo, object input)
        {
            SqlWriterDictionary.Logger.Debug($"Entering DecodeNumber. propertyInfo: {propertyInfo.GetExtendedMemberInfoString()}, input: {input}");

            if (input is DBNull)
            {
                SqlWriterDictionary.Logger.Debug("input is DBNull");
                return 0;
            }

            if (
                !new[] { typeof(byte), typeof(int), typeof(short), typeof(long) }.Contains(input.GetType()))
            {
                throw new UnexpectedTypeException(string.Format(Messages.UnexpectedHandlerType, propertyInfo.GetExtendedMemberInfoString(), input));
            }

            LargeInteger result = (ulong)Convert.ChangeType(input, typeof(ulong));

            SqlWriterDictionary.Logger.Debug("Exiting DecodeNumber");

            return result;
        }