Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1707,9 +1707,9 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
case TdsEnums.SQLJSON:
// Could be either string, SqlCachedBuffer, XmlReader or XmlDataFeed
Debug.Assert((value is XmlReader) || (value is SqlCachedBuffer) || (value is string) || (value is SqlString) || (value is XmlDataFeed), "Invalid value type of Xml datatype");
if (value is XmlReader)
if (value is XmlReader xmlReader)
{
value = new XmlDataFeed((XmlReader)value);
value = new XmlDataFeed(xmlReader);
typeChanged = true;
coercedToDataFeed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,7 @@ and not SqlDbType.Udt
s = val as string;
if (s is null)
{
SqlString sval = val is SqlString ? (SqlString)val : SqlString.Null;
SqlString sval = val is SqlString sqlVal ? sqlVal : SqlString.Null;
if (!sval.IsNull)
{
s = sval.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,9 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
{
throw ADP.ArgumentNull(nameof(destinationType));
}
if (typeof(InstanceDescriptor) == destinationType)
if (destinationType == typeof(InstanceDescriptor) && value is SqlConnectionStringBuilder obj)
{
SqlConnectionStringBuilder obj = (value as SqlConnectionStringBuilder);
if (obj is not null)
{
return ConvertToInstanceDescriptor(obj);
}
return ConvertToInstanceDescriptor(obj);
}
return base.ConvertTo(context, culture, value, destinationType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
{
throw ADP.ArgumentNull(nameof(destinationType));
}
if ((typeof(InstanceDescriptor) == destinationType) && (value is SqlParameter))
if (destinationType == typeof(InstanceDescriptor) && value is SqlParameter parameter)
{
return ConvertToInstanceDescriptor(value as SqlParameter);
return ConvertToInstanceDescriptor(parameter);
}
return base.ConvertTo(context, culture, value, destinationType);
}
Expand Down Expand Up @@ -1951,9 +1951,9 @@ private MetaType GetMetaTypeOnly()
_value = _value.ToString();
valueType = typeof(string);
}
else if (valueType == typeof(char[]))
else if (_value is char[] chars)
{
_value = new string((char[])_value);
_value = new string(chars);
valueType = typeof(string);
}
return MetaType.GetMetaTypeFromType(valueType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1909,9 +1909,8 @@ internal static Exception GetExceptionArray(string serverName, string errorMessa
Exception exceptionToInclude = e.InnerException != null ? e.InnerException : e;
sqlErs.Add(new SqlError(infoNumber: 0, errorState: (byte)0x00, errorClass: (byte)TdsEnums.MIN_ERROR_CLASS, server: serverName, errorMessage: errorMessage, procedure: null, lineNumber: 0));

if (e is SqlException)
if (e is SqlException exThrown)
{
SqlException exThrown = (SqlException)e;
SqlErrorCollection errorList = exThrown.Errors;
for (int i = 0; i < exThrown.Errors.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10664,9 +10664,9 @@ private Task TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParamet

if (isSqlVal)
{
if (value is SqlString)
if (value is SqlString sqlString)
{
s = ((SqlString)value).Value;
s = sqlString.Value;
}
else
{
Expand Down Expand Up @@ -11994,9 +11994,9 @@ internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsPars
break;
case TdsEnums.SQLXMLTYPE:
// Value here could be string or XmlReader
if (value is XmlReader)
if (value is XmlReader xmlReader)
{
value = MetaType.GetStringFromXml((XmlReader)value);
value = MetaType.GetStringFromXml(xmlReader);
}
ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
break;
Expand Down Expand Up @@ -12468,9 +12468,9 @@ private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLe
WriteInt(actualLength, stateObj); // chunk length
}

if (value is SqlBinary)
if (value is SqlBinary sqlBinary)
{
return stateObj.WriteByteArray(((SqlBinary)value).Value, actualLength, offset, canAccumulate: false);
return stateObj.WriteByteArray(sqlBinary.Value, actualLength, offset, canAccumulate: false);
}
else
{
Expand Down Expand Up @@ -12537,9 +12537,9 @@ private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLe
{
WriteInt(codePageByteSize, stateObj); // chunk length
}
if (value is SqlChars)
if (value is SqlChars sqlCharsEnc)
{
string sch = new string(((SqlChars)value).Value);
string sch = new string(sqlCharsEnc.Value);

return WriteEncodingChar(sch, actualLength, offset, _defaultEncoding, stateObj, canAccumulate: false);
}
Expand Down Expand Up @@ -12583,9 +12583,9 @@ private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLe
actualLength >>= 1;
}

if (value is SqlChars)
if (value is SqlChars sqlCharsArr)
{
return WriteCharArray(((SqlChars)value).Value, actualLength, offset, stateObj, canAccumulate: false);
return WriteCharArray(sqlCharsArr.Value, actualLength, offset, stateObj, canAccumulate: false);
}
else
{
Expand Down Expand Up @@ -13633,9 +13633,9 @@ private byte[] SerializeUnencryptedSqlValue(object value, MetaType type, int act
{
byte[] b = new byte[actualLength];

if (value is SqlBinary)
if (value is SqlBinary sqlBin)
{
Buffer.BlockCopy(((SqlBinary)value).Value, offset, b, 0, actualLength);
Buffer.BlockCopy(sqlBin.Value, offset, b, 0, actualLength);
}
else
{
Expand Down Expand Up @@ -13686,9 +13686,9 @@ private byte[] SerializeUnencryptedSqlValue(object value, MetaType type, int act
case TdsEnums.SQLBIGCHAR:
case TdsEnums.SQLBIGVARCHAR:
case TdsEnums.SQLTEXT:
if (value is SqlChars)
if (value is SqlChars sqlChSer)
{
String sch = new String(((SqlChars)value).Value);
String sch = new String(sqlChSer.Value);
return SerializeEncodingChar(sch, actualLength, offset, _defaultEncoding);
}
else
Expand All @@ -13709,9 +13709,9 @@ private byte[] SerializeUnencryptedSqlValue(object value, MetaType type, int act
actualLength >>= 1;
}

if (value is SqlChars)
if (value is SqlChars sqlChArr)
{
return SerializeCharArray(((SqlChars)value).Value, actualLength, offset);
return SerializeCharArray(sqlChArr.Value, actualLength, offset);
}
else
{
Expand Down
Loading