Exemplo n.º 1
0
        private void CreateAnonymous(RangedNumberRequest range, IComparable value)
        {
            lock (this.syncRoot)
            {
                var minimum = (IComparable)range.Minimum;
                var maximum = (IComparable)range.Maximum;

                if (this.rangedValue != null)
                {
                    this.rangedValue = Convert.ChangeType(this.rangedValue, range.OperandType, CultureInfo.CurrentCulture);
                }

                if (this.rangedValue != null && (minimum.CompareTo(this.rangedValue) <= 0 && maximum.CompareTo(this.rangedValue) > 0))
                {
                    this.rangedValue = RangedNumberGenerator.Add(this.rangedValue, Convert.ChangeType(1, range.OperandType, CultureInfo.CurrentCulture));
                }
                else if (minimum.CompareTo(value) == 0)
                {
                    this.rangedValue = minimum;
                }
                else if (maximum.CompareTo(value) == 0)
                {
                    this.rangedValue = maximum;
                }
                else if (minimum.CompareTo(value) <= 0 && maximum.CompareTo(value) <= 0)
                {
                    this.rangedValue = minimum;
                }
                else if (minimum.CompareTo(this.rangedValue) <= 0 && maximum.CompareTo(this.rangedValue) <= 0)
                {
                    this.rangedValue = minimum;
                }
                else
                {
                    this.rangedValue = RangedNumberGenerator.Add(minimum, value);
                }
            }
        }
Exemplo n.º 2
0
        private void CreateAnonymous(RangedNumberRequest range, IComparable value)
        {
            lock (this.syncRoot)
            {
                var minimum = (IComparable)range.Minimum;
                var maximum = (IComparable)range.Maximum;

                if (this.rangedValue != null)
                {
                    object target;
                    if (range.OperandType == typeof(byte) &&
                        Convert.ToInt32(
                            this.rangedValue,
                            CultureInfo.CurrentCulture) > byte.MaxValue ||
                        range.OperandType == typeof(short) &&
                        Convert.ToInt32(
                            this.rangedValue,
                            CultureInfo.CurrentCulture) > short.MaxValue)
                    {
                        target = minimum;
                    }
                    else
                    {
                        target = this.rangedValue;
                    }

                    this.rangedValue = Convert.ChangeType(target, range.OperandType, CultureInfo.CurrentCulture);
                }

                if (this.rangedValue != null && (minimum.CompareTo(this.rangedValue) <= 0 && maximum.CompareTo(this.rangedValue) > 0))
                {
                    this.rangedValue =
                        Convert.ChangeType(
                            RangedNumberGenerator.Add(
                                this.rangedValue,
                                Convert.ChangeType(
                                    1,
                                    range.OperandType,
                                    CultureInfo.CurrentCulture)),
                            range.OperandType,
                            CultureInfo.CurrentCulture);

                    if (maximum.CompareTo(this.rangedValue) < 0)
                    {
                        this.rangedValue = Convert.ChangeType(
                            maximum,
                            range.OperandType,
                            CultureInfo.CurrentCulture);
                    }
                }
                else if (minimum.CompareTo(value) == 0)
                {
                    this.rangedValue = minimum;
                }
                else if (maximum.CompareTo(value) == 0)
                {
                    this.rangedValue = maximum;
                }
                else if (minimum.CompareTo(value) <= 0 && maximum.CompareTo(value) <= 0)
                {
                    this.rangedValue = minimum;
                }
                else if (minimum.CompareTo(this.rangedValue) <= 0 && maximum.CompareTo(this.rangedValue) <= 0)
                {
                    this.rangedValue = minimum;
                }
                else if (minimum.CompareTo(value) < 0)
                {
                    this.rangedValue = value;
                }
                else
                {
                    this.rangedValue = RangedNumberGenerator.Add(minimum, value);

                    if (minimum.CompareTo(this.rangedValue) > 0 ||
                        maximum.CompareTo(this.rangedValue) < 0)
                    {
                        this.rangedValue = minimum;
                    }
                }

                this.rangedValue = Convert.ChangeType(this.rangedValue, range.OperandType, CultureInfo.CurrentCulture);
            }
        }