forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinderHelper.cs
More file actions
55 lines (48 loc) · 2.27 KB
/
BinderHelper.cs
File metadata and controls
55 lines (48 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using Simple.Data.Extensions;
namespace Simple.Data
{
static class BinderHelper
{
private static IDictionary<string, object> NamedArgumentsToDictionary(IEnumerable<string> argumentNames, IEnumerable<object> args)
{
return argumentNames
.Reverse()
.Zip(args.Reverse(), (k, v) => new KeyValuePair<string, object>(k, v))
.Reverse()
.ToDictionary(StringComparer.InvariantCultureIgnoreCase);
}
private static IDictionary<string, object> ArgumentsToDictionary(IEnumerable<String> argumentNames, IEnumerable<object> args)
{
var argsArray = args.ToArray();
if (argsArray.Length == 1 && argsArray[0] is IDictionary<string, object>)
return (IDictionary<string, object>)argsArray[0];
return argsArray.Reverse()
.Zip(argumentNames.Reverse().ExtendInfinite(), (v, k) => new KeyValuePair<string, object>(k, v))
.Reverse()
.Select((kvp, i) => kvp.Key == null ? new KeyValuePair<string, object>("_" + i.ToString(), kvp.Value ?? DBNull.Value) : kvp)
.ToDictionary(StringComparer.InvariantCultureIgnoreCase);
}
internal static IDictionary<string, object> NamedArgumentsToDictionary(this InvokeMemberBinder binder, IEnumerable<object> args)
{
return NamedArgumentsToDictionary(binder.CallInfo.ArgumentNames, args);
}
public static IDictionary<string, object> ArgumentsToDictionary(this InvokeMemberBinder binder, IEnumerable<object> args)
{
return ArgumentsToDictionary(binder.CallInfo.ArgumentNames, args);
}
internal static IDictionary<string, object> NamedArgumentsToDictionary(this InvokeBinder binder, IEnumerable<object> args)
{
return NamedArgumentsToDictionary(binder.CallInfo.ArgumentNames, args);
}
public static IDictionary<string, object> ArgumentsToDictionary(this InvokeBinder binder, IEnumerable<object> args)
{
return ArgumentsToDictionary(binder.CallInfo.ArgumentNames, args);
}
}
}