Skip to content

Commit 962f8c8

Browse files
committed
6. Optional refactoring that reduces #if directives in merged TdsParserStateObject.
1 parent 674496f commit 962f8c8

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ internal struct SNIErrorDetails
4040
// and surfacing objects to the user.
4141
internal sealed partial class TdsParser
4242
{
43+
internal struct ReliabilitySection
44+
{
45+
/// <summary>
46+
/// This is a no-op in netcore version. Only needed for merging with netfx codebase.
47+
/// </summary>
48+
[Conditional("NETFRAMEWORK")]
49+
internal static void Assert(string message)
50+
{
51+
}
52+
}
53+
4354
private static int _objectTypeCount; // EventSource counter
4455
private readonly SqlClientLogger _logger = new SqlClientLogger();
4556

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,7 @@ internal bool TryProcessHeader()
963963
// NOTE: This method (and all it calls) should be retryable without replaying a snapshot
964964
internal bool TryPrepareBuffer()
965965
{
966-
#if NETFRAMEWORK
967966
TdsParser.ReliabilitySection.Assert("unreliable call to ReadBuffer"); // you need to setup for a thread abort somewhere before you call this method
968-
#endif
969967
Debug.Assert(_inBuff != null, "packet buffer should not be null!");
970968

971969
// Header spans packets, or we haven't read the header yet - process header
@@ -1146,9 +1144,7 @@ public bool TryReadByteArray(Span<byte> buff, int len)
11461144
// Every time you call this method increment the offset and decrease len by the value of totalRead
11471145
public bool TryReadByteArray(Span<byte> buff, int len, out int totalRead)
11481146
{
1149-
#if NETFRAMEWORK
11501147
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByteArray"); // you need to setup for a thread abort somewhere before you call this method
1151-
#endif
11521148
totalRead = 0;
11531149

11541150
#if DEBUG
@@ -1207,9 +1203,7 @@ public bool TryReadByteArray(Span<byte> buff, int len, out int totalRead)
12071203
// before the byte is returned.
12081204
internal bool TryReadByte(out byte value)
12091205
{
1210-
#if NETFRAMEWORK
12111206
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByte"); // you need to setup for a thread abort somewhere before you call this method
1212-
#endif
12131207
Debug.Assert(_inBytesUsed >= 0 && _inBytesUsed <= _inBytesRead, "ERROR - TDSParser: _inBytesUsed < 0 or _inBytesUsed > _inBytesRead");
12141208
value = 0;
12151209

@@ -1313,9 +1307,7 @@ internal bool TryReadInt16(out short value)
13131307

13141308
internal bool TryReadInt32(out int value)
13151309
{
1316-
#if NETFRAMEWORK
13171310
TdsParser.ReliabilitySection.Assert("unreliable call to ReadInt32"); // you need to setup for a thread abort somewhere before you call this method
1318-
#endif
13191311
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
13201312
Span<byte> buffer = stackalloc byte[4];
13211313
if (((_inBytesUsed + 4) > _inBytesRead) || (_inBytesPacket < 4))
@@ -1345,9 +1337,7 @@ internal bool TryReadInt32(out int value)
13451337
// This method is safe to call when doing async without snapshot
13461338
internal bool TryReadInt64(out long value)
13471339
{
1348-
#if NETFRAMEWORK
13491340
TdsParser.ReliabilitySection.Assert("unreliable call to ReadInt64"); // you need to setup for a thread abort somewhere before you call this method
1350-
#endif
13511341
if ((_inBytesPacket == 0) || (_inBytesUsed == _inBytesRead))
13521342
{
13531343
if (!TryPrepareBuffer())
@@ -1426,9 +1416,7 @@ internal bool TryReadUInt16(out ushort value)
14261416
// This method is safe to call when doing async without replay
14271417
internal bool TryReadUInt32(out uint value)
14281418
{
1429-
#if NETFRAMEWORK
14301419
TdsParser.ReliabilitySection.Assert("unreliable call to ReadUInt32"); // you need to setup for a thread abort somewhere before you call this method
1431-
#endif
14321420
if ((_inBytesPacket == 0) || (_inBytesUsed == _inBytesRead))
14331421
{
14341422
if (!TryPrepareBuffer())
@@ -1477,9 +1465,7 @@ internal bool TryReadUInt32(out uint value)
14771465

14781466
internal bool TryReadSingle(out float value)
14791467
{
1480-
#if NETFRAMEWORK
14811468
TdsParser.ReliabilitySection.Assert("unreliable call to ReadSingle"); // you need to setup for a thread abort somewhere before you call this method
1482-
#endif
14831469
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
14841470
if (((_inBytesUsed + 4) > _inBytesRead) || (_inBytesPacket < 4))
14851471
{
@@ -1513,9 +1499,7 @@ internal bool TryReadSingle(out float value)
15131499

15141500
internal bool TryReadDouble(out double value)
15151501
{
1516-
#if NETFRAMEWORK
15171502
TdsParser.ReliabilitySection.Assert("unreliable call to ReadDouble"); // you need to setup for a thread abort somewhere before you call this method
1518-
#endif
15191503
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
15201504
if (((_inBytesUsed + 8) > _inBytesRead) || (_inBytesPacket < 8))
15211505
{
@@ -1549,9 +1533,7 @@ internal bool TryReadDouble(out double value)
15491533

15501534
internal bool TryReadString(int length, out string value)
15511535
{
1552-
#if NETFRAMEWORK
15531536
TdsParser.ReliabilitySection.Assert("unreliable call to ReadString"); // you need to setup for a thread abort somewhere before you call this method
1554-
#endif
15551537
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
15561538
int cBytes = length << 1;
15571539
byte[] buf;
@@ -1592,9 +1574,7 @@ internal bool TryReadString(int length, out string value)
15921574

15931575
internal bool TryReadStringWithEncoding(int length, System.Text.Encoding encoding, bool isPlp, out string value)
15941576
{
1595-
#if NETFRAMEWORK
15961577
TdsParser.ReliabilitySection.Assert("unreliable call to ReadStringWithEncoding"); // you need to setup for a thread abort somewhere before you call this method
1597-
#endif
15981578
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
15991579

16001580
if (null == encoding)

0 commit comments

Comments
 (0)