public override bool TryCreateStep(object value, out ValueGenerator.Step step)
            {
                if (value is sbyte)
                {
                    step = new ComparableStep <sbyte>((sbyte)value, (prev, stepValue) => checked ((sbyte)(prev + stepValue)));
                    return(true);
                }

                return(base.TryCreateStep(value, out step));
            }
Beispiel #2
0
            public override bool TryCreateStep(object value, out ValueGenerator.Step step)
            {
                if (value is uint)
                {
                    step = new ComparableStep <uint>((uint)value, (prev, stepValue) => checked (prev + stepValue));
                    return(true);
                }

                if (value is int)
                {
                    step = new ComparableStep <int>((int)value, (prev, stepValue) => checked ((uint)(prev + stepValue)));
                    return(true);
                }

                return(base.TryCreateStep(value, out step));
            }
            public override bool TryCreateStep(object value, out ValueGenerator.Step step)
            {
                if (value is ulong uValue)
                {
                    step = new ComparableStep <ulong>(uValue, (prev, stepValue) => checked (prev + stepValue));
                    return(true);
                }

                if (value is int iValue)
                {
                    step = new ComparableStep <int>(iValue, (prev, stepValue) => checked (prev + (ulong)stepValue));
                    return(true);
                }

                return(base.TryCreateStep(value, out step));
            }
Beispiel #4
0
            public override bool TryCreateStep(object value, out ValueGenerator.Step step)
            {
                if (value is float)
                {
                    step = new ComparableStep <float>((float)value, (prev, stepValue) =>
                    {
                        var next = prev + stepValue;
                        if (stepValue > 0 ? next <= prev : prev <= next)
                        {
                            throw new ArithmeticException($"Not enough precision to represent the next step; {prev:r} + {stepValue:r} = {next:r}.");
                        }
                        return(next);
                    });
                    return(true);
                }

                return(base.TryCreateStep(value, out step));
            }
Beispiel #5
0
            public override bool TryCreateStep(object value, out ValueGenerator.Step step)
            {
                if (value is byte)
                {
                    step = new ComparableStep <byte>((byte)value, (prev, stepValue) => checked ((byte)(prev + stepValue)));
                    return(true);
                }

                // ByteValueGenerator is unusual in this regard. We allow byte parameter ranges to start high and end low,
                // and internally the step is represented as the Int32 value -1 since it can’t be represented as a Byte.
                // -1 can be converted natively to Int16, SByte and Decimal, so we can fall back on the automatic conversion for them.
                if (value is int)
                {
                    step = new ComparableStep <int>((int)value, (prev, stepValue) => checked ((byte)(prev + stepValue)));
                    return(true);
                }

                return(base.TryCreateStep(value, out step));
            }