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
88766056
Commit
88766056
authored
Jun 10, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ISupportInitialize support
parent
f5ae8e67
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+12
-0
Tests.cs
Tests/Tests.cs
+23
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
88766056
...
@@ -2850,6 +2850,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
...
@@ -2850,6 +2850,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
ConstructorInfo
specializedConstructor
=
null
;
ConstructorInfo
specializedConstructor
=
null
;
bool
supportInitialize
=
false
;
if
(
type
.
IsValueType
)
if
(
type
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
...
@@ -2874,6 +2875,12 @@ public static void SetTypeMap(Type type, ITypeMap map)
...
@@ -2874,6 +2875,12 @@ public static void SetTypeMap(Type type, ITypeMap map)
{
{
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
"BeginInit"
),
null
);
}
}
}
else
else
specializedConstructor
=
ctor
;
specializedConstructor
=
ctor
;
...
@@ -3120,6 +3127,11 @@ public static void SetTypeMap(Type type, ITypeMap map)
...
@@ -3120,6 +3127,11 @@ public static void SetTypeMap(Type type, ITypeMap map)
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
}
}
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
"EndInit"
),
null
);
}
}
}
il
.
MarkLabel
(
allDone
);
il
.
MarkLabel
(
allDone
);
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
...
...
Tests/Tests.cs
View file @
88766056
...
@@ -2878,6 +2878,29 @@ public void DataTableParameters()
...
@@ -2878,6 +2878,29 @@ public void DataTableParameters()
}
}
}
}
public
void
SupportInit
()
{
var
obj
=
connection
.
Query
<
WithInit
>(
"select 'abc' as Value"
).
Single
();
obj
.
Value
.
Equals
(
"abc"
);
obj
.
Flags
.
Equals
(
31
);
}
class
WithInit
:
ISupportInitialize
{
public
string
Value
{
get
;
set
;
}
public
int
Flags
{
get
;
set
;
}
void
ISupportInitialize
.
BeginInit
()
{
Flags
+=
1
;
}
void
ISupportInitialize
.
EndInit
()
{
Flags
+=
30
;
}
}
#if POSTGRESQL
#if POSTGRESQL
class
Cat
class
Cat
...
...
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