Skip to content

Commit

Permalink
Add GetFieldValue(Async)<T> support for XmlReader, TextReader, Stream (
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Oct 6, 2021
1 parent 6ac1e49 commit 3d73709
Show file tree
Hide file tree
Showing 9 changed files with 1,123 additions and 190 deletions.
12 changes: 8 additions & 4 deletions doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@
<summary>Synchronously gets the value of the specified column as a type. <see cref="M:Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueAsync``1(System.Int32,System.Threading.CancellationToken)" /> is the asynchronous version of this method.</summary>
<returns>The returned type object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
<format type="text/markdown">
<![CDATA[
## Remarks
`T` can be one of the following types:
Expand All @@ -332,7 +333,8 @@
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
|SqlInt64|SqlMoney|SqlSingle|SqlString|
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
|XmlReader||||
For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).
Expand All @@ -359,7 +361,8 @@
<summary>Asynchronously gets the value of the specified column as a type. <see cref="M:Microsoft.Data.SqlClient.SqlDataReader.GetFieldValue``1(System.Int32)" /> is the synchronous version of this method.</summary>
<returns>The returned type object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
<format type="text/markdown">
<![CDATA[
## Remarks
`T` can be one of the following types:
Expand All @@ -372,7 +375,8 @@
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
|SqlInt64|SqlMoney|SqlSingle|SqlString|
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
|XmlReader||||
For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal SqlXml ToSqlXml()
[MethodImpl(MethodImplOptions.NoInlining)]
internal XmlReader ToXmlReader()
{
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false);
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
}

public bool IsNull
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Data.SqlTypes;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Xml;
using Microsoft.Data.SqlTypes;

namespace Microsoft.Data.SqlClient
{
Expand Down Expand Up @@ -134,26 +134,7 @@ internal SqlXml ToSqlXml()
[MethodImpl(MethodImplOptions.NoInlining)]
internal XmlReader ToXmlReader()
{
//XmlTextReader xr = new XmlTextReader(fragment, XmlNodeType.Element, null);
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ConformanceLevel = ConformanceLevel.Fragment;

// Call internal XmlReader.CreateSqlReader from System.Xml.
// Signature: internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext);
MethodInfo createSqlReaderMethodInfo = typeof(System.Xml.XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
object[] args = new object[3] { ToStream(), readerSettings, null };
XmlReader xr;

new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.MemberAccess).Assert();
try
{
xr = (XmlReader)createSqlReaderMethodInfo.Invoke(null, args);
}
finally
{
System.Security.Permissions.ReflectionPermission.RevertAssert();
}
return xr;
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
}

public bool IsNull
Expand All @@ -163,7 +144,5 @@ public bool IsNull
return (_cachedBytes == null) ? true : false;
}
}

}

}
Loading

0 comments on commit 3d73709

Please sign in to comment.