Skip to content

Commit

Permalink
Fix spacing around square brackets.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Jan 14, 2024
1 parent db551d4 commit 43a25e0
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 96 deletions.
4 changes: 2 additions & 2 deletions src/MySqlConnector/Core/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
if (csb.LoadBalance != MySqlLoadBalance.RoundRobin)
throw new NotSupportedException("LoadBalance not supported when ConnectionProtocol=NamedPipe");
ConnectionProtocol = MySqlConnectionProtocol.NamedPipe;
HostNames = (csb.Server == "." || string.Equals(csb.Server, "localhost", StringComparison.OrdinalIgnoreCase)) ? s_localhostPipeServer : [ csb.Server ];
HostNames = (csb.Server == "." || string.Equals(csb.Server, "localhost", StringComparison.OrdinalIgnoreCase)) ? s_localhostPipeServer : [csb.Server];
PipeName = csb.PipeName;
}
else if (csb.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory)
Expand Down Expand Up @@ -272,7 +272,7 @@ private ConnectionSettings(ConnectionSettings other, string host, int port, stri
ConnectionString = other.ConnectionString;

ConnectionProtocol = MySqlConnectionProtocol.Sockets;
HostNames = [ host ];
HostNames = [host];
LoadBalance = other.LoadBalance;
Port = port;
PipeName = other.PipeName;
Expand Down
4 changes: 2 additions & 2 deletions src/MySqlConnector/Core/ServerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public ServerVersion(ReadOnlySpan<byte> versionString)
if (Utf8Parser.TryParse(versionString, out int major, out var bytesConsumed))
{
versionString = versionString[bytesConsumed..];
if (versionString is [ 0x2E, .. ])
if (versionString is [0x2E, ..])
{
versionString = versionString[1..];
if (Utf8Parser.TryParse(versionString, out minor, out bytesConsumed))
{
versionString = versionString[bytesConsumed..];
if (versionString is [ 0x2E, .. ])
if (versionString is [0x2E, ..])
{
versionString = versionString[1..];
if (Utf8Parser.TryParse(versionString, out build, out bytesConsumed))
Expand Down
46 changes: 23 additions & 23 deletions src/MySqlConnector/Core/TypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ private TypeMapper()
m_mySqlDbTypeToColumnTypeMetadata = [];

// boolean
var typeBoolean = AddDbTypeMapping(new(typeof(bool), [ DbType.Boolean ], convert: static o => Convert.ToBoolean(o, CultureInfo.InvariantCulture)));
var typeBoolean = AddDbTypeMapping(new(typeof(bool), [DbType.Boolean], convert: static o => Convert.ToBoolean(o, CultureInfo.InvariantCulture)));
AddColumnTypeMetadata(new("TINYINT", typeBoolean, MySqlDbType.Bool, isUnsigned: false, length: 1, columnSize: 1, simpleDataTypeName: "BOOL", createFormat: "BOOL"));

// integers
var typeSbyte = AddDbTypeMapping(new(typeof(sbyte), [ DbType.SByte ], convert: static o => Convert.ToSByte(o, CultureInfo.InvariantCulture)));
var typeByte = AddDbTypeMapping(new(typeof(byte), [ DbType.Byte ], convert: static o => Convert.ToByte(o, CultureInfo.InvariantCulture)));
var typeShort = AddDbTypeMapping(new(typeof(short), [ DbType.Int16 ], convert: static o => Convert.ToInt16(o, CultureInfo.InvariantCulture)));
var typeUshort = AddDbTypeMapping(new(typeof(ushort), [ DbType.UInt16 ], convert: static o => Convert.ToUInt16(o, CultureInfo.InvariantCulture)));
var typeInt = AddDbTypeMapping(new(typeof(int), [ DbType.Int32 ], convert: static o => Convert.ToInt32(o, CultureInfo.InvariantCulture)));
var typeUint = AddDbTypeMapping(new(typeof(uint), [ DbType.UInt32 ], convert: static o => Convert.ToUInt32(o, CultureInfo.InvariantCulture)));
var typeLong = AddDbTypeMapping(new(typeof(long), [ DbType.Int64 ], convert: static o => Convert.ToInt64(o, CultureInfo.InvariantCulture)));
var typeUlong = AddDbTypeMapping(new(typeof(ulong), [ DbType.UInt64 ], convert: static o => Convert.ToUInt64(o, CultureInfo.InvariantCulture)));
var typeSbyte = AddDbTypeMapping(new(typeof(sbyte), [DbType.SByte], convert: static o => Convert.ToSByte(o, CultureInfo.InvariantCulture)));
var typeByte = AddDbTypeMapping(new(typeof(byte), [DbType.Byte], convert: static o => Convert.ToByte(o, CultureInfo.InvariantCulture)));
var typeShort = AddDbTypeMapping(new(typeof(short), [DbType.Int16], convert: static o => Convert.ToInt16(o, CultureInfo.InvariantCulture)));
var typeUshort = AddDbTypeMapping(new(typeof(ushort), [DbType.UInt16], convert: static o => Convert.ToUInt16(o, CultureInfo.InvariantCulture)));
var typeInt = AddDbTypeMapping(new(typeof(int), [DbType.Int32], convert: static o => Convert.ToInt32(o, CultureInfo.InvariantCulture)));
var typeUint = AddDbTypeMapping(new(typeof(uint), [DbType.UInt32], convert: static o => Convert.ToUInt32(o, CultureInfo.InvariantCulture)));
var typeLong = AddDbTypeMapping(new(typeof(long), [DbType.Int64], convert: static o => Convert.ToInt64(o, CultureInfo.InvariantCulture)));
var typeUlong = AddDbTypeMapping(new(typeof(ulong), [DbType.UInt64], convert: static o => Convert.ToUInt64(o, CultureInfo.InvariantCulture)));
AddColumnTypeMetadata(new("TINYINT", typeSbyte, MySqlDbType.Byte, isUnsigned: false));
AddColumnTypeMetadata(new("TINYINT", typeByte, MySqlDbType.UByte, isUnsigned: true, length: 1));
AddColumnTypeMetadata(new("TINYINT", typeByte, MySqlDbType.UByte, isUnsigned: true));
Expand All @@ -46,18 +46,18 @@ private TypeMapper()
AddColumnTypeMetadata(new("BIT", typeUlong, MySqlDbType.Bit));

// decimals
var typeDecimal = AddDbTypeMapping(new(typeof(decimal), [ DbType.Decimal, DbType.Currency, DbType.VarNumeric ], convert: static o => Convert.ToDecimal(o, CultureInfo.InvariantCulture)));
var typeDouble = AddDbTypeMapping(new(typeof(double), [ DbType.Double ], convert: static o => Convert.ToDouble(o, CultureInfo.InvariantCulture)));
var typeFloat = AddDbTypeMapping(new(typeof(float), [ DbType.Single ], convert: static o => Convert.ToSingle(o, CultureInfo.InvariantCulture)));
var typeDecimal = AddDbTypeMapping(new(typeof(decimal), [DbType.Decimal, DbType.Currency, DbType.VarNumeric], convert: static o => Convert.ToDecimal(o, CultureInfo.InvariantCulture)));
var typeDouble = AddDbTypeMapping(new(typeof(double), [DbType.Double], convert: static o => Convert.ToDouble(o, CultureInfo.InvariantCulture)));
var typeFloat = AddDbTypeMapping(new(typeof(float), [DbType.Single], convert: static o => Convert.ToSingle(o, CultureInfo.InvariantCulture)));
AddColumnTypeMetadata(new("DECIMAL", typeDecimal, MySqlDbType.NewDecimal, createFormat: "DECIMAL({0},{1});precision,scale"));
AddColumnTypeMetadata(new("DECIMAL", typeDecimal, MySqlDbType.NewDecimal, isUnsigned: true, createFormat: "DECIMAL({0},{1}) UNSIGNED;precision,scale"));
AddColumnTypeMetadata(new("DECIMAL", typeDecimal, MySqlDbType.Decimal));
AddColumnTypeMetadata(new("DOUBLE", typeDouble, MySqlDbType.Double));
AddColumnTypeMetadata(new("FLOAT", typeFloat, MySqlDbType.Float));

// string
var typeFixedString = AddDbTypeMapping(new(typeof(string), [ DbType.StringFixedLength, DbType.AnsiStringFixedLength ], convert: Convert.ToString!));
var typeString = AddDbTypeMapping(new(typeof(string), [ DbType.String, DbType.AnsiString, DbType.Xml ], convert: Convert.ToString!));
var typeFixedString = AddDbTypeMapping(new(typeof(string), [DbType.StringFixedLength, DbType.AnsiStringFixedLength], convert: Convert.ToString!));
var typeString = AddDbTypeMapping(new(typeof(string), [DbType.String, DbType.AnsiString, DbType.Xml], convert: Convert.ToString!));
AddColumnTypeMetadata(new("VARCHAR", typeString, MySqlDbType.VarChar, createFormat: "VARCHAR({0});size"));
AddColumnTypeMetadata(new("VARCHAR", typeString, MySqlDbType.VarString));
AddColumnTypeMetadata(new("CHAR", typeFixedString, MySqlDbType.String, createFormat: "CHAR({0});size"));
Expand All @@ -70,7 +70,7 @@ private TypeMapper()
AddColumnTypeMetadata(new("JSON", typeString, MySqlDbType.JSON));

// binary
var typeBinary = AddDbTypeMapping(new(typeof(byte[]), [ DbType.Binary ]));
var typeBinary = AddDbTypeMapping(new(typeof(byte[]), [DbType.Binary]));
AddColumnTypeMetadata(new("BLOB", typeBinary, MySqlDbType.Blob, binary: true, columnSize: ushort.MaxValue, simpleDataTypeName: "BLOB"));
AddColumnTypeMetadata(new("BINARY", typeBinary, MySqlDbType.Binary, binary: true, simpleDataTypeName: "BLOB", createFormat: "BINARY({0});length"));
AddColumnTypeMetadata(new("VARBINARY", typeBinary, MySqlDbType.VarBinary, binary: true, simpleDataTypeName: "BLOB", createFormat: "VARBINARY({0});length"));
Expand All @@ -91,15 +91,15 @@ private TypeMapper()

// date/time
#if NET6_0_OR_GREATER
AddDbTypeMapping(new(typeof(DateOnly), [ DbType.Date ]));
AddDbTypeMapping(new(typeof(DateOnly), [DbType.Date]));
#endif
var typeDate = AddDbTypeMapping(new(typeof(DateTime), [ DbType.Date ]));
var typeDateTime = AddDbTypeMapping(new(typeof(DateTime), [ DbType.DateTime, DbType.DateTime2, DbType.DateTimeOffset ]));
AddDbTypeMapping(new(typeof(DateTimeOffset), [ DbType.DateTimeOffset ]));
var typeDate = AddDbTypeMapping(new(typeof(DateTime), [DbType.Date]));
var typeDateTime = AddDbTypeMapping(new(typeof(DateTime), [DbType.DateTime, DbType.DateTime2, DbType.DateTimeOffset]));
AddDbTypeMapping(new(typeof(DateTimeOffset), [DbType.DateTimeOffset]));
#if NET6_0_OR_GREATER
AddDbTypeMapping(new(typeof(TimeOnly), [ DbType.Time ]));
AddDbTypeMapping(new(typeof(TimeOnly), [DbType.Time]));
#endif
var typeTime = AddDbTypeMapping(new(typeof(TimeSpan), [ DbType.Time ], convert: static o => o is string s ? Utility.ParseTimeSpan(Encoding.UTF8.GetBytes(s)) : Convert.ChangeType(o, typeof(TimeSpan), CultureInfo.InvariantCulture)));
var typeTime = AddDbTypeMapping(new(typeof(TimeSpan), [DbType.Time], convert: static o => o is string s ? Utility.ParseTimeSpan(Encoding.UTF8.GetBytes(s)) : Convert.ChangeType(o, typeof(TimeSpan), CultureInfo.InvariantCulture)));
AddColumnTypeMetadata(new("DATETIME", typeDateTime, MySqlDbType.DateTime));
AddColumnTypeMetadata(new("DATE", typeDate, MySqlDbType.Date));
AddColumnTypeMetadata(new("DATE", typeDate, MySqlDbType.Newdate));
Expand All @@ -113,11 +113,11 @@ private TypeMapper()
#else
Func<object, object> convertGuid = static o => Guid.Parse(Convert.ToString(o, CultureInfo.InvariantCulture)!);
#endif
var typeGuid = AddDbTypeMapping(new(typeof(Guid), [ DbType.Guid ], convert: convertGuid));
var typeGuid = AddDbTypeMapping(new(typeof(Guid), [DbType.Guid], convert: convertGuid));
AddColumnTypeMetadata(new("CHAR", typeGuid, MySqlDbType.Guid, length: 36, simpleDataTypeName: "CHAR(36)", createFormat: "CHAR(36)"));

// null
var typeNull = AddDbTypeMapping(new(typeof(object), [ DbType.Object ]));
var typeNull = AddDbTypeMapping(new(typeof(object), [DbType.Object]));
AddColumnTypeMetadata(new("NULL", typeNull, MySqlDbType.Null));
}

Expand Down
2 changes: 1 addition & 1 deletion src/MySqlConnector/MySqlBulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static bool WriteBytes(ReadOnlySpan<byte> value, ref int inputIndex, Span<byte>
}
}

private static readonly char[] s_specialCharacters = [ '\t', '\\', '\n' ];
private static readonly char[] s_specialCharacters = ['\t', '\\', '\n'];
private static readonly UTF8Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

private readonly MySqlConnection m_connection;
Expand Down
2 changes: 1 addition & 1 deletion src/MySqlConnector/MySqlCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override void SetRowUpdatingHandler(DbDataAdapter adapter)

public override string UnquoteIdentifier(string quotedIdentifier)
{
if (quotedIdentifier is [ '`', .., '`' ])
if (quotedIdentifier is ['`', .., '`'])
quotedIdentifier = quotedIdentifier[1..^1];
return quotedIdentifier.Replace("``", "`");
}
Expand Down
Loading

0 comments on commit 43a25e0

Please sign in to comment.