Skip to content

Commit

Permalink
XMLDoc fixes for latest methods and missing DataSet in .NET Core
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Craver committed May 24, 2016
1 parent 806e343 commit 9a97a04
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 11 deletions.
1 change: 1 addition & 0 deletions Dapper.EntityFramework.StrongName/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}
},
"buildOptions": {
"xmlDoc": true,
"warningsAsErrors": true,
"compile": {
"include": [
Expand Down
1 change: 1 addition & 0 deletions Dapper.EntityFramework/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}
},
"buildOptions": {
"xmlDoc": true,
"warningsAsErrors": true
},
"frameworks": {
Expand Down
3 changes: 2 additions & 1 deletion Dapper.StrongName/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
},
"buildOptions": {
"xmlDoc": true,
"keyFile": "../Dapper.snk",
"warningsAsErrors": true,
"compile": {
Expand All @@ -28,7 +29,7 @@
"exclude": [
"../Dapper/obj/"
]
}
}
},
"frameworks": {
"net40": {
Expand Down
4 changes: 2 additions & 2 deletions Dapper/SqlMapper.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
/// <returns>An <see cref="IDataReader"/> that can be used to iterate over the results of the SQL query.</returns>
/// <remarks>
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a <see cref="DataTable"/>
/// or <see cref="DataSet"/>.
/// or <see cref="T:DataSet"/>.
/// </remarks>
/// <example>
/// <code>
Expand All @@ -804,7 +804,7 @@ public static Task<IDataReader> ExecuteReaderAsync(
/// <returns>An <see cref="IDataReader"/> that can be used to iterate over the results of the SQL query.</returns>
/// <remarks>
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a <see cref="DataTable"/>
/// or <see cref="DataSet"/>.
/// or <see cref="T:DataSet"/>.
/// </remarks>
public static Task<IDataReader> ExecuteReaderAsync(this IDbConnection cnn, CommandDefinition command)
{
Expand Down
76 changes: 75 additions & 1 deletion Dapper/SqlMapper.IDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Dapper
{
partial class SqlMapper
{
/// <summary>
/// Parses a data reader to a sequence of data of the supplied type. Used for deserializing a reader without a connection, etc.
/// </summary>
public static IEnumerable<T> Parse<T>(this IDataReader reader)
{
if(reader.Read())
Expand All @@ -17,6 +20,10 @@ public static IEnumerable<T> Parse<T>(this IDataReader reader)
} while (reader.Read());
}
}

/// <summary>
/// Parses a data reader to a sequence of data of the supplied type (as object). Used for deserializing a reader without a connection, etc.
/// </summary>
public static IEnumerable<object> Parse(this IDataReader reader, Type type)
{
if (reader.Read())
Expand All @@ -28,6 +35,10 @@ public static IEnumerable<object> Parse(this IDataReader reader, Type type)
} while (reader.Read());
}
}

/// <summary>
/// Parses a data reader to a sequence of dynamic. Used for deserializing a reader without a connection, etc.
/// </summary>
public static IEnumerable<dynamic> Parse(this IDataReader reader)
{
if (reader.Read())
Expand All @@ -39,12 +50,75 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
} while (reader.Read());
}
}


/// <summary>
/// Gets the row parser for a specific row on a data reader. This allows for type switching every row based on, for example, a TypeId column.
/// You could return a collection of the base type but have each more specific.
/// </summary>
/// <param name="reader">The data reader to get the parser for the current row from</param>
/// <param name="type">The type to get the parser for</param>
/// <param name="startIndex">The start column index of the object (default 0)</param>
/// <param name="length">The length of columns to read (default -1 = all fields following startIndex)</param>
/// <param name="returnNullIfFirstMissing">Return null if we can't find the first column? (default false)</param>
/// <returns>A parser for this specific object from this row.</returns>
public static Func<IDataReader, object> GetRowParser(this IDataReader reader, Type type,
int startIndex = 0, int length = -1, bool returnNullIfFirstMissing = false)
{
return GetDeserializer(type, reader, startIndex, length, returnNullIfFirstMissing);
}

/// <summary>
/// Gets the row parser for a specific row on a data reader. This allows for type switching every row based on, for example, a TypeId column.
/// You could return a collection of the base type but have each more specific.
/// </summary>
/// <param name="reader">The data reader to get the parser for the current row from</param>
/// <param name="concreteType">The type to get the parser for</param>
/// <param name="startIndex">The start column index of the object (default 0)</param>
/// <param name="length">The length of columns to read (default -1 = all fields following startIndex)</param>
/// <param name="returnNullIfFirstMissing">Return null if we can't find the first column? (default false)</param>
/// <returns>A parser for this specific object from this row.</returns>
/// <example>
/// var result = new List&lt;BaseType&gt;();
/// using (var reader = connection.ExecuteReader(@"
/// select 'abc' as Name, 1 as Type, 3.0 as Value
/// union all
/// select 'def' as Name, 2 as Type, 4.0 as Value"))
/// {
/// if (reader.Read())
/// {
/// var toFoo = reader.GetRowParser&lt;BaseType&gt;(typeof(Foo));
/// var toBar = reader.GetRowParser&lt;BaseType&gt;(typeof(Bar));
/// var col = reader.GetOrdinal("Type");
/// do
/// {
/// switch (reader.GetInt32(col))
/// {
/// case 1:
/// result.Add(toFoo(reader));
/// break;
/// case 2:
/// result.Add(toBar(reader));
/// break;
/// }
/// } while (reader.Read());
/// }
/// }
///
/// abstract class BaseType
/// {
/// public abstract int Type { get; }
/// }
/// class Foo : BaseType
/// {
/// public string Name { get; set; }
/// public override int Type =&gt; 1;
/// }
/// class Bar : BaseType
/// {
/// public float Value { get; set; }
/// public override int Type =&gt; 2;
/// }
/// </example>
public static Func<IDataReader, T> GetRowParser<T>(this IDataReader reader, Type concreteType = null,
int startIndex = 0, int length = -1, bool returnNullIfFirstMissing = false)
{
Expand Down
21 changes: 14 additions & 7 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ public static DbType GetDbType(object value)
return LookupDbType(value.GetType(), "n/a", false, out handler);

}

/// <summary>
/// OBSOLETE: For internal usage only. Lookup the DbType and handler for a given Type and member
/// </summary>
[Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX
[Browsable(false)]
Expand Down Expand Up @@ -554,7 +558,7 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
/// <returns>An <see cref="IDataReader"/> that can be used to iterate over the results of the SQL query.</returns>
/// <remarks>
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a <see cref="DataTable"/>
/// or <see cref="DataSet"/>.
/// or <see cref="T:DataSet"/>.
/// </remarks>
/// <example>
/// <code>
Expand Down Expand Up @@ -583,7 +587,7 @@ public static IDataReader ExecuteReader(
/// <returns>An <see cref="IDataReader"/> that can be used to iterate over the results of the SQL query.</returns>
/// <remarks>
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a <see cref="DataTable"/>
/// or <see cref="DataSet"/>.
/// or <see cref="T:DataSet"/>.
/// </remarks>
public static IDataReader ExecuteReader(this IDbConnection cnn, CommandDefinition command)
{
Expand All @@ -597,7 +601,7 @@ public static IDataReader ExecuteReader(this IDbConnection cnn, CommandDefinitio
/// <returns>An <see cref="IDataReader"/> that can be used to iterate over the results of the SQL query.</returns>
/// <remarks>
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a <see cref="DataTable"/>
/// or <see cref="DataSet"/>.
/// or <see cref="T:DataSet"/>.
/// </remarks>
public static IDataReader ExecuteReader(this IDbConnection cnn, CommandDefinition command, CommandBehavior commandBehavior)
{
Expand Down Expand Up @@ -804,7 +808,7 @@ public static IEnumerable<T> Query<T>(this IDbConnection cnn, CommandDefinition
/// Executes a query, returning the data typed as per T
/// </summary>
/// <remarks>the dynamic param may seem a bit odd, but this works around a major usability issue in vs, if it is Object vs completion gets annoying. Eg type new [space] get new object</remarks>
/// <returns>A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// <returns>A single instance or null of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
/// </returns>
public static T QueryFirst<T>(this IDbConnection cnn, CommandDefinition command)
Expand All @@ -815,7 +819,7 @@ public static T QueryFirst<T>(this IDbConnection cnn, CommandDefinition command)
/// Executes a query, returning the data typed as per T
/// </summary>
/// <remarks>the dynamic param may seem a bit odd, but this works around a major usability issue in vs, if it is Object vs completion gets annoying. Eg type new [space] get new object</remarks>
/// <returns>A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// <returns>A single or null instance of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
/// </returns>
public static T QueryFirstOrDefault<T>(this IDbConnection cnn, CommandDefinition command)
Expand All @@ -826,7 +830,7 @@ public static T QueryFirstOrDefault<T>(this IDbConnection cnn, CommandDefinition
/// Executes a query, returning the data typed as per T
/// </summary>
/// <remarks>the dynamic param may seem a bit odd, but this works around a major usability issue in vs, if it is Object vs completion gets annoying. Eg type new [space] get new object</remarks>
/// <returns>A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// <returns>A single instance of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
/// </returns>
public static T QuerySingle<T>(this IDbConnection cnn, CommandDefinition command)
Expand All @@ -837,7 +841,7 @@ public static T QuerySingle<T>(this IDbConnection cnn, CommandDefinition command
/// Executes a query, returning the data typed as per T
/// </summary>
/// <remarks>the dynamic param may seem a bit odd, but this works around a major usability issue in vs, if it is Object vs completion gets annoying. Eg type new [space] get new object</remarks>
/// <returns>A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// <returns>A single instance of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
/// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
/// </returns>
public static T QuerySingleOrDefault<T>(this IDbConnection cnn, CommandDefinition command)
Expand Down Expand Up @@ -1970,6 +1974,9 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj

}

/// <summary>
/// OBSOLETE: For internal usage only. Sanitizes the paramter value with proper type casting.
/// </summary>
[Obsolete(ObsoleteInternalUsageOnly, false)]
public static object SanitizeParameterValue(object value)
{
Expand Down
1 change: 1 addition & 0 deletions Dapper/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
},
"buildOptions": {
"xmlDoc": true,
"warningsAsErrors": true
},
"frameworks": {
Expand Down

0 comments on commit 9a97a04

Please sign in to comment.