예제 #1
0
파일: Repl.cs 프로젝트: paradise/test
 /// <summary>
 /// A using statement starts with "using "
 /// </summary>
 /// <param name="code">a line of C# code</param>
 /// <returns>a <see cref="CompiledCodeSnippet"/> if <paramref name="code"/> is a using statement,
 /// otherwise null</returns>
 private static CompiledCodeSnippet UsingStatement(this string code)
 {
     CompiledCodeSnippet codeSnippet = null;
     if (code.TrimStart().StartsWith("using "))
     {
         var statementCode = code.TrimEnd();
         if (!statementCode.EndsWith(";"))
         {
             statementCode += ";";
         }
         var program = Program(usingStatement: statementCode);
         var statement = new Statement(code, CompileFromSource(program));
         if (!statement.HasErrors)
         {
             Context.UsingStatements.Add(statementCode);
             codeSnippet = statement;
         }
     }
     return codeSnippet;
 }
예제 #2
0
파일: Repl.cs 프로젝트: paradise/test
        private static CompiledCodeSnippet GenericStatement(this string code)
        {
            CompiledCodeSnippet codeSnippet = null;
            var program = Program(statement: code + ";");

            var statement = new Statement(code, CompileFromSource(program));
            if (!statement.HasErrors)
            {
                Context.CallStack.Add(code + ";");
                codeSnippet = statement;
            }
            else if (!Context.MultiLine &&
                        (statement.Errors[0].ErrorNumber == CompilerErrors.CS1513 ||
                        statement.Errors[0].ErrorNumber == CompilerErrors.CS1528))
            {
                Context.MultiLine = true;
                Context.MultiLineStatement += code;
            }

            return codeSnippet;
        }