1+ // Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime.
2+ // Website: http://eval-expression.net/
3+ // Documentation: https://github.com/zzzprojects/Eval-Expression.NET/wiki
4+ // Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues
5+ // License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE
6+ // More projects: http://www.zzzprojects.com/
7+ // Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
8+
9+ using System ;
10+ using System . Collections ;
11+ using System . Collections . Generic ;
12+ using System . ComponentModel ;
13+ using System . Data ;
14+ using System . Data . Common ;
15+ using System . Data . SqlClient ;
16+ using System . Diagnostics ;
17+ using System . Diagnostics . Eventing ;
18+ using System . Diagnostics . Eventing . Reader ;
19+ using System . Diagnostics . PerformanceData ;
20+ using System . Dynamic ;
21+ using System . Globalization ;
22+ using System . IO ;
23+ using System . IO . Compression ;
24+ using System . IO . IsolatedStorage ;
25+ using System . IO . Pipes ;
26+ using System . IO . Ports ;
27+ using System . Linq ;
28+ using System . Linq . Expressions ;
29+ using System . Net ;
30+ using System . Net . Mail ;
31+ using System . Net . NetworkInformation ;
32+ using System . Net . Security ;
33+ using System . Net . Sockets ;
34+ using System . Reflection ;
35+ using System . Reflection . Emit ;
36+ using System . Resources ;
37+ using System . Security ;
38+ using System . Security . AccessControl ;
39+ using System . Security . Cryptography ;
40+ using System . Security . Cryptography . X509Certificates ;
41+ using System . Security . Principal ;
42+ using System . Text ;
43+ using System . Text . RegularExpressions ;
44+ using System . Threading ;
45+ using System . Threading . Tasks ;
46+ using System . Xml ;
47+ using System . Xml . Linq ;
48+ using System . Xml . Schema ;
49+ using System . Xml . Serialization ;
50+ using System . Xml . XPath ;
51+ using System . Xml . Xsl ;
52+ using EventDescriptor = System . ComponentModel . EventDescriptor ;
53+
54+ namespace Z . Expressions
55+ {
56+ public partial class EvalContext
57+ {
58+ /// <summary>Registers default alias (Extension Methods, Names, Static Members, Types and Values).</summary>
59+ public void RegisterDefaultAlias ( )
60+ {
61+ // Extension Methods
62+ RegisterExtensionMethod ( typeof ( Enumerable ) ) ;
63+ RegisterExtensionMethod ( typeof ( Queryable ) ) ;
64+
65+ // Static Members
66+ RegisterStaticMember ( typeof ( Math ) ) ;
67+
68+ // Types
69+
70+ // Fundamentals
71+ {
72+ // System (Primitive Type)
73+ RegisterType ( typeof ( bool ) ) ;
74+ RegisterType ( typeof ( byte ) ) ;
75+ RegisterType ( typeof ( char ) ) ;
76+ RegisterType ( typeof ( decimal ) ) ;
77+ RegisterType ( typeof ( double ) ) ;
78+ RegisterType ( typeof ( int ) ) ;
79+ RegisterType ( typeof ( float ) ) ;
80+ RegisterType ( typeof ( long ) ) ;
81+ RegisterType ( typeof ( object ) ) ;
82+ RegisterType ( typeof ( sbyte ) ) ;
83+ RegisterType ( typeof ( short ) ) ;
84+ RegisterType ( typeof ( string ) ) ;
85+ RegisterType ( typeof ( uint ) ) ;
86+ RegisterType ( typeof ( ulong ) ) ;
87+ RegisterType ( typeof ( ushort ) ) ;
88+
89+ // System (Exception)
90+ RegisterType ( typeof ( Exception ) ) ;
91+ RegisterType ( typeof ( OverflowException ) ) ;
92+
93+ // System (Misc)
94+ RegisterType ( typeof ( Array ) ) ;
95+ RegisterType ( typeof ( DateTime ) ) ;
96+ RegisterType ( typeof ( DateTimeOffset ) ) ;
97+ RegisterType ( typeof ( Delegate ) ) ;
98+ RegisterType ( typeof ( Enum ) ) ;
99+ RegisterType ( typeof ( EventArgs ) ) ;
100+ RegisterType ( typeof ( ExpandoObject ) ) ;
101+ RegisterType ( typeof ( Math ) ) ;
102+ RegisterType ( typeof ( TimeZoneInfo ) ) ;
103+ RegisterType ( typeof ( Type ) ) ;
104+
105+ // System.Collections
106+ RegisterType ( typeof ( ArrayList ) ) ;
107+ RegisterType ( typeof ( Hashtable ) ) ;
108+ RegisterType ( typeof ( IEnumerable ) ) ;
109+
110+ // System.Collections.Generic
111+ RegisterType ( typeof ( Dictionary < , > ) ) ;
112+ RegisterType ( typeof ( HashSet < > ) ) ;
113+ RegisterType ( typeof ( IEnumerable < > ) ) ;
114+ RegisterType ( typeof ( List < > ) ) ;
115+ RegisterType ( typeof ( Queue < > ) ) ;
116+ RegisterType ( typeof ( Stack < > ) ) ;
117+
118+ // System.ComponentModel
119+ RegisterType ( typeof ( Component ) ) ;
120+ RegisterType ( typeof ( TypeConverter ) ) ;
121+
122+ // System.Diagnostics
123+
124+ // System.Diagnostics.Eventing
125+
126+ // System.Diagnostics.Eventing.Reader
127+
128+ // System.Diagnostics.PerformanceData
129+
130+ // System.Globalization
131+
132+ // System.IO
133+
134+ // System.IO.Compression
135+ RegisterType ( typeof ( GZipStream ) ) ;
136+
137+ // System.IO.IsolatedStorage
138+ RegisterType ( typeof ( IsolatedStorage ) ) ;
139+
140+ // System.IO.Pipes
141+ RegisterType ( typeof ( AnonymousPipeClientStream ) ) ;
142+ RegisterType ( typeof ( AnonymousPipeServerStream ) ) ;
143+ RegisterType ( typeof ( NamedPipeClientStream ) ) ;
144+ RegisterType ( typeof ( NamedPipeServerStream ) ) ;
145+ RegisterType ( typeof ( PipeSecurity ) ) ;
146+ RegisterType ( typeof ( PipeStream ) ) ;
147+
148+ // System.IO.Ports
149+ RegisterType ( typeof ( SerialPort ) ) ;
150+
151+ // System.Linq
152+ RegisterType ( typeof ( IQueryable < > ) ) ;
153+ RegisterType ( typeof ( Queryable ) ) ;
154+
155+ // System.Linq.Expressions
156+ RegisterType ( typeof ( Expression < > ) ) ;
157+ RegisterType ( typeof ( Expression ) ) ;
158+
159+ // System.Reflection
160+ RegisterType ( typeof ( Assembly ) ) ;
161+ RegisterType ( typeof ( ConstructorInfo ) ) ;
162+ RegisterType ( typeof ( FieldInfo ) ) ;
163+ RegisterType ( typeof ( MemberInfo ) ) ;
164+ RegisterType ( typeof ( MethodInfo ) ) ;
165+ RegisterType ( typeof ( PropertyInfo ) ) ;
166+
167+ // System.Reflection.Emit
168+ RegisterType ( typeof ( AssemblyBuilder ) ) ;
169+ RegisterType ( typeof ( MethodBuilder ) ) ;
170+ RegisterType ( typeof ( TypeBuilder ) ) ;
171+
172+ // System.Resources
173+ RegisterType ( typeof ( ResourceManager ) ) ;
174+
175+ // System.Security
176+ RegisterType ( typeof ( SecureString ) ) ;
177+ RegisterType ( typeof ( SecurityManager ) ) ;
178+
179+ // System.Security.AccessControl
180+ RegisterType ( typeof ( AccessRule ) ) ;
181+ RegisterType ( typeof ( FileSecurity ) ) ;
182+ RegisterType ( typeof ( ObjectSecurity ) ) ;
183+
184+ // System.Security.Cryptography
185+ RegisterType ( typeof ( ECDsaCng ) ) ;
186+ RegisterType ( typeof ( SHA1 ) ) ;
187+ RegisterType ( typeof ( TripleDES ) ) ;
188+
189+ // System.Security.Cruptography.X509Certificates
190+ RegisterType ( typeof ( X509Store ) ) ;
191+
192+ // System.Security.Principal
193+ RegisterType ( typeof ( WindowsIdentity ) ) ;
194+
195+ // System.Text
196+ RegisterType ( typeof ( Encoding ) ) ;
197+ RegisterType ( typeof ( StringBuilder ) ) ;
198+
199+ // System.Text.RegularExpressions
200+ RegisterType ( typeof ( Regex ) ) ;
201+
202+ // System.Threading
203+ RegisterType ( typeof ( ReaderWriterLockSlim ) ) ;
204+ RegisterType ( typeof ( Semaphore ) ) ;
205+ RegisterType ( typeof ( Thread ) ) ;
206+ RegisterType ( typeof ( WaitHandle ) ) ;
207+ }
208+
209+ // Communications and Workflow
210+ {
211+ // System.Net
212+ RegisterType ( typeof ( Dns ) ) ;
213+ RegisterType ( typeof ( FtpWebRequest ) ) ;
214+ RegisterType ( typeof ( HttpListener ) ) ;
215+ RegisterType ( typeof ( HttpWebRequest ) ) ;
216+ RegisterType ( typeof ( WebClient ) ) ;
217+
218+ // System.Net.Mail
219+ RegisterType ( typeof ( MailMessage ) ) ;
220+ RegisterType ( typeof ( SmtpClient ) ) ;
221+
222+ // System.Net.NetworkInformation
223+ RegisterType ( typeof ( NetworkInterface ) ) ;
224+ RegisterType ( typeof ( NetworkChange ) ) ;
225+ RegisterType ( typeof ( Ping ) ) ;
226+
227+ // System.Net.Security
228+ RegisterType ( typeof ( NegotiateStream ) ) ;
229+ RegisterType ( typeof ( SslStream ) ) ;
230+
231+ // System.Net.Sockets
232+ RegisterType ( typeof ( NetworkStream ) ) ;
233+ RegisterType ( typeof ( Socket ) ) ;
234+ RegisterType ( typeof ( TcpClient ) ) ;
235+ RegisterType ( typeof ( TcpListener ) ) ;
236+ RegisterType ( typeof ( UdpClient ) ) ;
237+ }
238+
239+ // DATA, XML, and LINQ
240+ {
241+ // System.Data
242+ RegisterType ( typeof ( DataColumn ) ) ;
243+ RegisterType ( typeof ( DataRow ) ) ;
244+ RegisterType ( typeof ( DataSet ) ) ;
245+ RegisterType ( typeof ( DataTable ) ) ;
246+ RegisterType ( typeof ( DataView ) ) ;
247+
248+ // System.Data.Common
249+ RegisterType ( typeof ( DbCommand ) ) ;
250+ RegisterType ( typeof ( DbConnection ) ) ;
251+ RegisterType ( typeof ( DbDataAdapter ) ) ;
252+ RegisterType ( typeof ( DbDataReader ) ) ;
253+ RegisterType ( typeof ( DbProviderFactory ) ) ;
254+
255+ // System.Data.SqlClient
256+ RegisterType ( typeof ( SqlCommand ) ) ;
257+ RegisterType ( typeof ( SqlConnection ) ) ;
258+ RegisterType ( typeof ( SqlDataAdapter ) ) ;
259+ RegisterType ( typeof ( SqlDataReader ) ) ;
260+
261+ // System.XML
262+ RegisterType ( typeof ( XmlAttribute ) ) ;
263+ RegisterType ( typeof ( XmlDocument ) ) ;
264+ RegisterType ( typeof ( XmlElement ) ) ;
265+ RegisterType ( typeof ( XmlNode ) ) ;
266+ RegisterType ( typeof ( XmlReader ) ) ;
267+ RegisterType ( typeof ( XmlWriter ) ) ;
268+
269+ // System.Xml.Linq
270+ RegisterType ( typeof ( XAttribute ) ) ;
271+ RegisterType ( typeof ( XDocument ) ) ;
272+ RegisterType ( typeof ( XElement ) ) ;
273+ RegisterType ( typeof ( XName ) ) ;
274+ RegisterType ( typeof ( XNamespace ) ) ;
275+ RegisterType ( typeof ( XNode ) ) ;
276+ RegisterType ( typeof ( XText ) ) ;
277+
278+ // System.Xml.Schema
279+ RegisterType ( typeof ( XmlSchema ) ) ;
280+ RegisterType ( typeof ( XmlSchemaSet ) ) ;
281+ RegisterType ( typeof ( XmlSchemaValidator ) ) ;
282+
283+ // System.Xml.Serialization
284+ RegisterType ( typeof ( XmlSerializer ) ) ;
285+
286+ // System.Xml.XPath
287+ RegisterType ( typeof ( XPathDocument ) ) ;
288+ RegisterType ( typeof ( XPathExpression ) ) ;
289+ RegisterType ( typeof ( XPathNavigator ) ) ;
290+
291+ // System.Xml.Xsl
292+ RegisterType ( typeof ( XslCompiledTransform ) ) ;
293+ RegisterType ( typeof ( XsltArgumentList ) ) ;
294+ }
295+
296+ // .NET Framework 4 and Extensions
297+ {
298+ // Core
299+ RegisterType ( typeof ( SortedSet < > ) ) ;
300+ RegisterType ( typeof ( ParallelEnumerable ) ) ;
301+ RegisterType ( typeof ( LazyInitializer ) ) ;
302+ RegisterType ( typeof ( SpinLock ) ) ;
303+ RegisterType ( typeof ( Parallel ) ) ;
304+
305+ // System.Tuple
306+ RegisterType ( typeof ( Tuple ) ) ;
307+ RegisterType ( typeof ( Tuple < > ) ) ;
308+ RegisterType ( typeof ( Tuple < , > ) ) ;
309+ RegisterType ( typeof ( Tuple < , , > ) ) ;
310+ RegisterType ( typeof ( Tuple < , , , > ) ) ;
311+ RegisterType ( typeof ( Tuple < , , , , > ) ) ;
312+ RegisterType ( typeof ( Tuple < , , , , , > ) ) ;
313+ RegisterType ( typeof ( Tuple < , , , , , , > ) ) ;
314+ RegisterType ( typeof ( Tuple < , , , , , , , > ) ) ;
315+ }
316+
317+ // NEW
318+ RegisterType ( typeof ( CommandType ) ) ;
319+ RegisterType ( typeof ( Match ) ) ;
320+
321+ // Library
322+ RegisterType ( typeof ( EvalManager ) ) ;
323+ RegisterType ( typeof ( Eval ) ) ;
324+ }
325+ }
326+ }
0 commit comments