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
1fff7b97
Commit
1fff7b97
authored
Aug 05, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed: Issue 165
parent
71bac1da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
7 deletions
+32
-7
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+32
-7
No files found.
Dapper NET40/SqlMapper.cs
View file @
1fff7b97
...
...
@@ -587,7 +587,7 @@ public static int GetCachedSQLCount()
#endif
static
readonly
Dictionary
<
Type
,
DbType
>
typeMap
;
static
Dictionary
<
Type
,
DbType
>
typeMap
;
static
SqlMapper
()
{
...
...
@@ -630,34 +630,59 @@ static SqlMapper()
typeMap
[
typeof
(
TimeSpan
?)]
=
DbType
.
Time
;
typeMap
[
typeof
(
object
)]
=
DbType
.
Object
;
AddTypeHandler
(
typeof
(
DataTable
),
new
DataTableHandler
()
);
AddTypeHandler
Impl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
false
);
}
/// <summary>
/// Configire the specified type to be mapped to a given db-type
/// </summary>
public
static
void
AddTypeMap
(
Type
type
,
DbType
dbType
)
{
typeMap
[
type
]
=
dbType
;
// use clone, mutate, replace to avoid threading issues
var
snapshot
=
typeMap
;
DbType
oldValue
;
if
(
snapshot
.
TryGetValue
(
type
,
out
oldValue
)
&&
oldValue
==
dbType
)
return
;
// nothing to do
var
newCopy
=
new
Dictionary
<
Type
,
DbType
>(
snapshot
);
newCopy
[
type
]
=
dbType
;
typeMap
=
newCopy
;
}
/// <summary>
/// Configire the specified type to be processed by a custom handler
/// </summary>
public
static
void
AddTypeHandler
(
Type
type
,
ITypeHandler
handler
)
{
AddTypeHandlerImpl
(
type
,
handler
,
true
);
}
/// <summary>
/// Configire the specified type to be processed by a custom handler
/// </summary>
public
static
void
AddTypeHandlerImpl
(
Type
type
,
ITypeHandler
handler
,
bool
clone
)
{
if
(
type
==
null
)
throw
new
ArgumentNullException
(
"type"
);
var
snapshot
=
typeHandlers
;
ITypeHandler
oldValue
;
if
(
snapshot
.
TryGetValue
(
type
,
out
oldValue
)
&&
handler
==
oldValue
)
return
;
// nothing to do
var
newCopy
=
clone
?
new
Dictionary
<
Type
,
ITypeHandler
>(
snapshot
)
:
snapshot
;
#pragma warning disable 618
typeof
(
TypeHandlerCache
<>).
MakeGenericType
(
type
).
GetMethod
(
"SetHandler"
,
BindingFlags
.
Static
|
BindingFlags
.
NonPublic
).
Invoke
(
null
,
new
object
[]
{
handler
});
#pragma warning restore 618
if
(
handler
==
null
)
typeHandlers
.
Remove
(
type
);
else
typeHandlers
[
type
]
=
handler
;
if
(
handler
==
null
)
newCopy
.
Remove
(
type
);
else
newCopy
[
type
]
=
handler
;
typeHandlers
=
newCopy
;
}
/// <summary>
/// Configire the specified type to be processed by a custom handler
/// </summary>
public
static
void
AddTypeHandler
<
T
>(
TypeHandler
<
T
>
handler
)
{
AddTypeHandler
(
typeof
(
T
),
handler
);
AddTypeHandler
Impl
(
typeof
(
T
),
handler
,
true
);
}
/// <summary>
...
...
@@ -696,7 +721,7 @@ internal static void SetHandler(ITypeHandler handler)
private
static
ITypeHandler
handler
;
}
private
static
readonly
Dictionary
<
Type
,
ITypeHandler
>
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
private
static
Dictionary
<
Type
,
ITypeHandler
>
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
internal
const
string
LinqBinary
=
"System.Data.Linq.Binary"
;
internal
static
DbType
LookupDbType
(
Type
type
,
string
name
,
out
ITypeHandler
handler
)
...
...
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