Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
6745addf
Commit
6745addf
authored
May 08, 2017
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation and formatting: secondary types
parent
4d75b982
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
107 additions
and
65 deletions
+107
-65
CommandDefinition.cs
Dapper/CommandDefinition.cs
+20
-1
DynamicParameters.cs
Dapper/DynamicParameters.cs
+15
-5
FeatureSupport.cs
Dapper/FeatureSupport.cs
+2
-0
SqlDataRecordListTVPParameter.cs
Dapper/SqlDataRecordListTVPParameter.cs
+3
-1
SqlMapper.DapperRow.cs
Dapper/SqlMapper.DapperRow.cs
+1
-1
SqlMapper.DontMap.cs
Dapper/SqlMapper.DontMap.cs
+1
-1
SqlMapper.GridReader.Async.cs
Dapper/SqlMapper.GridReader.Async.cs
+1
-1
SqlMapper.GridReader.cs
Dapper/SqlMapper.GridReader.cs
+1
-1
SqlMapper.IDataReader.cs
Dapper/SqlMapper.IDataReader.cs
+12
-6
SqlMapper.IParameterLookup.cs
Dapper/SqlMapper.IParameterLookup.cs
+1
-0
SqlMapper.Identity.cs
Dapper/SqlMapper.Identity.cs
+20
-28
SqlMapper.Link.cs
Dapper/SqlMapper.Link.cs
+2
-0
SqlMapper.TypeHandler.cs
Dapper/SqlMapper.TypeHandler.cs
+8
-0
SqlMapper.TypeHandlerCache.cs
Dapper/SqlMapper.TypeHandlerCache.cs
+8
-10
TableValuedParameter.cs
Dapper/TableValuedParameter.cs
+10
-9
UdtTypeHandler.cs
Dapper/UdtTypeHandler.cs
+2
-1
No files found.
Dapper/CommandDefinition.cs
View file @
6745addf
...
@@ -73,9 +73,28 @@ internal void OnCompleted()
...
@@ -73,9 +73,28 @@ internal void OnCompleted()
/// </summary>
/// </summary>
public
bool
Pipelined
=>
(
Flags
&
CommandFlags
.
Pipelined
)
!=
0
;
public
bool
Pipelined
=>
(
Flags
&
CommandFlags
.
Pipelined
)
!=
0
;
#if ASYNC
/// <summary>
/// <summary>
/// Initialize the command definition
/// Initialize the command definition
/// </summary>
/// </summary>
/// <param name="commandText">The text for this command.</param>
/// <param name="parameters">The parameters for this command.</param>
/// <param name="transaction">The transaction for this command to participate in.</param>
/// <param name="commandTimeout">The timeout (in seconds) for this command.</param>
/// <param name="commandType">The <see cref="CommandType"/> for this command.</param>
/// <param name="flags">The behavior flags for this command.</param>
/// <param name="cancellationToken">The cancellation token for this command.</param>
#else
/// <summary>
/// Initialize the command definition
/// </summary>
/// <param name="commandText">The text for this command.</param>
/// <param name="parameters">The parameters for this command.</param>
/// <param name="transaction">The transaction for this command to participate in.</param>
/// <param name="commandTimeout">The timeout (in seconds) for this command.</param>
/// <param name="commandType">The <see cref="CommandType"/> for this command.</param>
/// <param name="flags">The behavior flags for this command.</param>
#endif
public
CommandDefinition
(
string
commandText
,
object
parameters
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
public
CommandDefinition
(
string
commandText
,
object
parameters
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
,
CommandFlags
flags
=
CommandFlags
.
Buffered
CommandType
?
commandType
=
null
,
CommandFlags
flags
=
CommandFlags
.
Buffered
#if ASYNC
#if ASYNC
...
@@ -182,4 +201,4 @@ private static MethodInfo GetBasicPropertySetter(Type declaringType, string name
...
@@ -182,4 +201,4 @@ private static MethodInfo GetBasicPropertySetter(Type declaringType, string name
return
null
;
return
null
;
}
}
}
}
}
}
\ No newline at end of file
Dapper/DynamicParameters.cs
View file @
6745addf
...
@@ -93,8 +93,13 @@ public void AddDynamicParams(object param)
...
@@ -93,8 +93,13 @@ public void AddDynamicParams(object param)
}
}
/// <summary>
/// <summary>
/// Add a parameter to this dynamic parameter list
/// Add a parameter to this dynamic parameter list
.
/// </summary>
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter.</param>
/// <param name="dbType">The type of the parameter.</param>
/// <param name="direction">The in or out direction of the parameter.</param>
/// <param name="size">The size of the parameter.</param>
public
void
Add
(
string
name
,
object
value
,
DbType
?
dbType
,
ParameterDirection
?
direction
,
int
?
size
)
public
void
Add
(
string
name
,
object
value
,
DbType
?
dbType
,
ParameterDirection
?
direction
,
int
?
size
)
{
{
parameters
[
Clean
(
name
)]
=
new
ParamInfo
parameters
[
Clean
(
name
)]
=
new
ParamInfo
...
@@ -108,11 +113,16 @@ public void Add(string name, object value, DbType? dbType, ParameterDirection? d
...
@@ -108,11 +113,16 @@ public void Add(string name, object value, DbType? dbType, ParameterDirection? d
}
}
/// <summary>
/// <summary>
/// Add a parameter to this dynamic parameter list
/// Add a parameter to this dynamic parameter list
.
/// </summary>
/// </summary>
public
void
Add
(
/// <param name="name">The name of the parameter.</param>
string
name
,
object
value
=
null
,
DbType
?
dbType
=
null
,
ParameterDirection
?
direction
=
null
,
int
?
size
=
null
,
byte
?
precision
=
null
,
byte
?
scale
=
null
/// <param name="value">The value of the parameter.</param>
)
/// <param name="dbType">The type of the parameter.</param>
/// <param name="direction">The in or out direction of the parameter.</param>
/// <param name="size">The size of the parameter.</param>
/// <param name="precision">The precision of the parameter.</param>
/// <param name="scale">The scale of the parameter.</param>
public
void
Add
(
string
name
,
object
value
=
null
,
DbType
?
dbType
=
null
,
ParameterDirection
?
direction
=
null
,
int
?
size
=
null
,
byte
?
precision
=
null
,
byte
?
scale
=
null
)
{
{
parameters
[
Clean
(
name
)]
=
new
ParamInfo
parameters
[
Clean
(
name
)]
=
new
ParamInfo
{
{
...
...
Dapper/FeatureSupport.cs
View file @
6745addf
...
@@ -15,6 +15,7 @@ private static readonly FeatureSupport
...
@@ -15,6 +15,7 @@ private static readonly FeatureSupport
/// <summary>
/// <summary>
/// Gets the feature set based on the passed connection
/// Gets the feature set based on the passed connection
/// </summary>
/// </summary>
/// <param name="connection">The connection to get supported features for.</param>
public
static
FeatureSupport
Get
(
IDbConnection
connection
)
public
static
FeatureSupport
Get
(
IDbConnection
connection
)
{
{
string
name
=
connection
?.
GetType
().
Name
;
string
name
=
connection
?.
GetType
().
Name
;
...
@@ -26,6 +27,7 @@ private FeatureSupport(bool arrays)
...
@@ -26,6 +27,7 @@ private FeatureSupport(bool arrays)
{
{
Arrays
=
arrays
;
Arrays
=
arrays
;
}
}
/// <summary>
/// <summary>
/// True if the db supports array columns e.g. Postgresql
/// True if the db supports array columns e.g. Postgresql
/// </summary>
/// </summary>
...
...
Dapper/SqlDataRecordListTVPParameter.cs
View file @
6745addf
...
@@ -13,8 +13,10 @@ internal sealed class SqlDataRecordListTVPParameter : SqlMapper.ICustomQueryPara
...
@@ -13,8 +13,10 @@ internal sealed class SqlDataRecordListTVPParameter : SqlMapper.ICustomQueryPara
private
readonly
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
;
private
readonly
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
;
private
readonly
string
typeName
;
private
readonly
string
typeName
;
/// <summary>
/// <summary>
/// Create a new instance of
SqlDataRecordListTVPParameter
/// Create a new instance of
<see cref="SqlDataRecordListTVPParameter"/>.
/// </summary>
/// </summary>
/// <param name="data">The data records to convert into TVPs.</param>
/// <param name="typeName">The parameter type name.</param>
public
SqlDataRecordListTVPParameter
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
,
string
typeName
)
public
SqlDataRecordListTVPParameter
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
,
string
typeName
)
{
{
this
.
data
=
data
;
this
.
data
=
data
;
...
...
Dapper/SqlMapper.DapperRow.cs
View file @
6745addf
...
@@ -23,7 +23,7 @@ public DapperRow(DapperTable table, object[] values)
...
@@ -23,7 +23,7 @@ public DapperRow(DapperTable table, object[] values)
private
sealed
class
DeadValue
private
sealed
class
DeadValue
{
{
public
static
readonly
DeadValue
Default
=
new
DeadValue
();
public
static
readonly
DeadValue
Default
=
new
DeadValue
();
private
DeadValue
()
{
}
private
DeadValue
()
{
/* hiding constructor */
}
}
}
int
ICollection
<
KeyValuePair
<
string
,
object
>>.
Count
int
ICollection
<
KeyValuePair
<
string
,
object
>>.
Count
...
...
Dapper/SqlMapper.DontMap.cs
View file @
6745addf
...
@@ -5,6 +5,6 @@ public static partial class SqlMapper
...
@@ -5,6 +5,6 @@ public static partial class SqlMapper
/// <summary>
/// <summary>
/// Dummy type for excluding from multi-map
/// Dummy type for excluding from multi-map
/// </summary>
/// </summary>
private
class
DontMap
{
}
private
class
DontMap
{
/* hiding constructor */
}
}
}
}
}
Dapper/SqlMapper.GridReader.Async.cs
View file @
6745addf
...
@@ -213,7 +213,7 @@ private async Task<T> ReadRowAsyncImplViaDbReader<T>(DbDataReader reader, Type t
...
@@ -213,7 +213,7 @@ private async Task<T> ReadRowAsyncImplViaDbReader<T>(DbDataReader reader, Type t
}
}
result
=
(
T
)
deserializer
.
Func
(
reader
);
result
=
(
T
)
deserializer
.
Func
(
reader
);
if
((
row
&
Row
.
Single
)
!=
0
&&
await
reader
.
ReadAsync
(
cancel
).
ConfigureAwait
(
false
))
ThrowMultipleRows
(
row
);
if
((
row
&
Row
.
Single
)
!=
0
&&
await
reader
.
ReadAsync
(
cancel
).
ConfigureAwait
(
false
))
ThrowMultipleRows
(
row
);
while
(
await
reader
.
ReadAsync
(
cancel
).
ConfigureAwait
(
false
))
{
}
while
(
await
reader
.
ReadAsync
(
cancel
).
ConfigureAwait
(
false
))
{
/* ignore subsequent rows */
}
}
}
else
if
((
row
&
Row
.
FirstOrDefault
)
==
0
)
// demanding a row, and don't have one
else
if
((
row
&
Row
.
FirstOrDefault
)
==
0
)
// demanding a row, and don't have one
{
{
...
...
Dapper/SqlMapper.GridReader.cs
View file @
6745addf
...
@@ -192,7 +192,7 @@ private T ReadRow<T>(Type type, Row row)
...
@@ -192,7 +192,7 @@ private T ReadRow<T>(Type type, Row row)
result
=
(
T
)
Convert
.
ChangeType
(
val
,
convertToType
,
CultureInfo
.
InvariantCulture
);
result
=
(
T
)
Convert
.
ChangeType
(
val
,
convertToType
,
CultureInfo
.
InvariantCulture
);
}
}
if
((
row
&
Row
.
Single
)
!=
0
&&
reader
.
Read
())
ThrowMultipleRows
(
row
);
if
((
row
&
Row
.
Single
)
!=
0
&&
reader
.
Read
())
ThrowMultipleRows
(
row
);
while
(
reader
.
Read
())
{
}
while
(
reader
.
Read
())
{
/* ignore subsequent rows */
}
}
}
else
if
((
row
&
Row
.
FirstOrDefault
)
==
0
)
// demanding a row, and don't have one
else
if
((
row
&
Row
.
FirstOrDefault
)
==
0
)
// demanding a row, and don't have one
{
{
...
...
Dapper/SqlMapper.IDataReader.cs
View file @
6745addf
...
@@ -9,9 +9,11 @@ public static partial class SqlMapper
...
@@ -9,9 +9,11 @@ public static partial class SqlMapper
/// <summary>
/// <summary>
/// Parses a data reader to a sequence of data of the supplied type. Used for deserializing a reader without a connection, etc.
/// Parses a data reader to a sequence of data of the supplied type. Used for deserializing a reader without a connection, etc.
/// </summary>
/// </summary>
/// <typeparam name="T">The type to parse from the <paramref name="reader"/>.</typeparam>
/// <param name="reader">The data reader to parse results from.</param>
public
static
IEnumerable
<
T
>
Parse
<
T
>(
this
IDataReader
reader
)
public
static
IEnumerable
<
T
>
Parse
<
T
>(
this
IDataReader
reader
)
{
{
if
(
reader
.
Read
())
if
(
reader
.
Read
())
{
{
var
deser
=
GetDeserializer
(
typeof
(
T
),
reader
,
0
,
-
1
,
false
);
var
deser
=
GetDeserializer
(
typeof
(
T
),
reader
,
0
,
-
1
,
false
);
do
do
...
@@ -24,6 +26,8 @@ public static IEnumerable<T> Parse<T>(this IDataReader reader)
...
@@ -24,6 +26,8 @@ public static IEnumerable<T> Parse<T>(this IDataReader reader)
/// <summary>
/// <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.
/// 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>
/// </summary>
/// <param name="reader">The data reader to parse results from.</param>
/// <param name="type">The type to parse from the <paramref name="reader"/>.</param>
public
static
IEnumerable
<
object
>
Parse
(
this
IDataReader
reader
,
Type
type
)
public
static
IEnumerable
<
object
>
Parse
(
this
IDataReader
reader
,
Type
type
)
{
{
if
(
reader
.
Read
())
if
(
reader
.
Read
())
...
@@ -39,6 +43,7 @@ public static IEnumerable<object> Parse(this IDataReader reader, Type type)
...
@@ -39,6 +43,7 @@ public static IEnumerable<object> Parse(this IDataReader reader, Type type)
/// <summary>
/// <summary>
/// Parses a data reader to a sequence of dynamic. Used for deserializing a reader without a connection, etc.
/// Parses a data reader to a sequence of dynamic. Used for deserializing a reader without a connection, etc.
/// </summary>
/// </summary>
/// <param name="reader">The data reader to parse results from.</param>
public
static
IEnumerable
<
dynamic
>
Parse
(
this
IDataReader
reader
)
public
static
IEnumerable
<
dynamic
>
Parse
(
this
IDataReader
reader
)
{
{
if
(
reader
.
Read
())
if
(
reader
.
Read
())
...
@@ -71,11 +76,12 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
...
@@ -71,11 +76,12 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
/// 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.
/// 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.
/// You could return a collection of the base type but have each more specific.
/// </summary>
/// </summary>
/// <param name="reader">The data reader to get the parser for the current row from</param>
/// <typeparam name="T">The type of results to return.</typeparam>
/// <param name="concreteType">The type to get the parser for</param>
/// <param name="reader">The data reader to get the parser for the current row from.</param>
/// <param name="startIndex">The start column index of the object (default 0)</param>
/// <param name="concreteType">The type to get the parser for.</param>
/// <param name="length">The length of columns to read (default -1 = all fields following startIndex)</param>
/// <param name="startIndex">The start column index of the object (default: 0).</param>
/// <param name="returnNullIfFirstMissing">Return null if we can't find the first column? (default false)</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>
/// <returns>A parser for this specific object from this row.</returns>
/// <example>
/// <example>
/// var result = new List<BaseType>();
/// var result = new List<BaseType>();
...
...
Dapper/SqlMapper.IParameterLookup.cs
View file @
6745addf
...
@@ -10,6 +10,7 @@ public interface IParameterLookup : IDynamicParameters
...
@@ -10,6 +10,7 @@ public interface IParameterLookup : IDynamicParameters
/// <summary>
/// <summary>
/// Get the value of the specified parameter (return null if not found)
/// Get the value of the specified parameter (return null if not found)
/// </summary>
/// </summary>
/// <param name="name">The name of the parameter to get.</param>
object
this
[
string
name
]
{
get
;
}
object
this
[
string
name
]
{
get
;
}
}
}
}
}
...
...
Dapper/SqlMapper.Identity.cs
View file @
6745addf
...
@@ -6,32 +6,27 @@ namespace Dapper
...
@@ -6,32 +6,27 @@ namespace Dapper
public
static
partial
class
SqlMapper
public
static
partial
class
SqlMapper
{
{
/// <summary>
/// <summary>
/// Identity of a cached query in Dapper, used for extensibility
/// Identity of a cached query in Dapper, used for extensibility
.
/// </summary>
/// </summary>
public
class
Identity
:
IEquatable
<
Identity
>
public
class
Identity
:
IEquatable
<
Identity
>
{
{
internal
Identity
ForGrid
(
Type
primaryType
,
int
gridIndex
)
internal
Identity
ForGrid
(
Type
primaryType
,
int
gridIndex
)
=>
{
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
null
,
gridIndex
);
return
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
null
,
gridIndex
);
}
internal
Identity
ForGrid
(
Type
primaryType
,
Type
[]
otherTypes
,
int
gridIndex
)
=>
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
otherTypes
,
gridIndex
);
internal
Identity
ForGrid
(
Type
primaryType
,
Type
[]
otherTypes
,
int
gridIndex
)
{
return
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
otherTypes
,
gridIndex
);
}
/// <summary>
/// <summary>
/// Create an identity for use with DynamicParameters, internal use only
/// Create an identity for use with DynamicParameters, internal use only
.
/// </summary>
/// </summary>
/// <param name="type"></param>
/// <param name="type">
The parameters type to create an <see cref="Identity"/> for.
</param>
/// <returns></returns>
/// <returns></returns>
public
Identity
ForDynamicParameters
(
Type
type
)
public
Identity
ForDynamicParameters
(
Type
type
)
=>
{
new
Identity
(
sql
,
commandType
,
connectionString
,
this
.
type
,
type
,
null
,
-
1
);
return
new
Identity
(
sql
,
commandType
,
connectionString
,
this
.
type
,
type
,
null
,
-
1
);
}
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
)
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
)
:
this
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
otherTypes
,
0
)
:
this
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
otherTypes
,
0
)
{
/* base call */
}
{
}
private
Identity
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
,
int
gridIndex
)
private
Identity
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
,
int
gridIndex
)
{
{
this
.
sql
=
sql
;
this
.
sql
=
sql
;
...
@@ -43,19 +38,19 @@ private Identity(string sql, CommandType? commandType, string connectionString,
...
@@ -43,19 +38,19 @@ private Identity(string sql, CommandType? commandType, string connectionString,
unchecked
unchecked
{
{
hashCode
=
17
;
// we *know* we are using this in a dictionary, so pre-compute this
hashCode
=
17
;
// we *know* we are using this in a dictionary, so pre-compute this
hashCode
=
hashCode
*
23
+
commandType
.
GetHashCode
();
hashCode
=
(
hashCode
*
23
)
+
commandType
.
GetHashCode
();
hashCode
=
hashCode
*
23
+
gridIndex
.
GetHashCode
();
hashCode
=
(
hashCode
*
23
)
+
gridIndex
.
GetHashCode
();
hashCode
=
hashCode
*
23
+
(
sql
?.
GetHashCode
()
??
0
);
hashCode
=
(
hashCode
*
23
)
+
(
sql
?.
GetHashCode
()
??
0
);
hashCode
=
hashCode
*
23
+
(
type
?.
GetHashCode
()
??
0
);
hashCode
=
(
hashCode
*
23
)
+
(
type
?.
GetHashCode
()
??
0
);
if
(
otherTypes
!=
null
)
if
(
otherTypes
!=
null
)
{
{
foreach
(
var
t
in
otherTypes
)
foreach
(
var
t
in
otherTypes
)
{
{
hashCode
=
hashCode
*
23
+
(
t
?.
GetHashCode
()
??
0
);
hashCode
=
(
hashCode
*
23
)
+
(
t
?.
GetHashCode
()
??
0
);
}
}
}
}
hashCode
=
hashCode
*
23
+
(
connectionString
==
null
?
0
:
connectionStringComparer
.
GetHashCode
(
connectionString
));
hashCode
=
(
hashCode
*
23
)
+
(
connectionString
==
null
?
0
:
connectionStringComparer
.
GetHashCode
(
connectionString
));
hashCode
=
hashCode
*
23
+
(
parametersType
?.
GetHashCode
()
??
0
);
hashCode
=
(
hashCode
*
23
)
+
(
parametersType
?.
GetHashCode
()
??
0
);
}
}
}
}
...
@@ -63,10 +58,7 @@ private Identity(string sql, CommandType? commandType, string connectionString,
...
@@ -63,10 +58,7 @@ private Identity(string sql, CommandType? commandType, string connectionString,
/// Whether this <see cref="Identity"/> equals another.
/// Whether this <see cref="Identity"/> equals another.
/// </summary>
/// </summary>
/// <param name="obj">The other <see cref="object"/> to compare to.</param>
/// <param name="obj">The other <see cref="object"/> to compare to.</param>
public
override
bool
Equals
(
object
obj
)
public
override
bool
Equals
(
object
obj
)
=>
Equals
(
obj
as
Identity
);
{
return
Equals
(
obj
as
Identity
);
}
/// <summary>
/// <summary>
/// The raw SQL command.
/// The raw SQL command.
...
...
Dapper/SqlMapper.Link.cs
View file @
6745addf
...
@@ -9,6 +9,8 @@ public static partial class SqlMapper
...
@@ -9,6 +9,8 @@ public static partial class SqlMapper
/// and strictly append-only; you cannot change existing values. All key matches are on **REFERENCE**
/// and strictly append-only; you cannot change existing values. All key matches are on **REFERENCE**
/// equality. The type is fully thread-safe.
/// equality. The type is fully thread-safe.
/// </summary>
/// </summary>
/// <typeparam name="TKey">The type to cache.</typeparam>
/// <typeparam name="TValue">The value type of the cache.</typeparam>
internal
class
Link
<
TKey
,
TValue
>
where
TKey
:
class
internal
class
Link
<
TKey
,
TValue
>
where
TKey
:
class
{
{
public
static
bool
TryGet
(
Link
<
TKey
,
TValue
>
link
,
TKey
key
,
out
TValue
value
)
public
static
bool
TryGet
(
Link
<
TKey
,
TValue
>
link
,
TKey
key
,
out
TValue
value
)
...
...
Dapper/SqlMapper.TypeHandler.cs
View file @
6745addf
...
@@ -8,6 +8,7 @@ public static partial class SqlMapper
...
@@ -8,6 +8,7 @@ public static partial class SqlMapper
/// <summary>
/// <summary>
/// Base-class for simple type-handlers
/// Base-class for simple type-handlers
/// </summary>
/// </summary>
/// <typeparam name="T">This <see cref="Type"/> this handler is for.</typeparam>
public
abstract
class
TypeHandler
<
T
>
:
ITypeHandler
public
abstract
class
TypeHandler
<
T
>
:
ITypeHandler
{
{
/// <summary>
/// <summary>
...
@@ -41,19 +42,25 @@ object ITypeHandler.Parse(Type destinationType, object value)
...
@@ -41,19 +42,25 @@ object ITypeHandler.Parse(Type destinationType, object value)
return
Parse
(
value
);
return
Parse
(
value
);
}
}
}
}
/// <summary>
/// <summary>
/// Base-class for simple type-handlers that are based around strings
/// Base-class for simple type-handlers that are based around strings
/// </summary>
/// </summary>
/// <typeparam name="T">This <see cref="Type"/> this handler is for.</typeparam>
public
abstract
class
StringTypeHandler
<
T
>
:
TypeHandler
<
T
>
public
abstract
class
StringTypeHandler
<
T
>
:
TypeHandler
<
T
>
{
{
/// <summary>
/// <summary>
/// Parse a string into the expected type (the string will never be null)
/// Parse a string into the expected type (the string will never be null)
/// </summary>
/// </summary>
/// <param name="xml">The string to parse.</param>
protected
abstract
T
Parse
(
string
xml
);
protected
abstract
T
Parse
(
string
xml
);
/// <summary>
/// <summary>
/// Format an instace into a string (the instance will never be null)
/// Format an instace into a string (the instance will never be null)
/// </summary>
/// </summary>
/// <param name="xml">The string to format.</param>
protected
abstract
string
Format
(
T
xml
);
protected
abstract
string
Format
(
T
xml
);
/// <summary>
/// <summary>
/// Assign the value of a parameter before a command executes
/// Assign the value of a parameter before a command executes
/// </summary>
/// </summary>
...
@@ -63,6 +70,7 @@ public override void SetValue(IDbDataParameter parameter, T value)
...
@@ -63,6 +70,7 @@ public override void SetValue(IDbDataParameter parameter, T value)
{
{
parameter
.
Value
=
value
==
null
?
(
object
)
DBNull
.
Value
:
Format
(
value
);
parameter
.
Value
=
value
==
null
?
(
object
)
DBNull
.
Value
:
Format
(
value
);
}
}
/// <summary>
/// <summary>
/// Parse a database value back to a typed value
/// Parse a database value back to a typed value
/// </summary>
/// </summary>
...
...
Dapper/SqlMapper.TypeHandlerCache.cs
View file @
6745addf
...
@@ -9,6 +9,7 @@ public static partial class SqlMapper
...
@@ -9,6 +9,7 @@ public static partial class SqlMapper
/// <summary>
/// <summary>
/// Not intended for direct usage
/// Not intended for direct usage
/// </summary>
/// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !COREFX
#if !COREFX
[
Browsable
(
false
)]
[
Browsable
(
false
)]
...
@@ -17,22 +18,19 @@ public static partial class SqlMapper
...
@@ -17,22 +18,19 @@ public static partial class SqlMapper
public
static
class
TypeHandlerCache
<
T
>
public
static
class
TypeHandlerCache
<
T
>
{
{
/// <summary>
/// <summary>
/// Not intended for direct usage
/// Not intended for direct usage
.
/// </summary>
/// </summary>
/// <param name="value">The object to parse.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
public
static
T
Parse
(
object
value
)
public
static
T
Parse
(
object
value
)
=>
(
T
)
handler
.
Parse
(
typeof
(
T
),
value
);
{
return
(
T
)
handler
.
Parse
(
typeof
(
T
),
value
);
}
/// <summary>
/// <summary>
/// Not intended for direct usage
/// Not intended for direct usage
.
/// </summary>
/// </summary>
/// <param name="parameter">The parameter to set a value for.</param>
/// <param name="value">The value to set.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
public
static
void
SetValue
(
IDbDataParameter
parameter
,
object
value
)
public
static
void
SetValue
(
IDbDataParameter
parameter
,
object
value
)
=>
handler
.
SetValue
(
parameter
,
value
);
{
handler
.
SetValue
(
parameter
,
value
);
}
internal
static
void
SetHandler
(
ITypeHandler
handler
)
internal
static
void
SetHandler
(
ITypeHandler
handler
)
{
{
...
...
Dapper/TableValuedParameter.cs
View file @
6745addf
...
@@ -14,12 +14,16 @@ internal sealed class TableValuedParameter : SqlMapper.ICustomQueryParameter
...
@@ -14,12 +14,16 @@ internal sealed class TableValuedParameter : SqlMapper.ICustomQueryParameter
private
readonly
string
typeName
;
private
readonly
string
typeName
;
/// <summary>
/// <summary>
/// Create a new instance of
TableValuedParameter
/// Create a new instance of
<see cref="TableValuedParameter"/>.
/// </summary>
/// </summary>
public
TableValuedParameter
(
DataTable
table
)
:
this
(
table
,
null
)
{
}
/// <param name="table">The <see cref="DataTable"/> to create this parameter for</param>
public
TableValuedParameter
(
DataTable
table
)
:
this
(
table
,
null
)
{
/* run base */
}
/// <summary>
/// <summary>
/// Create a new instance of
TableValuedParameter
/// Create a new instance of
<see cref="TableValuedParameter"/>.
/// </summary>
/// </summary>
/// <param name="table">The <see cref="DataTable"/> to create this parameter for.</param>
/// <param name="typeName">The name of the type this parameter is for.</param>
public
TableValuedParameter
(
DataTable
table
,
string
typeName
)
public
TableValuedParameter
(
DataTable
table
,
string
typeName
)
{
{
this
.
table
=
table
;
this
.
table
=
table
;
...
@@ -54,13 +58,10 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
...
@@ -54,13 +58,10 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
{
{
typeName
=
table
.
GetTypeName
();
typeName
=
table
.
GetTypeName
();
}
}
if
(!
string
.
IsNullOrEmpty
(
typeName
))
if
(!
string
.
IsNullOrEmpty
(
typeName
)
&&
(
parameter
is
System
.
Data
.
SqlClient
.
SqlParameter
sqlParam
)
)
{
{
if
(
parameter
is
System
.
Data
.
SqlClient
.
SqlParameter
sqlParam
)
setTypeName
?.
Invoke
(
sqlParam
,
typeName
);
{
sqlParam
.
SqlDbType
=
SqlDbType
.
Structured
;
setTypeName
?.
Invoke
(
sqlParam
,
typeName
);
sqlParam
.
SqlDbType
=
SqlDbType
.
Structured
;
}
}
}
}
}
}
}
...
...
Dapper/UdtTypeHandler.cs
View file @
6745addf
...
@@ -14,8 +14,9 @@ public class UdtTypeHandler : ITypeHandler
...
@@ -14,8 +14,9 @@ public class UdtTypeHandler : ITypeHandler
{
{
private
readonly
string
udtTypeName
;
private
readonly
string
udtTypeName
;
/// <summary>
/// <summary>
/// Creates a new instance of UdtTypeHandler with the specified
UdtTypeName
/// Creates a new instance of UdtTypeHandler with the specified
<see cref="UdtTypeHandler"/>.
/// </summary>
/// </summary>
/// <param name="udtTypeName">The user defined type name.</param>
public
UdtTypeHandler
(
string
udtTypeName
)
public
UdtTypeHandler
(
string
udtTypeName
)
{
{
if
(
string
.
IsNullOrEmpty
(
udtTypeName
))
throw
new
ArgumentException
(
"Cannot be null or empty"
,
udtTypeName
);
if
(
string
.
IsNullOrEmpty
(
udtTypeName
))
throw
new
ArgumentException
(
"Cannot be null or empty"
,
udtTypeName
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment