-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extension.cs
171 lines (145 loc) · 4.03 KB
/
Extension.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//using BotEngine.Common;
//using BotEngine.Motor;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using Sanderling.Interface.MemoryStruct;
//using Bib3.Geometrik;
//using Bib3;
//using BotEngine.Windows;
using static BotEngine;
namespace Sanderling.Motor
{
static public class Extension
{
//这个函数我不会还原
//static public bool WhereNotDefault<T>(mvar<u1> element)
//{
// var defaultValue = default(mvar<u1>);
// return !object.Equals(defaultValue, element);
//}
static public Vektor2DInt? ClientToScreen(this IntPtr hWnd, Vektor2DInt locationInClient)
{
var structWinApi = locationInClient.AsWindowsPoint();
if (!WinApi.ClientToScreen(hWnd, ref structWinApi))
return null;
return locationInClient;
}
static public IDictionary<KeyT, ValueT> ToDictionary<KeyT, ValueT>(
this IEnumerable<KeyValuePair<KeyT, ValueT>> source)
{
if (null == source)
{
return null;
}
return source.ToDictionary(t => t.Key, t => t.Value);
}
static public IDictionary<KeyT, ValueT[]> ToDictionary<KeyT, ValueT>(
this IEnumerable<IGrouping<KeyT, ValueT>> source)
{
if (null == source)
{
return null;
}
return
source.Select(group => new KeyValuePair<KeyT, ValueT[]>(group.Key, group.ToArray()))
.ToDictionary();
}
public static IEnumerable<T> ConcatNullable<T>(
IEnumerable<IEnumerable<T>> Liste)
{
if (null == Liste)
{
yield break;
}
foreach (var item in Liste)
{
if (null == item)
{
continue;
}
foreach (var item1 in item)
{
yield return item1;
}
}
}
public static IEnumerable<T> ConcatNullable<T>(
IEnumerable<T> Liste0,
IEnumerable<T> Liste1)
{
if (null == Liste0)
{
return Liste1;
}
if (null == Liste1)
{
return Liste0;
}
return Liste0.Concat(Liste1);
}
public static IEnumerable<T> ConcatNullable2<T>(this IEnumerable<IEnumerable<T>> seq)
{
foreach (var item in seq)
{
if (item != null)
{
foreach (var subItem in item)
{
yield return subItem;
}
}
}
}
public static TValue TryGetValueOrDefault<TKey, TValue>(
this IDictionary<TKey, TValue> Dict,
TKey Key)
{
if (null != Dict)
{
TValue Value;
if (Dict.TryGetValue(Key, out Value))
{
return Value;
}
}
return default;
}
static public void ForEach<T>(
this IEnumerable<T> Menge,
Action<T, int> Aktioon)
{
if (null == Menge)
{
return;
}
if (null == Aktioon)
{
return;
}
int ElementIndex = 0;
foreach (var item in Menge)
{
Aktioon(item, ElementIndex);
++ElementIndex;
}
}
static public void ForEach<T>(
this IEnumerable<T> Menge,
Action<T> Aktioon)
{
if (null == Menge)
{
return;
}
if (null == Aktioon)
{
return;
}
foreach (var item in Menge)
{
Aktioon(item);
}
}
}
}