Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
//
// AssemblyInfo.cs
//
// Authors:
// Marek Safar (marek.safar@gmail.com)
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the assembly
[assembly: AssemblyTitle ("Mono.CSharp.dll")]
[assembly: AssemblyDescription ("Mono.CSharp.dll")]
[assembly: AssemblyDefaultAlias ("Mono.CSharp.dll")]
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: NeutralResourcesLanguage ("en-US")]
//[assembly: CLSCompliant (true)]
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../mono.pub")]
[assembly: ComVisible (false)]
[assembly: InternalsVisibleTo ("Microsoft.CSharp, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

View File

@@ -0,0 +1,8 @@
2009-12-08 Marek Safar <marek.safar@gmail.com>
* AssemblyInfo.cs: InternalsVisibleTo Microsoft.CSharp.
2009-11-26 Marek Safar <marek.safar@gmail.com>
* ChangeLog: Added

View File

@@ -0,0 +1,5 @@
2010-05-08 Daniel Nauck <dna@mono-project.de>
* Mono.CSharp.csproj: add double quotes around path directives
in the prebuild event for jay to support
compile locations with spaces in path.

View File

@@ -0,0 +1,30 @@
<Type Name="CompiledMethod" FullName="Mono.CSharp.CompiledMethod">
<TypeSignature Language="C#" Value="public delegate void CompiledMethod(ref object retvalue);" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Delegate</BaseTypeName>
</Base>
<Parameters>
<Parameter Name="retvalue" Type="System.Object&amp;" RefType="ref" />
</Parameters>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Docs>
<param name="retvalue">The return value.</param>
<summary>
A delegate that can be used to invoke the
compiled expression or statement.
</summary>
<remarks>
Since the Compile methods will compile
statements and expressions into the same
delegate, you can tell if a value was returned
by checking whether the returned value is of type
NoValueSet.
</remarks>
</Docs>
</Type>

View File

@@ -0,0 +1,36 @@
<Type Name="Evaluator+NoValueSet" FullName="Mono.CSharp.Evaluator+NoValueSet">
<TypeSignature Language="C#" Value="public class Evaluator.NoValueSet" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
Sentinel value used to indicate that no value was returned.
</summary>
<remarks>
A sentinel value used to indicate that no value was
was set by the compiled function. This is used to
differentiate between a function not returning a
value and null.
</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public NoValueSet ();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary></summary>
<remarks></remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@@ -0,0 +1,415 @@
<Type Name="Evaluator" FullName="Mono.CSharp.Evaluator">
<TypeSignature Language="C#" Value="public class Evaluator" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
Evaluator: provides an API to evaluate C# statements and
expressions dynamically.
</summary>
<remarks>
<para>
This class exposes static methods to execute C# statements and
evaluate C# expressions in the current program. Expressions
and statements should be fully formed, so they need to end
with a semicolon as they would in a regular C# file.
</para>
<para>
To initialize the evaluator with a number of compiler
options call the Init(string[]args) method with a set of
command line options that the compiler recognizes.
</para>
<para>
To interrupt execution of a statement, you can invoke the
Evaluator.Interrupt method. This comes in handy if you want
to implement a handler for Control-C for example.
</para>
</remarks>
</Docs>
<Members>
<Member MemberName="Compile">
<MemberSignature Language="C#" Value="public static Mono.CSharp.CompiledMethod Compile (string input);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Mono.CSharp.CompiledMethod</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="input" Type="System.String" />
</Parameters>
<Docs>
<param name="input">The expression or statement to compile.</param>
<summary>
Compiles the input string and returns a delegate that represents the compiled code.
</summary>
<returns></returns>
<remarks>
<para>
Compiles the input string as a C# expression or
statement.
</para>
<para>
Unlike the Evaluate method, the
resulting delegate can be invoked multiple times
without incurring in the compilation overhead.
</para>
<para>
This method can only deal with fully formed input
strings and does not provide a completion mechanism.
If you must deal with partial input (for example for
interactive use) use the other overload.
</para>
<para>
On success, a delegate is returned that can be used
to invoke the method.
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="Compile">
<MemberSignature Language="C#" Value="public static string Compile (string input, out Mono.CSharp.CompiledMethod compiled);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="input" Type="System.String" />
<Parameter Name="compiled" Type="Mono.CSharp.CompiledMethod&amp;" RefType="out" />
</Parameters>
<Docs>
<param name="input">The expression or statement to compile.</param>
<param name="compiled">The compiled code will be returned in this delegate.</param>
<summary>
Compiles the input string and returns a delegate that represents the compiled code.
</summary>
<returns>On success, a delegate that can be used to invoke the compiled code repeatedly.</returns>
<remarks>
<para>
Compiles the input string as a C# expression or
statement, unlike the Evaluate method, the
resulting delegate can be invoked multiple times
without incurring in the compilation overhead.
</para>
<para>
If the return value of this function is null,
this indicates that the parsing was complete.
</para>
<para>
If the return value is a string it indicates
that the input string was partial and that the
invoking code should provide more code before
the code can be successfully compiled.
</para>
<para>
If you know that you will always get full expressions or
statements and do not care about partial input, you can use
the other Compile overload.
</para>
<para>
On success, in addition to returning null, the
compiled parameter will be set to the delegate
that can be invoked to execute the code.
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="Evaluate">
<MemberSignature Language="C#" Value="public static object Evaluate (string input);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="input" Type="System.String" />
</Parameters>
<Docs>
<param name="input">The expression to evaluate.</param>
<summary>
Evaluates and expression or statement and returns the result.
</summary>
<returns>The result of computing the expression.</returns>
<remarks>
<para>
Evaluates the input string as a C# expression or
statement and returns the value.
</para>
<para>
This method will throw an exception if there is a syntax error,
of if the provided input is not an expression but a statement.
</para>
<para>
<example>
<code lang="C#">
// First setup the active using statements:
Evaluator.Run ("using System;");
int sum = (int) Evaluator.Evaluate ("1+2");
// A more interesting sample
Evaluator.Run ("using System.Linq");
Evaluator.Run ("var numbers = new int [] {1,2,3,4,5};");
// We know the result is an IEnumerator, cast it.
IEnumerator even = (IEnumerator) Evaluator.Evaluate ("from x in numbers where (x % 2) == 0 select x");
</code>
</example>
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="Evaluate">
<MemberSignature Language="C#" Value="public static string Evaluate (string input, out object result, out bool result_set);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="input" Type="System.String" />
<Parameter Name="result" Type="System.Object&amp;" RefType="out" />
<Parameter Name="result_set" Type="System.Boolean&amp;" RefType="out" />
</Parameters>
<Docs>
<param name="input">The expression to evaluate.</param>
<param name="result">The result will be stored here.</param>
<param name="result_set">If this value is true, the result was set and can be used, otherwise it was not set.</param>
<summary>
Evaluates and expression or statement and returns any result values.
</summary>
<returns>If null, the parsing was successful, if not, it means that the input is partial.</returns>
<remarks>
<para>
Evaluates the input string as a C# expression or
statement. If the input string is an expression
the result will be stored in the result variable
and the result_set variable will be set to true.
</para>
<para>
It is necessary to use the result/result_set
pair to identify when a result was set (for
example, execution of user-provided input can be
an expression, a statement or others, and
result_set would only be set if the input was an
expression.
</para>
<para>
If the return value of this function is null,
this indicates that the parsing was complete.
</para>
<para>
If the return value is a string, it indicates
that the input is partial and that the user
should provide an updated string.
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="GetUsing">
<MemberSignature Language="C#" Value="public static string GetUsing ();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a list of the active using statements.</summary>
<returns>A list of active using statements.</returns>
<remarks>This result can be shown to the user.</remarks>
</Docs>
</Member>
<Member MemberName="GetVars">
<MemberSignature Language="C#" Value="public static string GetVars ();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a list of all local variables.</summary>
<returns>A user-visible list of all local variables defined when invoking the evaluator.</returns>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="Init">
<MemberSignature Language="C#" Value="public static void Init (string[] args);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="args" Type="System.String[]" />
</Parameters>
<Docs>
<param name="args">Compiler options.</param>
<summary>
Optional initialization for the Evaluator.
</summary>
<remarks>
<para>
Initializes the Evaluator with the command line options
that would be processed by the command line compiler. Only
the first call to Init will work, any future invocations are
ignored.
</para>
<para>
You can safely avoid calling this method if your application
does not need any of the features exposed by the command line
interface.
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="InteractiveBaseClass">
<MemberSignature Language="C#" Value="public static Type InteractiveBaseClass { set; get; }" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Type</ReturnType>
</ReturnValue>
<Docs>
<summary>
The base class for the classes that host the user generated code
</summary>
<value></value>
<remarks>
<para>
This is the base class that will host the code
executed by the Evaluator. By default
this is the Mono.CSharp.InteractiveBase class
which is useful for interactive use.
</para>
<para>
By changing this property you can control the
base class and the static members that are
available to your evaluated code.
</para>
</remarks>
</Docs>
</Member>
<Member MemberName="Interrupt">
<MemberSignature Language="C#" Value="public static void Interrupt ();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>
Interrupts the evaluation of an expression executing in Evaluate.
</summary>
<remarks>
Use this method to interrupt long-running invocations.
</remarks>
</Docs>
</Member>
<Member MemberName="LoadAssembly">
<MemberSignature Language="C#" Value="public static void LoadAssembly (string file);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="file" Type="System.String" />
</Parameters>
<Docs>
<param name="file">The filename that holds the assembly.</param>
<summary>
Loads the given assembly and exposes the API to the user.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="ReferenceAssembly">
<MemberSignature Language="C#" Value="public static void ReferenceAssembly (System.Reflection.Assembly a);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="a" Type="System.Reflection.Assembly" />
</Parameters>
<Docs>
<param name="a">The assembly to expose to the evaluated expressions.</param>
<summary>
Exposes the API of the given assembly to the Evaluator
</summary>
<remarks>After this invocation, the types from the referenced
assembly will be accessible to code executed by the
evaluator.</remarks>
</Docs>
</Member>
<Member MemberName="Run">
<MemberSignature Language="C#" Value="public static bool Run (string statement);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="statement" Type="System.String" />
</Parameters>
<Docs>
<param name="statement">A statement to execute.</param>
<summary>
Executes the given expression or statement.
</summary>
<returns>True if the code was succesfully parsed.</returns>
<remarks>
<para>
Executes the provided statement, returns true
on success, false on parsing errors. Exceptions
might be thrown by the called code.
</para>
<para>
<example>
<code lang="C#">
// First setup the active using statements:
Evaluator.Run ("using System;");
Evaluator.Run ("Console.WriteLine (\"Hello, World\");
</code>
</example>
</para>
</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@@ -0,0 +1,18 @@
<Type Name="InteractiveBase+Simple" FullName="Mono.CSharp.InteractiveBase+Simple">
<TypeSignature Language="C#" Value="public delegate void InteractiveBase.Simple();" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Delegate</BaseTypeName>
</Base>
<Parameters />
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Docs>
<summary>A helper delegate to a void method.</summary>
<remarks>Equivalent to a System.Action.</remarks>
</Docs>
</Type>

View File

@@ -0,0 +1,271 @@
<Type Name="InteractiveBase" FullName="Mono.CSharp.InteractiveBase">
<TypeSignature Language="C#" Value="public class InteractiveBase" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
The default base class for every interaction line
</summary>
<remarks>
The expressions and statements behave as if they were
a static method of this class. The InteractiveBase class
contains a number of useful methods, but can be overwritten
by setting the InteractiveBaseType property in the Evaluator
</remarks>
</Docs>
<Members>
<Member MemberName="ContinuationPrompt">
<MemberSignature Language="C#" Value="public static string ContinuationPrompt;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>
The secondary prompt.
</summary>
<remarks>The secondary prompt is used for interactive use
(used when an expression is incomplete).</remarks>
</Docs>
</Member>
<Member MemberName="Describe">
<MemberSignature Language="C#" Value="public static string Describe (object x);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="x" Type="System.Object" />
</Parameters>
<Docs>
<param name="x">An object or a type.</param>
<summary>
Describes an object or a type.
</summary>
<returns>A user friendly rendering of the type.</returns>
<remarks>
This method will show a textual representation
of the object's type. If the object is a
System.Type it renders the type directly,
otherwise it renders the type returned by
invoking GetType on the object.
</remarks>
</Docs>
</Member>
<Member MemberName="Error">
<MemberSignature Language="C#" Value="public static System.IO.TextWriter Error;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.IO.TextWriter</ReturnType>
</ReturnValue>
<Docs>
<summary>
Determines where the standard error of methods in this class will go.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="help">
<MemberSignature Language="C#" Value="public static string help { get; }" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>
Returns a list of available static methods.
</summary>
<value></value>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="LoadAssembly">
<MemberSignature Language="C#" Value="public static void LoadAssembly (string assembly);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="assembly" Type="System.String" />
</Parameters>
<Docs>
<param name="assembly">The file to load.</param>
<summary>
Loads the assembly
</summary>
<remarks>
Loads the specified assembly and makes its types
available to the evaluator. This is equivalent
to passing the -pkg: command line flag to the C#
compiler on the command line.
</remarks>
</Docs>
</Member>
<Member MemberName="LoadPackage">
<MemberSignature Language="C#" Value="public static void LoadPackage (string pkg);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="pkg" Type="System.String" />
</Parameters>
<Docs>
<param name="pkg">The name of the package to load.</param>
<summary>
Loads the assemblies from a package
</summary>
<remarks>
Loads the assemblies from a package. This is equivalent
to passing the -pkg: command line flag to the C# compiler
on the command line.
</remarks>
</Docs>
</Member>
<Member MemberName="Output">
<MemberSignature Language="C#" Value="public static System.IO.TextWriter Output;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.IO.TextWriter</ReturnType>
</ReturnValue>
<Docs>
<summary>
Determines where the standard output of methods in this class will go.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="Prompt">
<MemberSignature Language="C#" Value="public static string Prompt;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>
The primary prompt used for interactive use.
</summary>
<remarks>This is the primary prompt to be used by
read-eval-print-loop implementations. </remarks>
</Docs>
</Member>
<Member MemberName="quit">
<MemberSignature Language="C#" Value="public static object quit { get; }" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Docs>
<summary>
Indicates to the read-eval-print-loop that the interaction should be finished.
</summary>
<value></value>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="QuitRequested">
<MemberSignature Language="C#" Value="public static bool QuitRequested;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>
Used to signal that the user has invoked the `quit' statement.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="ShowUsing">
<MemberSignature Language="C#" Value="public static void ShowUsing ();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>
Displays the using statements in effect at this point.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="ShowVars">
<MemberSignature Language="C#" Value="public static void ShowVars ();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>
Shows all the variables defined so far.
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="Time">
<MemberSignature Language="C#" Value="public static TimeSpan Time (Mono.CSharp.InteractiveBase.Simple a);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.TimeSpan</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="a" Type="Mono.CSharp.InteractiveBase+Simple" />
</Parameters>
<Docs>
<param name="a">The method to time.</param>
<summary>
Times the execution of the given delegate
</summary>
<returns>The time it took for the method passed to execute.</returns>
<remarks>This is a very simple benchmarking tool.</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@@ -0,0 +1,96 @@
<Type Name="Report" FullName="Mono.CSharp.Report">
<TypeSignature Language="C#" Value="public class Report" />
<AssemblyInfo>
<AssemblyName>Mono.CSharp</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
This class is used to report errors and warnings to te user.
</summary>
<remarks></remarks>
</Docs>
<Members>
<Member MemberName="Errors">
<MemberSignature Language="C#" Value="public static int Errors;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>
Errors encountered so far
</summary>
<remarks>The number of errors reported</remarks>
</Docs>
</Member>
<Member MemberName="Stderr">
<MemberSignature Language="C#" Value="public static System.IO.TextWriter Stderr;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.IO.TextWriter</ReturnType>
</ReturnValue>
<Docs>
<summary>The TextWriter used to report errors.</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="WarningLevel">
<MemberSignature Language="C#" Value="public static int WarningLevel { set; get; }" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>The warning level for reporting errors.</summary>
<value></value>
<remarks>See the compiler manual page for the possible values for the this variable.</remarks>
</Docs>
</Member>
<Member MemberName="Warnings">
<MemberSignature Language="C#" Value="public static int Warnings;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>
Warnings encountered so far
</summary>
<remarks></remarks>
</Docs>
</Member>
<Member MemberName="WarningsAreErrors">
<MemberSignature Language="C#" Value="public static bool WarningsAreErrors;" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>
Whether warnings should be considered errors
</summary>
<remarks>Equivalent to passing -warnaserror to the compiler.</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@@ -0,0 +1,39 @@
<Overview>
<Assemblies>
<Assembly Name="Mono.CSharp" Version="2.1.0.0">
<Attributes>
<Attribute>
<AttributeName>System.Reflection.AssemblyCompany("Novell, Inc.")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Reflection.AssemblyConfiguration("")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Reflection.AssemblyCopyright("2001 - 2008 Novell, Inc.")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Reflection.AssemblyProduct("Mono")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Reflection.AssemblyTitle("Embedded C# Compiler and Library")</AttributeName>
</Attribute>
</Attributes>
</Assembly>
</Assemblies>
<Remarks>To be added.</Remarks>
<Copyright>To be added.</Copyright>
<Types>
<Namespace Name="Mono.CSharp">
<Type Name="CompiledMethod" Kind="Delegate" />
<Type Name="Evaluator" Kind="Class" />
<Type Name="Evaluator+NoValueSet" Kind="Class" />
<Type Name="InteractiveBase" Kind="Class" />
<Type Name="InteractiveBase+Simple" Kind="Delegate" />
<Type Name="Report" Kind="Class" />
</Namespace>
</Types>
<Title>Mono.CSharp</Title>
</Overview>

View File

@@ -0,0 +1,63 @@
<Namespace Name="Mono.CSharp">
<Docs>
<summary>C# Compiler Service and Runtime Evaulator.</summary>
<remarks>
<para>
The Mono.CSharp.dll assembly is a repackaging of Mono's C#
compiler and provides access to the C# compiler as a service.
It implements a C# eval. It allows applications to compile
and execute C# statements and expressions at runtime.
</para>
<para>
This API is not yet final and will likely change as we get a
better understanding of how developers will like to use the
Mono C# Compiler Service. You can make a local copy of the
Mono.CSharp.dll assembly and reference that locally as we are
not commiting to the stability of this API yet.
</para>
<para>
The evaluator currently exposes a statement and expression API
and will allow the consumer to execute statements or compute
the value of expressions and get the results back. Support
for compiling classes will appear in a future version. The
<see cref="M:Mono.CSharp.Evaluator.Run(string)"/> method is a
convenient way of executing expressions and stamtements and
discarding the result. If you want to get the results of
executing an expression use the <see
cref="M:Mono.CSharp.Evaluator.Evaluate(string)"/> method
instead.
</para>
<para>
Variables declared during evaluation will continue to be made
available on upcoming invocations. This allows variables to
be declared and reused later.
</para>
<para>
The evaluator does not have direct access to any assemblies
that are not explicitly referenced through the Evaluator's
<see
cref="M:Mono.CSharp.Evaluator.ReferenceAssembly(System.Reflection.Assembly)"/>
method.
</para>
<para>
The API exposes similar entry points, some are used for
read-eval-print loops where more control over partial-input is
required. Another set of entry points are provided when this
functionality is not required.
</para>
<para>
The following are limitations in the Mono 2.2 API and will change in the future:
</para>
<para>
Using statements are currently global, once the using
statement has been issued, it remains active.
</para>
<para>
If you want to create local variables that are not visible
across multiple evaluations, you will have to create a new
<see cref="T:System.AppDomain"/> and invoke the compiler
there.
</para>
</remarks>
</Docs>
</Namespace>

View File

@@ -0,0 +1,16 @@
thisdir = class/Mono.CSharp
SUBDIRS =
include ../../build/rules.make
LIBRARY = Mono.CSharp.dll
LIB_MCS_FLAGS = -r:System.Core.dll -r:System.Xml.dll -r:System.dll
ifeq (monotouch, $(PROFILE))
LIB_MCS_FLAGS += -d:IOS_REFLECTION
endif
TEST_MCS_FLAGS = -r:System.Core.dll
include ../../build/library.make

View File

@@ -0,0 +1,58 @@
../../mcs/anonymous.cs
../../mcs/argument.cs
../../mcs/assign.cs
../../mcs/assembly.cs
../../mcs/async.cs
../../mcs/attribute.cs
../../mcs/cs-tokenizer.cs
../../mcs/cfold.cs
../../mcs/class.cs
../../mcs/codegen.cs
../../mcs/complete.cs
../../mcs/const.cs
../../mcs/constant.cs
../../mcs/convert.cs
../../mcs/context.cs
../../mcs/decl.cs
../../mcs/delegate.cs
../../mcs/doc.cs
../../mcs/driver.cs
../../mcs/dynamic.cs
../../mcs/ecore.cs
../../mcs/enum.cs
../../mcs/eval.cs
../../mcs/expression.cs
../../mcs/field.cs
../../mcs/flowanalysis.cs
../../mcs/generic.cs
../../mcs/import.cs
../../mcs/iterators.cs
../../mcs/lambda.cs
../../mcs/linq.cs
../../mcs/literal.cs
../../mcs/location.cs
../../mcs/membercache.cs
../../mcs/method.cs
../../mcs/modifiers.cs
../../mcs/namespace.cs
../../mcs/nullable.cs
../../mcs/parameter.cs
../../mcs/pending.cs
../../mcs/property.cs
../../mcs/reflection.cs
../../mcs/report.cs
../../mcs/settings.cs
../../mcs/module.cs
../../mcs/statement.cs
../../mcs/support.cs
../../mcs/typemanager.cs
../../mcs/typespec.cs
../../mcs/visit.cs
../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
../../class/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs
../../class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
../../build/common/Consts.cs
../../tools/monop/outline.cs
../../mcs/cs-parser.cs
Assembly/AssemblyInfo.cs

View File

@@ -0,0 +1,7 @@
AssertReportPrinter.cs
Evaluator/BuildinCommands.cs
Evaluator/CompletionTest.cs
Evaluator/EvaluatorFixture.cs
Evaluator/EvaluatorTest.cs
Evaluator/ExpressionsTest.cs
Evaluator/TypesTest.cs

View File

@@ -0,0 +1,41 @@
//
// AssertReportPrinter.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.CSharp;
using NUnit.Framework;
namespace MonoTests
{
class AssertReportPrinter : ReportPrinter
{
public override void Print (AbstractMessage msg, bool showFullPath)
{
Assert.Fail (msg.Text);
}
}
}

View File

@@ -0,0 +1,44 @@
//
// BuildinCommandsTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class BuildinCommandsTest : EvaluatorFixture
{
[Test]
public void ShowUsing ()
{
// Evaluator.Run ("ShowUsing();");
}
}
}

View File

@@ -0,0 +1,78 @@
//
// Completion.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class Completion : EvaluatorFixture
{
[Test]
public void SimpleSystemNamespace ()
{
Evaluator.Run ("using System;");
string prefix;
string[] res;
res = Evaluator.GetCompletions ("ConsoleK", out prefix);
Assert.AreEqual (new string[] { "ey", "eyInfo" }, res, "#1");
res = Evaluator.GetCompletions ("Converte", out prefix);
Assert.AreEqual (new string[] { "r" }, res, "#2");
res = Evaluator.GetCompletions ("Sys", out prefix);
Assert.AreEqual (new string[] { "tem", "temException" }, res, "#3");
res = Evaluator.GetCompletions ("System.Int3", out prefix);
Assert.AreEqual (new string[] { "2" }, res, "#4");
}
[Test]
public void Initializers ()
{
string prefix;
string[] res;
res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { Ca", out prefix);
Assert.AreEqual (new string[] { "pacity" }, res, "#1");
res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { ", out prefix);
Assert.AreEqual (new string[] { "Capacity", "Length", "MaxCapacity" }, res, "#2");
}
[Test]
public void StringLocalVariable ()
{
string prefix;
var res = Evaluator.GetCompletions ("string a.", out prefix);
Assert.IsNull (res);
}
}
}

View File

@@ -0,0 +1,53 @@
//
// EvaluatorFixture.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
public class EvaluatorFixture
{
Evaluator evaluator;
protected CompilerSettings settings;
[SetUp]
public void Setup ()
{
settings = new CompilerSettings ();
var ctx = new CompilerContext (settings, new AssertReportPrinter ());
evaluator = new Evaluator (ctx);
}
public Evaluator Evaluator {
get {
return evaluator;
}
}
}
}

View File

@@ -0,0 +1,44 @@
//
// EvaluatorTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
public class EvaluatorTest : EvaluatorFixture
{
[Test]
public void SameSettings ()
{
var ctx = new CompilerContext (settings, new AssertReportPrinter ());
var evaluator2 = new Evaluator (ctx);
evaluator2.Run ("int i = 0;");
}
}
}

View File

@@ -0,0 +1,170 @@
//
// ExpressionsTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class ExpressionsTest : EvaluatorFixture
{
[Test]
public void StatementExpression_1 ()
{
Evaluator.Run ("System.Console.WriteLine (100)");
}
[Test]
public void StatementExpression_2 ()
{
Evaluator.Run ("var a = new int [] {1,2,3}; var b = a.Length;");
}
[Test]
public void AnonymousType ()
{
Evaluator.Run ("var foo = new { Bar = \"baz\" };");
}
[Test]
public void Simple ()
{
object res;
res = Evaluator.Evaluate ("\"foo\" == \"bar\";");
Assert.AreEqual (false, res, "CompareString");
res = Evaluator.Evaluate ("var a = 1; a+2;");
Assert.AreEqual (3, res, "CompareInt");
res = Evaluator.Evaluate ("2 * 4;");
Assert.AreEqual (8, res, "Multiply");
}
[Test]
public void UsingAfterError ()
{
try {
Evaluator.Evaluate ("File.OpenRead (\"/etc/passwd\");");
Assert.Fail ("#1");
} catch {
}
Evaluator.Run ("using System.IO;");
Evaluator.Evaluate ("File.Exists (\"/etc/passwd\");");
}
[Test]
public void WithTypeBuilders ()
{
object res;
Evaluator.Run ("var a = new { A = 1 };");
res = Evaluator.Evaluate ("a.ToString ();");
Assert.AreEqual ("{ A = 1 }", res, "#1");
}
[Test]
public void LinqExpressions ()
{
Evaluator.Run ("using System; using System.Linq;");
Evaluator.Run ("var a = new int[]{1,2,3};");
object res = Evaluator.Evaluate ("from x in a select x + 1;");
CollectionAssert.AreEqual (new int[] { 2, 3, 4 }, ((IEnumerable<int>) res).ToArray ());
}
[Test]
public void LinqExpressionStatements ()
{
Evaluator.Run ("using System; using System.Linq;");
Evaluator.Run ("var first_scope = new int [] {1,2,3};");
Evaluator.Run ("var second_scope = from x in first_scope select x;");
}
[Test]
public void ReferenceLoading ()
{
Evaluator.ReferenceAssembly (typeof (ExpressionsTest).Assembly);
object res = Evaluator.Evaluate ("typeof (MonoTests.EvaluatorTest.ExpressionsTest) != null;");
Assert.AreEqual (true, res, "#1");
}
[Test]
public void PartialExpression ()
{
object eval_result;
bool result_set;
string sres = Evaluator.Evaluate ("1+", out eval_result, out result_set);
Assert.IsFalse (result_set, "No result should have been set");
Assert.AreEqual ("1+", sres, "The result should have been the input string, since we have a partial input");
}
[Test]
public void GotoWithUnreachableStatement ()
{
Evaluator.Run ("using System;");
string code = "var x = new Action(() => {" +
"Console.WriteLine(\"beforeGoto\");" +
"goto L;" +
"L:" +
"Console.WriteLine(\"afterGoto\");" +
"});";
Assert.IsTrue (Evaluator.Run (code), "#1");
Assert.IsTrue (Evaluator.Run ("x();"), "#2");
}
#if NET_4_0
[Test]
public void DynamicStatement ()
{
Evaluator.Run ("dynamic d = 1;");
Evaluator.Run ("d = 'a';");
Evaluator.Run ("d.GetType ();");
}
#endif
#if NET_4_5
[Test]
public void AwaitExpression ()
{
Evaluator.WaitOnTask = true;
var res = Evaluator.Evaluate("var res = await System.Threading.Tasks.Task.FromResult (1) + await System.Threading.Tasks.Task.FromResult (2);");
res = Evaluator.Evaluate ("res;");
Assert.AreEqual (3, res, "#1");
}
#endif
}
}

Some files were not shown because too many files have changed in this diff Show More