6
6
7
7
using System ;
8
8
using System . Collections . Generic ;
9
- using System . IO ;
10
9
using System . Linq ;
11
- using System . Reflection ;
10
+ using System . Text ;
12
11
using System . Windows . Forms ;
13
- using System . Xml . Linq ;
14
- using System . Xml . Schema ;
15
- using Z . Reflection . Documentation . Test ;
16
12
17
13
namespace Z . ExtensionMethods . Lab
18
14
{
15
+ public static class LabExtension
16
+ {
17
+ public static IEnumerable < T > MergeInnerEnumerable < T > ( this IEnumerable < IEnumerable < T > > @this )
18
+ {
19
+ List < IEnumerable < T > > listItem = @this . ToList ( ) ;
20
+
21
+ var list = new List < T > ( ) ;
22
+
23
+ foreach ( var item in listItem )
24
+ {
25
+ list . AddRange ( item ) ;
26
+ }
27
+
28
+ return list ;
29
+ }
30
+
31
+ public static IEnumerable < T > MergeDistinctInnerEnumerable < T > ( this IEnumerable < IEnumerable < T > > @this )
32
+ {
33
+ List < IEnumerable < T > > listItem = @this . ToList ( ) ;
34
+
35
+ var list = new List < T > ( ) ;
36
+
37
+ foreach ( var item in listItem )
38
+ {
39
+ list = list . Union ( item ) . ToList ( ) ;
40
+ }
41
+
42
+ return list ;
43
+ }
44
+
45
+ public static string StripHtml ( this string @this )
46
+ {
47
+ var path = new StringBuilder ( @this ) ;
48
+ var sb = new StringBuilder ( ) ;
49
+
50
+ int pos = 0 ;
51
+
52
+ while ( pos < path . Length )
53
+ {
54
+ char ch = path [ pos ] ;
55
+ pos ++ ;
56
+
57
+ if ( ch == '<' )
58
+ {
59
+ // Loop until we close the tag
60
+ while ( pos < path . Length )
61
+ {
62
+ ch = path [ pos ] ;
63
+ pos ++ ;
64
+
65
+ if ( ch == '>' )
66
+ {
67
+ break ;
68
+ }
69
+
70
+ if ( ch == '\' ' )
71
+ {
72
+ // Skip attribute starting with single quote
73
+ pos = GetIndexAfterNextSingleQuote ( path , pos ) ;
74
+ }
75
+ else if ( ch == '"' )
76
+ {
77
+ // Skip attribute starting with double quote
78
+ pos = GetIndexAfterNextDoubleQuote ( path , pos ) ;
79
+ }
80
+ }
81
+ }
82
+ else
83
+ {
84
+ sb . Append ( ch ) ;
85
+ }
86
+ }
87
+
88
+ return sb . ToString ( ) ;
89
+ }
90
+
91
+ public static string Substring ( StringBuilder @this , int startIndex )
92
+ {
93
+ return @this . ToString ( startIndex , @this . Length - startIndex ) ;
94
+ }
95
+
96
+ public static string Substring ( StringBuilder @this , int startIndex , int length )
97
+ {
98
+ return @this . ToString ( startIndex , length ) ;
99
+ }
100
+
101
+
102
+ public static int StripHtml_EndTag ( this StringBuilder path , int pos )
103
+ {
104
+ return pos ;
105
+ }
106
+ public static int GetIndexAfterNextSingleQuote ( StringBuilder path , int startIndex )
107
+ {
108
+ while ( startIndex < path . Length )
109
+ {
110
+ char ch = path [ startIndex ] ;
111
+ startIndex ++ ;
112
+
113
+ char nextChar ;
114
+ if ( ch == '\\ ' && startIndex < path . Length && ( ( nextChar = path [ startIndex ] ) == '\\ ' || nextChar == '\' ' ) )
115
+ {
116
+ startIndex ++ ; // Treat as escape character for \\ or \"
117
+ }
118
+ else if ( ch == '\' ' )
119
+ {
120
+ return startIndex ;
121
+ }
122
+ }
123
+
124
+ return startIndex ;
125
+ }
126
+
127
+ public static int GetIndexAfterNextDoubleQuote ( StringBuilder path , int startIndex )
128
+ {
129
+ while ( startIndex < path . Length )
130
+ {
131
+ char ch = path [ startIndex ] ;
132
+ startIndex ++ ;
133
+
134
+ char nextChar ;
135
+ if ( ch == '\\ ' && startIndex < path . Length && ( ( nextChar = path [ startIndex ] ) == '\\ ' || nextChar == '"' ) )
136
+ {
137
+ startIndex ++ ; // Treat as escape character for \\ or \"
138
+ }
139
+ else if ( ch == '"' )
140
+ {
141
+ return startIndex ;
142
+ }
143
+ }
144
+
145
+ return startIndex ;
146
+ }
147
+ }
148
+
19
149
public partial class Form1 : Form
20
150
{
21
151
public Form1 ( )
22
152
{
23
153
InitializeComponent ( ) ;
24
-
25
- //var entityMembers = typeof (Entity).GetMembers();
26
- // var list1 = entityMembers.Select(x => x.GetSignature()).ToList();
27
- // var list2 = entityMembers.Select(x => x.GetDeclaration()).ToList();
28
- // var list3 = entityMembers.Select(x => x.GetMemberName()).ToList();
29
-
30
- // object a = null;
31
- // string b = "";
32
- // MethodBase mi = MethodBase.GetCurrentMethod();
33
- // MethodInfo serialize2 = typeof (MethodInfo).GetMethod("FormatNameAndSig", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof (bool)}, null);
34
- // //MethodInfo serialize = typeof (MethodInfo).GetMethod("FormatNameAndSig", BindingFlags.NonPublic | BindingFlags.Instance);
35
-
36
- // MethodInfo[] methods = typeof (Entity).GetMethods();
37
- // MethodInfo abc = methods[0];
38
-
39
- // var serialize = serialize2.Invoke(abc, new[] {(object) true});
40
- // MethodInfo test1 = abc.GetRuntimeBaseDefinition();
41
- // string assemblyDirectory = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1";
42
-
43
- // FileInfo dll = assemblyDirectory.ToDirectoryInfo().GetFiles("System.Core.dll")[0];
44
- // FileInfo xml = assemblyDirectory.ToDirectoryInfo().GetFiles("System.Core.xml")[0];
45
-
46
-
47
- // Assembly assembly = Assembly.UnsafeLoadFrom(dll.FullName);
48
-
49
- // XDocument xDoc = XDocument.Load(xml.FullName);
50
- // IEnumerable<XElement> members = xDoc.Element("doc").Element("members").Elements("member");
51
-
52
- // Dictionary<string, string> dict = members.Select(x => x.Attribute("name").Value).ToDictionary(x => x);
53
-
54
-
55
- // Type[] types = assembly.GetTypes();
56
- // List<string> memberNames = types.SelectMany(x => x.GetMembers()).Select(x => x.GetMemberName()).OrderBy(x => x).ToList();
57
- // List<string> typeNames = types.Select(x => x.GetMemberName()).ToList();
58
-
59
- // typeNames.ForEach(x =>
60
- // {
61
- // if (dict.ContainsKey(x))
62
- // {
63
- // dict.Remove(x);
64
- // }
65
- // });
66
- // memberNames.ForEach(x =>
67
- // {
68
- // if (dict.ContainsKey(x))
69
- // {
70
- // dict.Remove(x);
71
- // }
72
- // });
73
-
74
- // var missingTypes = dict.Where(x => x.Value.StartsWith("T:")).ToList();
75
- // var missingProperty = dict.Where(x => x.Value.StartsWith("P:") && !x.Value.Contains("#")).ToList();
76
- // var missingField = dict.Where(x => x.Value.StartsWith("F:")).ToList();
77
- // var missingEvent = dict.Where(x => x.Value.StartsWith("E:")).ToList();
78
- // var missingMethod = dict.Where(x => x.Value.StartsWith("M:")).ToList();
79
- // List<string> toVerify = memberNames.Where(x => x.StartsWith("P:System.Runtime.CompilerServices")).OrderBy(x => x).ToList();
80
-
81
-
154
+
155
+ StringBuilder sb = new StringBuilder ( "0123456789" ) ;
156
+ var b4 = "abc" . Substring ( 1 , 4 ) ;
157
+ char ch = '\' ' ;
158
+ char ch2 = '"' ;
159
+ string tag = "a<b class='to>to'>c</b>d" ;
160
+ string tag2 = tag . StripHtml ( ) ;
161
+ var a = new [ ] { "a" , "b" , "c" } ;
162
+ var b = new [ ] { "c" , "d" } ;
163
+
164
+ var c = new List < String [ ] > { a , b } ;
165
+ IEnumerable < string > d = c . MergeInnerEnumerable ( ) ;
166
+ }
167
+
168
+ public void Misc ( )
169
+ {
170
+ // object a = null;
171
+ // string b = "";
172
+ // MethodBase mi = MethodBase.GetCurrentMethod();
173
+ // MethodInfo serialize2 = typeof (MethodInfo).GetMethod("FormatNameAndSig", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof (bool)}, null);
174
+ // //MethodInfo serialize = typeof (MethodInfo).GetMethod("FormatNameAndSig", BindingFlags.NonPublic | BindingFlags.Instance);
175
+
176
+ // MethodInfo[] methods = typeof (Entity).GetMethods();
177
+ // MethodInfo abc = methods[0];
178
+
179
+ // var serialize = serialize2.Invoke(abc, new[] {(object) true});
180
+ // MethodInfo test1 = abc.GetRuntimeBaseDefinition();
181
+ // string assemblyDirectory = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1";
182
+
183
+ // FileInfo dll = assemblyDirectory.ToDirectoryInfo().GetFiles("System.Core.dll")[0];
184
+ // FileInfo xml = assemblyDirectory.ToDirectoryInfo().GetFiles("System.Core.xml")[0];
185
+
186
+
187
+ // Assembly assembly = Assembly.UnsafeLoadFrom(dll.FullName);
188
+
189
+ // XDocument xDoc = XDocument.Load(xml.FullName);
190
+ // IEnumerable<XElement> members = xDoc.Element("doc").Element("members").Elements("member");
191
+
192
+ // Dictionary<string, string> dict = members.Select(x => x.Attribute("name").Value).ToDictionary(x => x);
193
+
194
+
195
+ // Type[] types = assembly.GetTypes();
196
+ // List<string> memberNames = types.SelectMany(x => x.GetMembers()).Select(x => x.GetMemberName()).OrderBy(x => x).ToList();
197
+ // List<string> typeNames = types.Select(x => x.GetMemberName()).ToList();
198
+
199
+ // typeNames.ForEach(x =>
200
+ // {
201
+ // if (dict.ContainsKey(x))
202
+ // {
203
+ // dict.Remove(x);
204
+ // }
205
+ // });
206
+ // memberNames.ForEach(x =>
207
+ // {
208
+ // if (dict.ContainsKey(x))
209
+ // {
210
+ // dict.Remove(x);
211
+ // }
212
+ // });
213
+
214
+ // var missingTypes = dict.Where(x => x.Value.StartsWith("T:")).ToList();
215
+ // var missingProperty = dict.Where(x => x.Value.StartsWith("P:") && !x.Value.Contains("#")).ToList();
216
+ // var missingField = dict.Where(x => x.Value.StartsWith("F:")).ToList();
217
+ // var missingEvent = dict.Where(x => x.Value.StartsWith("E:")).ToList();
218
+ // var missingMethod = dict.Where(x => x.Value.StartsWith("M:")).ToList();
219
+ // List<string> toVerify = memberNames.Where(x => x.StartsWith("P:System.Runtime.CompilerServices")).OrderBy(x => x).ToList();
82
220
}
83
221
}
84
222
}
0 commit comments