<PackageReference Include="NUnit" Version="4.3.2" />

ValueGenerator

abstract class ValueGenerator
using System; using System.Collections; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal { internal abstract class ValueGenerator { private sealed class ByteValueGenerator : ValueGenerator<byte> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { checked { if (value is byte) { byte value2 = (byte)value; step = new ComparableStep<byte>(value2, (byte prev, byte stepValue) => (byte)(unchecked((int)prev) + unchecked((int)stepValue))); return true; } if (value is int) { int value3 = (int)value; step = new ComparableStep<int>(value3, (byte prev, int stepValue) => (byte)(unchecked((int)prev) + stepValue)); return true; } return base.TryCreateStep(value, out step); } } } public abstract class Step { public abstract bool IsPositive { get; } public abstract bool IsNegative { get; } } private sealed class DecimalValueGenerator : ValueGenerator<decimal> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is decimal) { decimal value2 = (decimal)value; step = new ComparableStep<decimal>(value2, delegate(decimal prev, decimal stepValue) { decimal num = prev + stepValue; if ((stepValue > decimal.Zero) ? (num <= prev) : (prev <= num)) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(56, 3); defaultInterpolatedStringHandler.AppendLiteral("Not enough precision to represent the next step; "); defaultInterpolatedStringHandler.AppendFormatted(prev); defaultInterpolatedStringHandler.AppendLiteral(" + "); defaultInterpolatedStringHandler.AppendFormatted(stepValue); defaultInterpolatedStringHandler.AppendLiteral(" = "); defaultInterpolatedStringHandler.AppendFormatted(num); defaultInterpolatedStringHandler.AppendLiteral("."); throw new ArithmeticException(defaultInterpolatedStringHandler.ToStringAndClear()); } return num; }); return true; } return base.TryCreateStep(value, out step); } } [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] private sealed class DefaultValueGenerator<T> : ValueGenerator<T> { } private sealed class DoubleValueGenerator : ValueGenerator<double> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is double) { double value2 = (double)value; step = new ComparableStep<double>(value2, delegate(double prev, double stepValue) { double num = prev + stepValue; if ((stepValue > 0) ? (num <= prev) : (prev <= num)) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(56, 3); defaultInterpolatedStringHandler.AppendLiteral("Not enough precision to represent the next step; "); defaultInterpolatedStringHandler.AppendFormatted(prev, "r"); defaultInterpolatedStringHandler.AppendLiteral(" + "); defaultInterpolatedStringHandler.AppendFormatted(stepValue, "r"); defaultInterpolatedStringHandler.AppendLiteral(" = "); defaultInterpolatedStringHandler.AppendFormatted(num, "r"); defaultInterpolatedStringHandler.AppendLiteral("."); throw new ArithmeticException(defaultInterpolatedStringHandler.ToStringAndClear()); } return num; }); return true; } return base.TryCreateStep(value, out step); } } private sealed class Int16ValueGenerator : ValueGenerator<short> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is short) { short value2 = (short)value; step = new ComparableStep<short>(value2, (short prev, short stepValue) => checked((short)(prev + stepValue))); return true; } return base.TryCreateStep(value, out step); } } private sealed class Int32ValueGenerator : ValueGenerator<int> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is int) { int value2 = (int)value; step = new ComparableStep<int>(value2, (int prev, int stepValue) => checked(prev + stepValue)); return true; } return base.TryCreateStep(value, out step); } } private sealed class Int64ValueGenerator : ValueGenerator<long> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is long) { long value2 = (long)value; step = new ComparableStep<long>(value2, (long prev, long stepValue) => checked(prev + stepValue)); return true; } return base.TryCreateStep(value, out step); } } private sealed class SByteValueGenerator : ValueGenerator<sbyte> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is sbyte) { sbyte value2 = (sbyte)value; step = new ComparableStep<sbyte>(value2, (sbyte prev, sbyte stepValue) => checked((sbyte)(prev + stepValue))); return true; } return base.TryCreateStep(value, out step); } } private sealed class SingleValueGenerator : ValueGenerator<float> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { if (value is float) { float value2 = (float)value; step = new ComparableStep<float>(value2, delegate(float prev, float stepValue) { float num = prev + stepValue; if ((stepValue > 0) ? (num <= prev) : (prev <= num)) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(56, 3); defaultInterpolatedStringHandler.AppendLiteral("Not enough precision to represent the next step; "); defaultInterpolatedStringHandler.AppendFormatted(prev, "r"); defaultInterpolatedStringHandler.AppendLiteral(" + "); defaultInterpolatedStringHandler.AppendFormatted(stepValue, "r"); defaultInterpolatedStringHandler.AppendLiteral(" = "); defaultInterpolatedStringHandler.AppendFormatted(num, "r"); defaultInterpolatedStringHandler.AppendLiteral("."); throw new ArithmeticException(defaultInterpolatedStringHandler.ToStringAndClear()); } return num; }); return true; } return base.TryCreateStep(value, out step); } } private sealed class UInt16ValueGenerator : ValueGenerator<ushort> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { checked { if (value is ushort) { ushort value2 = (ushort)value; step = new ComparableStep<ushort>(value2, (ushort prev, ushort stepValue) => (ushort)(unchecked((int)prev) + unchecked((int)stepValue))); return true; } if (value is int) { int value3 = (int)value; step = new ComparableStep<int>(value3, (ushort prev, int stepValue) => (ushort)(unchecked((int)prev) + stepValue)); return true; } return base.TryCreateStep(value, out step); } } } private sealed class UInt32ValueGenerator : ValueGenerator<uint> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { checked { if (value is uint) { uint value2 = (uint)value; step = new ComparableStep<uint>(value2, (uint prev, uint stepValue) => prev + stepValue); return true; } if (value is int) { int value3 = (int)value; step = new ComparableStep<int>(value3, (uint prev, int stepValue) => (uint)(unchecked((long)prev) + unchecked((long)stepValue))); return true; } return base.TryCreateStep(value, out step); } } } private sealed class UInt64ValueGenerator : ValueGenerator<ulong> { [System.Runtime.CompilerServices.NullableContext(1)] public override bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out ValueGenerator.Step step) { checked { if (value is ulong) { ulong value2 = (ulong)value; step = new ComparableStep<ulong>(value2, (ulong prev, ulong stepValue) => prev + stepValue); return true; } if (value is int) { int value3 = (int)value; step = new ComparableStep<int>(value3, (ulong prev, int stepValue) => prev + (ulong)stepValue); return true; } return base.TryCreateStep(value, out step); } } } [System.Runtime.CompilerServices.Nullable(1)] private static readonly MethodInfo GenericCreateMethod = typeof(ValueGenerator).GetMethods(BindingFlags.Static | BindingFlags.Public).Single(delegate(MethodInfo method) { if (method.Name == "Create") return method.IsGenericMethod; return false; }); [System.Runtime.CompilerServices.NullableContext(1)] public abstract IEnumerable GenerateRange(object start, object end, Step step); [System.Runtime.CompilerServices.NullableContext(1)] public static ValueGenerator Create(Type valueType) { MethodInfo methodInfo = GenericCreateMethod.MakeGenericMethod(valueType); Func<ValueGenerator> func = (Func<ValueGenerator>)methodInfo.CreateDelegate(typeof(Func<ValueGenerator>)); return func(); } [System.Runtime.CompilerServices.NullableContext(1)] public static ValueGenerator<T> Create<[System.Runtime.CompilerServices.Nullable(2)] T>() { if (typeof(T) == typeof(sbyte)) return (ValueGenerator<T>)new SByteValueGenerator(); if (typeof(T) == typeof(byte)) return (ValueGenerator<T>)new ByteValueGenerator(); if (typeof(T) == typeof(short)) return (ValueGenerator<T>)new Int16ValueGenerator(); if (typeof(T) == typeof(ushort)) return (ValueGenerator<T>)new UInt16ValueGenerator(); if (typeof(T) == typeof(int)) return (ValueGenerator<T>)new Int32ValueGenerator(); if (typeof(T) == typeof(uint)) return (ValueGenerator<T>)new UInt32ValueGenerator(); if (typeof(T) == typeof(long)) return (ValueGenerator<T>)new Int64ValueGenerator(); if (typeof(T) == typeof(ulong)) return (ValueGenerator<T>)new UInt64ValueGenerator(); if (typeof(T) == typeof(float)) return (ValueGenerator<T>)new SingleValueGenerator(); if (typeof(T) == typeof(double)) return (ValueGenerator<T>)new DoubleValueGenerator(); if (typeof(T) == typeof(decimal)) return (ValueGenerator<T>)new DecimalValueGenerator(); return new DefaultValueGenerator<T>(); } [System.Runtime.CompilerServices.NullableContext(1)] public abstract Step CreateStep(object value); [System.Runtime.CompilerServices.NullableContext(1)] public abstract bool TryCreateStep(object value, [System.Runtime.CompilerServices.Nullable(2)] [NotNullWhen(true)] out Step step); } }