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
8aa10a02
Commit
8aa10a02
authored
Nov 05, 2016
by
hwikene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SqlMapper.RemoveTypeMap() method
parent
a155ebb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
Tests.cs
Dapper.Tests/Tests.cs
+46
-0
SqlMapper.cs
Dapper/SqlMapper.cs
+16
-0
No files found.
Dapper.Tests/Tests.cs
View file @
8aa10a02
...
...
@@ -2484,6 +2484,52 @@ public void Issue253_TestIEnumerableTypeHandlerSetParameterValue()
}
}
public
class
RecordingTypeHandler
<
T
>
:
Dapper
.
SqlMapper
.
TypeHandler
<
T
>
{
public
override
void
SetValue
(
IDbDataParameter
parameter
,
T
value
)
{
SetValueWasCalled
=
true
;
parameter
.
Value
=
value
;
}
public
override
T
Parse
(
object
value
)
{
ParseWasCalled
=
true
;
return
(
T
)
value
;
}
public
bool
SetValueWasCalled
{
get
;
set
;
}
public
bool
ParseWasCalled
{
get
;
set
;
}
}
[
Fact
]
public
void
Test_RemoveTypeMap
()
{
Dapper
.
SqlMapper
.
ResetTypeHandlers
();
Dapper
.
SqlMapper
.
RemoveTypeMap
(
typeof
(
DateTime
));
var
dateTimeHandler
=
new
RecordingTypeHandler
<
DateTime
>();
Dapper
.
SqlMapper
.
AddTypeHandler
(
dateTimeHandler
);
connection
.
Execute
(
"CREATE TABLE #Test_RemoveTypeMap (x datetime NOT NULL);"
);
try
{
connection
.
Execute
(
@"INSERT INTO #Test_RemoveTypeMap VALUES (@Now)"
,
new
{
DateTime
.
Now
});
connection
.
Query
<
DateTime
>(
"SELECT * FROM #Test_RemoveTypeMap"
);
dateTimeHandler
.
ParseWasCalled
.
IsTrue
();
dateTimeHandler
.
SetValueWasCalled
.
IsTrue
();
}
finally
{
connection
.
Execute
(
"DROP TABLE #Test_RemoveTypeMap"
);
Dapper
.
SqlMapper
.
AddTypeMap
(
typeof
(
DateTime
),
DbType
.
DateTime
);
// or an option to reset type map?
}
}
[
Fact
]
public
void
Issue130_IConvertible
()
{
...
...
Dapper/SqlMapper.cs
View file @
8aa10a02
...
...
@@ -260,6 +260,22 @@ public static void AddTypeMap(Type type, DbType dbType)
typeMap
=
newCopy
;
}
/// <summary>
/// Removes the specified type from the Type/DbType mapping table
/// </summary>
public
static
void
RemoveTypeMap
(
Type
type
)
{
// use clone, mutate, replace to avoid threading issues
var
snapshot
=
typeMap
;
if
(!
snapshot
.
ContainsKey
(
type
))
return
;
// nothing to do
var
newCopy
=
new
Dictionary
<
Type
,
DbType
>(
snapshot
);
newCopy
.
Remove
(
type
);
typeMap
=
newCopy
;
}
/// <summary>
/// Configure the specified type to be processed by a custom handler
/// </summary>
...
...
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