-
Notifications
You must be signed in to change notification settings - Fork 25
/
SymbolsFunctions.cs
177 lines (152 loc) · 6.36 KB
/
SymbolsFunctions.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
172
173
174
175
176
177
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace NTypewriter.CodeModel.Functions
{
/// <summary>
/// Set of filters that operates on IEnumerable<ISymbolBase>
/// </summary>
public static class SymbolsFunctions
{
/// <summary>
/// Filters symbols by the beginning of their namespace
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceStartsWith(this IEnumerable<ISymbolBase> symbols, string prefix)
{
var result = symbols.Where(x => x.Namespace.StartsWith(prefix));
return result;
}
/// <summary>
/// Filters symbols by the beginning of their namespace
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceDoesNotStartWith(this IEnumerable<ISymbolBase> symbols, string prefix)
{
var result = symbols.Where(x => !x.Namespace.StartsWith(prefix));
return result;
}
/// <summary>
/// Filters symbols by the end of their namespace
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceEndsWith(this IEnumerable<ISymbolBase> symbols, string postfix)
{
var result = symbols.Where(x => x.Namespace.EndsWith(postfix));
return result;
}
/// <summary>
/// Filters symbols by the end of their namespace
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceDoesNotEndWith(this IEnumerable<ISymbolBase> symbols, string postfix)
{
var result = symbols.Where(x => !x.Namespace.EndsWith(postfix));
return result;
}
/// <summary>
/// Filters symbols by regex pattern
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceMatches(this IEnumerable<ISymbolBase> symbols, string pattern)
{
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled);
var result = symbols.Where(x => regex.IsMatch(x.Namespace));
return result;
}
/// <summary>
/// Filters symbols by regex pattern
/// </summary>
public static IEnumerable<ISymbolBase> WhereNamespaceDoesNotMatch(this IEnumerable<ISymbolBase> symbols, string pattern)
{
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled);
var result = symbols.Where(x => !regex.IsMatch(x.Namespace));
return result;
}
/// <summary>
/// Filters symbols by the beginning of their name
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameStartsWith(this IEnumerable<ISymbolBase> symbols, string prefix)
{
var result = symbols.Where(x => x.BareName.StartsWith(prefix));
return result;
}
/// <summary>
/// Filters symbols by the beginning of their name
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameDoesNotStartWith(this IEnumerable<ISymbolBase> symbols, string prefix)
{
var result = symbols.Where(x => !x.BareName.StartsWith(prefix));
return result;
}
/// <summary>
/// Filters symbols by the end of their name
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameEndsWith(this IEnumerable<ISymbolBase> symbols, string postfix)
{
var result = symbols.Where(x => x.BareName.EndsWith(postfix));
return result;
}
/// <summary>
/// Filters symbols by the end of their name
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameDoesNotEndWith(this IEnumerable<ISymbolBase> symbols, string postfix)
{
var result = symbols.Where(x => !x.BareName.EndsWith(postfix));
return result;
}
/// <summary>
/// Filters symbols by a regex pattern
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameMatches(this IEnumerable<ISymbolBase> symbols, string pattern)
{
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled);
var result = symbols.Where(x => regex.IsMatch(x.Name));
return result;
}
/// <summary>
/// Filters symbols by a regex pattern
/// </summary>
public static IEnumerable<ISymbolBase> WhereNameDoesNotMatch(this IEnumerable<ISymbolBase> symbols, string pattern)
{
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled);
var result = symbols.Where(x => !regex.IsMatch(x.Name));
return result;
}
/// <summary>
/// Filters symbols by the presence of an attribute
/// </summary>
public static IEnumerable<ISymbolBase> ThatHaveAttribute(this IEnumerable<ISymbolBase> symbols, string attributeName)
{
var result = symbols.Where(x => x.Attributes.Any(y => y.Name == attributeName));
return result;
}
/// <summary>
/// Filters symbols by the absence of an attribute
/// </summary>
public static IEnumerable<ISymbolBase> ThatDoNotHaveAttribute(this IEnumerable<ISymbolBase> symbols, string attributeName)
{
var result = symbols.Where(x => !x.Attributes.Any(y => y.Name == attributeName));
return result;
}
/// <summary>
/// Filters symbols by the public access modifier
/// </summary>
public static IEnumerable<ISymbolBase> ThatArePublic(this IEnumerable<ISymbolBase> symbols)
{
var result = symbols.Where(x => x.IsPublic);
return result;
}
/// <summary>
/// Filters symbols by the static modifier
/// </summary>
public static IEnumerable<ISymbolBase> ThatAreStatic(this IEnumerable<ISymbolBase> symbols)
{
var result = symbols.Where(x => x.IsStatic);
return result;
}
/// <summary>
/// Filters symbols by the static modifier
/// </summary>
public static IEnumerable<ISymbolBase> ThatAreNotStatic(this IEnumerable<ISymbolBase> symbols)
{
var result = symbols.Where(x => !x.IsStatic);
return result;
}
}
}