-
Notifications
You must be signed in to change notification settings - Fork 323
avoid casts by using pattern matching #4014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| { | ||
|
|
@@ -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; | ||
|
|
@@ -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 | ||
| { | ||
|
|
@@ -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 sqlCharsA) | ||
| { | ||
| string sch = new string(((SqlChars)value).Value); | ||
| string sch = new string(sqlCharsA.Value); | ||
|
|
||
| return WriteEncodingChar(sch, actualLength, offset, _defaultEncoding, stateObj, canAccumulate: false); | ||
| } | ||
|
|
@@ -12583,9 +12583,9 @@ private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLe | |
| actualLength >>= 1; | ||
| } | ||
|
|
||
| if (value is SqlChars) | ||
| if (value is SqlChars sqlCharsB) | ||
| { | ||
| return WriteCharArray(((SqlChars)value).Value, actualLength, offset, stateObj, canAccumulate: false); | ||
| return WriteCharArray(sqlCharsB.Value, actualLength, offset, stateObj, canAccumulate: false); | ||
|
Comment on lines
+12586
to
+12588
|
||
| } | ||
| else | ||
| { | ||
|
|
@@ -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 sqlBinary2) | ||
| { | ||
| Buffer.BlockCopy(((SqlBinary)value).Value, offset, b, 0, actualLength); | ||
| Buffer.BlockCopy(sqlBinary2.Value, offset, b, 0, actualLength); | ||
|
Comment on lines
+13636
to
+13638
|
||
| } | ||
| else | ||
| { | ||
|
|
@@ -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 sqlCharsC) | ||
| { | ||
| String sch = new String(((SqlChars)value).Value); | ||
| String sch = new String(sqlCharsC.Value); | ||
| return SerializeEncodingChar(sch, actualLength, offset, _defaultEncoding); | ||
|
Comment on lines
+13689
to
13692
|
||
| } | ||
| else | ||
|
|
@@ -13709,9 +13709,9 @@ private byte[] SerializeUnencryptedSqlValue(object value, MetaType type, int act | |
| actualLength >>= 1; | ||
| } | ||
|
|
||
| if (value is SqlChars) | ||
| if (value is SqlChars sqlCharsD) | ||
| { | ||
| return SerializeCharArray(((SqlChars)value).Value, actualLength, offset); | ||
| return SerializeCharArray(sqlCharsD.Value, actualLength, offset); | ||
|
Comment on lines
+13712
to
+13714
|
||
| } | ||
| else | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suffix "A" on
sqlCharsAisn’t meaningful here and reduces readability. Since the pattern variable is scoped to theifblock, consider renaming tosqlChars(or another descriptive name) without the letter suffix.