Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapper
提交
be034083
D
Dapper
项目概览
int
/
Dapper
11 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapper
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be034083
编写于
7月 19, 2011
作者:
S
Sam Saffron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix for crazy multi mapping ... backwards compatible - allow for the Split to be in the first type.
上级
aa98265b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
19 deletion
+94
-19
Dapper/SqlMapper.cs
Dapper/SqlMapper.cs
+69
-19
Tests/Tests.cs
Tests/Tests.cs
+25
-0
未找到文件。
Dapper/SqlMapper.cs
浏览文件 @
be034083
...
...
@@ -504,21 +504,54 @@ class DontMap { }
var
splits
=
splitOn
.
Split
(
','
).
ToArray
();
var
splitIndex
=
0
;
Func
<
int
>
nextSplit
=
()
=>
Func
<
Type
,
int
>
nextSplit
=
type
=>
{
var
currentSplit
=
splits
[
splitIndex
];
if
(
splits
.
Length
>
splitIndex
+
1
)
{
splitIndex
++;
}
bool
skipFirst
=
false
;
int
startingPos
=
current
+
1
;
// if our current type has the split, skip the first time you see it.
if
(
type
!=
typeof
(
Object
))
{
var
props
=
GetSettableProps
(
type
);
var
fields
=
GetSettableFields
(
type
);
foreach
(
var
name
in
props
.
Select
(
p
=>
p
.
Name
).
Concat
(
fields
.
Select
(
f
=>
f
.
Name
)))
{
if
(
string
.
Equals
(
name
,
currentSplit
,
StringComparison
.
OrdinalIgnoreCase
))
{
skipFirst
=
true
;
startingPos
=
current
;
break
;
}
}
}
int
pos
;
for
(
pos
=
current
+
1
;
pos
<
reader
.
FieldCount
;
pos
++)
for
(
pos
=
startingPos
;
pos
<
reader
.
FieldCount
;
pos
++)
{
// some people like ID some id ... assuming case insensitive splits for now
if
(
splitOn
==
"*"
||
string
.
Equals
(
reader
.
GetName
(
pos
),
currentSplit
,
StringComparison
.
OrdinalIgnoreCase
)
)
if
(
splitOn
==
"*"
)
{
break
;
}
if
(
string
.
Equals
(
reader
.
GetName
(
pos
),
currentSplit
,
StringComparison
.
OrdinalIgnoreCase
))
{
if
(
skipFirst
)
{
skipFirst
=
false
;
}
else
{
break
;
}
}
}
current
=
pos
;
return
pos
;
...
...
@@ -526,30 +559,30 @@ class DontMap { }
var
otherDeserializer
=
new
List
<
object
>();
int
split
=
nextSplit
();
int
split
=
nextSplit
(
typeof
(
TFirst
)
);
deserializer
=
cinfo
.
Deserializer
=
GetDeserializer
<
TFirst
>(
reader
,
0
,
split
,
false
);
if
(
typeof
(
TSecond
)
!=
typeof
(
DontMap
))
{
var
next
=
nextSplit
();
var
next
=
nextSplit
(
typeof
(
TSecond
)
);
otherDeserializer
.
Add
(
GetDeserializer
<
TSecond
>(
reader
,
split
,
next
-
split
,
true
));
split
=
next
;
}
if
(
typeof
(
TThird
)
!=
typeof
(
DontMap
))
{
var
next
=
nextSplit
();
var
next
=
nextSplit
(
typeof
(
TThird
)
);
otherDeserializer
.
Add
(
GetDeserializer
<
TThird
>(
reader
,
split
,
next
-
split
,
true
));
split
=
next
;
}
if
(
typeof
(
TFourth
)
!=
typeof
(
DontMap
))
{
var
next
=
nextSplit
();
var
next
=
nextSplit
(
typeof
(
TFourth
)
);
otherDeserializer
.
Add
(
GetDeserializer
<
TFourth
>(
reader
,
split
,
next
-
split
,
true
));
split
=
next
;
}
if
(
typeof
(
TFifth
)
!=
typeof
(
DontMap
))
{
var
next
=
nextSplit
();
var
next
=
nextSplit
(
typeof
(
TFifth
)
);
otherDeserializer
.
Add
(
GetDeserializer
<
TFifth
>(
reader
,
split
,
next
-
split
,
true
));
}
...
...
@@ -1117,6 +1150,32 @@ static readonly MethodInfo
.
Where
(
p
=>
p
.
GetIndexParameters
().
Any
()
&&
p
.
GetIndexParameters
()[
0
].
ParameterType
==
typeof
(
int
))
.
Select
(
p
=>
p
.
GetGetMethod
()).
First
();
class
PropInfo
{
public
string
Name
{
get
;
set
;
}
public
MethodInfo
Setter
{
get
;
set
;
}
public
Type
Type
{
get
;
set
;
}
}
static
List
<
PropInfo
>
GetSettableProps
(
Type
t
)
{
return
t
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Select
(
p
=>
new
PropInfo
{
Name
=
p
.
Name
,
Setter
=
p
.
DeclaringType
==
t
?
p
.
GetSetMethod
(
true
)
:
p
.
DeclaringType
.
GetProperty
(
p
.
Name
).
GetSetMethod
(
true
),
Type
=
p
.
PropertyType
})
.
Where
(
info
=>
info
.
Setter
!=
null
)
.
ToList
();
}
static
List
<
FieldInfo
>
GetSettableFields
(
Type
t
)
{
return
t
.
GetFields
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
).
ToList
();
}
public
static
Func
<
IDataReader
,
T
>
GetClassDeserializer
<
T
>(
#if CSHARP30
IDataReader
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
...
...
@@ -1133,17 +1192,8 @@ static readonly MethodInfo
bool
haveEnumLocal
=
false
;
il
.
Emit
(
OpCodes
.
Ldc_I4_0
);
il
.
Emit
(
OpCodes
.
Stloc_0
);
var
properties
=
typeof
(
T
)
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Select
(
p
=>
new
{
p
.
Name
,
Setter
=
p
.
DeclaringType
==
typeof
(
T
)
?
p
.
GetSetMethod
(
true
)
:
p
.
DeclaringType
.
GetProperty
(
p
.
Name
).
GetSetMethod
(
true
),
Type
=
p
.
PropertyType
})
.
Where
(
info
=>
info
.
Setter
!=
null
)
.
ToList
();
var
fields
=
typeof
(
T
).
GetFields
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
);
var
properties
=
GetSettableProps
(
typeof
(
T
));
var
fields
=
GetSettableFields
(
typeof
(
T
));
if
(
length
==
-
1
)
{
length
=
reader
.
FieldCount
-
startBound
;
...
...
Tests/Tests.cs
浏览文件 @
be034083
...
...
@@ -1036,5 +1036,30 @@ public void TestDynamicParamNullSupport()
p
.
Get
<
int
?>(
"@b"
).
IsNull
();
}
class
Foo1
{
public
int
Id
;
public
int
BarId
{
get
;
set
;
}
}
class
Bar1
{
public
int
BarId
;
public
string
Name
{
get
;
set
;
}
}
public
void
TestMultiMapperIsNotConfusedWithUnorderedCols
()
{
var
result
=
connection
.
Query
<
Foo1
,
Bar1
,
Tuple
<
Foo1
,
Bar1
>>(
"select 1 as Id, 2 as BarId, 3 as BarId, 'a' as Name"
,
(
f
,
b
)
=>
Tuple
.
Create
(
f
,
b
),
splitOn
:
"BarId"
).
First
();
result
.
Item1
.
Id
.
IsEqualTo
(
1
);
result
.
Item1
.
BarId
.
IsEqualTo
(
2
);
result
.
Item2
.
BarId
.
IsEqualTo
(
3
);
result
.
Item2
.
Name
.
IsEqualTo
(
"a"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录