private void Test(Random r, CtpTypeCode code) { var list = new List <CtpObject>(); for (int x = 0; x < 1000; x++) { list.Add(CreateRandom(r, code)); } Test(list); }
public static Type ToType(CtpTypeCode columnTypeCode) { switch (columnTypeCode) { case CtpTypeCode.Null: return(typeof(DBNull)); case CtpTypeCode.Integer: return(typeof(Int64)); case CtpTypeCode.Single: return(typeof(Single)); case CtpTypeCode.Double: return(typeof(Double)); case CtpTypeCode.Numeric: return(typeof(CtpNumeric)); case CtpTypeCode.CtpTime: return(typeof(CtpTime)); case CtpTypeCode.Boolean: return(typeof(Boolean)); case CtpTypeCode.Guid: return(typeof(Guid)); case CtpTypeCode.String: return(typeof(String)); case CtpTypeCode.CtpBuffer: return(typeof(byte[])); case CtpTypeCode.CtpCommand: return(typeof(byte[])); default: throw new ArgumentOutOfRangeException(nameof(columnTypeCode), columnTypeCode, null); } }
public static CtpObject CreateDefault(CtpTypeCode typeCode) { switch (typeCode) { case CtpTypeCode.Null: return(CtpObject.Null); case CtpTypeCode.Integer: return(new CtpObject(0)); case CtpTypeCode.Single: return(new CtpObject(0f)); case CtpTypeCode.Double: return(new CtpObject(0d)); case CtpTypeCode.Numeric: return(new CtpObject(default(CtpNumeric))); case CtpTypeCode.CtpTime: return(new CtpTime(0)); case CtpTypeCode.Boolean: return(new CtpObject(false)); case CtpTypeCode.Guid: return(new CtpObject(Guid.Empty)); case CtpTypeCode.String: return(new CtpObject(string.Empty)); case CtpTypeCode.CtpBuffer: return(new CtpObject(CtpBuffer.Empty)); case CtpTypeCode.CtpCommand: throw new NotSupportedException(); default: throw new ArgumentOutOfRangeException(nameof(typeCode), typeCode, null); } }
private void ThrowHelper(CtpTypeCode code) { throw new InvalidOperationException($"The internal value is {ValueTypeCode}, not {code}"); }
private CtpObject CreateRandom(Random r, CtpTypeCode typeCode) { byte[] buffer = new byte[8]; r.NextBytes(buffer); switch (typeCode) { case CtpTypeCode.Null: return(CtpObject.Null); case CtpTypeCode.Integer: switch (r.Next(100)) { case 0: return(-1); case 1: return(-2); case 2: return(0); case 3: return(1); case 4: return(99); case 5: return(100); case 6: return(101); case 7: return(sbyte.MaxValue); case 8: return(sbyte.MinValue); case 9: return(byte.MaxValue); case 10: return(byte.MinValue); case 11: return(short.MaxValue); case 12: return(short.MinValue); case 13: return(ushort.MaxValue); case 14: return(ushort.MinValue); case 15: return(int.MaxValue); case 16: return(int.MinValue); case 17: return(uint.MaxValue); case 18: return(uint.MinValue); case 19: return(long.MaxValue); case 20: return(long.MinValue); case 21: return(ulong.MaxValue); case 22: return(ulong.MinValue); default: return(BigEndian.ToInt64(buffer, 0) >> r.Next(64)); } case CtpTypeCode.Single: switch (r.Next(100)) { case 0: return(-1f); case 1: return(0f); case 2: return(1f); case 3: return(float.NaN); case 4: return(float.MaxValue); case 5: return(float.MinValue); case 6: return(float.Epsilon); case 7: return(float.PositiveInfinity); case 8: return(float.NegativeInfinity); default: return(BigEndian.ToSingle(buffer, 0)); } case CtpTypeCode.Double: switch (r.Next(100)) { case 0: return(-1.0); case 1: return(0.0); case 2: return(1.0); case 3: return(double.NaN); case 4: return(double.MaxValue); case 5: return(double.MinValue); case 6: return(double.Epsilon); case 7: return(double.PositiveInfinity); case 8: return(double.NegativeInfinity); default: return(BigEndian.ToDouble(buffer, 0)); } case CtpTypeCode.Numeric: switch (r.Next(100)) { case 0: return(decimal.MinusOne); case 1: return(decimal.Zero); case 2: return(decimal.One); case 3: return(decimal.MaxValue); case 4: return(decimal.MinValue); default: { uint high = BigEndian.ToUInt32(buffer, 0); uint mid = BigEndian.ToUInt32(buffer, 2); uint low = BigEndian.ToUInt32(buffer, 4); int shift = r.Next(97); if (shift >= 32) { high = 0; shift = -32; if (shift >= 32) { mid = 0; shift = -32; low >>= shift; } else { mid >>= shift; } } else { high >>= shift; } return(new decimal((int)low, (int)mid, (int)high, r.Next(2) == 0, (byte)r.Next(29))); } } case CtpTypeCode.CtpTime: switch (r.Next(100)) { case 0: return(CtpTime.MaxValue); case 1: return(CtpTime.MinValue); case 2: return(new CtpTime(0)); default: return(new CtpTime(DateTime.FromBinary(Math.Min(DateTime.MaxValue.Ticks, Math.Max(0, BigEndian.ToInt64(buffer, 0)))))); } case CtpTypeCode.Boolean: return((buffer[0] & 1) == 1); case CtpTypeCode.Guid: return((buffer[0] % 30 == 0) ? Guid.Empty : Guid.NewGuid()); case CtpTypeCode.String: { var bytes = (byte[])CreateRandom(r, CtpTypeCode.CtpBuffer); return(Encoding.Unicode.GetString(bytes)); } case CtpTypeCode.CtpBuffer: { var data = new byte[buffer[0]]; r.NextBytes(data); return(CtpBuffer.DoNotClone(data)); } case CtpTypeCode.CtpCommand: return(new CtpError(CreateRandom(r, CtpTypeCode.String).AsString, CreateRandom(r, CtpTypeCode.String).AsString).ToCommand()); default: throw new ArgumentOutOfRangeException(nameof(typeCode), typeCode, null); } }
public MetadataColumn(string name, CtpTypeCode typeCode) { TypeCode = typeCode; Name = name; }