protected QueryCompiler(QueryCore query, bool addReferences)
 {
     this.IsMyExtensions = query.IsMyExtensions;
     if (this.IsMyExtensions)
     {
         MyExtensions.UpdateAdditionalRefs(query);
     }
     if (GacResolver.IsEntityFrameworkAvailable)
     {
         this.References.Add("System.Data.Entity.dll");
     }
     DataContextDriver driver = query.GetDriver(true);
     if ((query.Repository != null) && (driver != null))
     {
         this.ImportedNamespaces.RemoveRange(driver.GetNamespacesToRemoveInternal(query.Repository));
         this.ImportedNamespaces.AddRange(driver.GetNamespacesToAddInternal(query.Repository));
         if (addReferences)
         {
             this.References.AddRange(query.Repository.GetDriverAssemblies());
         }
     }
     if (addReferences)
     {
         this.References.AddRange(PluginAssembly.GetCompatibleAssemblies(query.IsMyExtensions));
     }
     this.ImportedNamespaces.AddRange(query.AdditionalNamespaces);
     if (!string.IsNullOrEmpty(query.QueryBaseClassNamespace))
     {
         this.ImportedNamespaces.Add(query.QueryBaseClassNamespace);
     }
     if (addReferences)
     {
         this.References.AddRange(query.AllFileReferences);
         foreach (string str in query.AdditionalGACReferences)
         {
             string item = GacResolver.FindPath(str);
             if (item != null)
             {
                 this.References.Add(item);
             }
         }
         this.References.AddRange(query.GetStaticSchemaSameFolderReferences());
         if (!this.IsMyExtensions)
         {
             this.References.AddRange(MyExtensions.AdditionalRefs);
         }
     }
 }
 public override string GetHeader(QueryCore query)
 {
     StringBuilder builder = new StringBuilder("#Const LINQPAD = True\r\n");
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "Imports " + n).ToArray<string>()));
     builder.AppendLine();
     if (query.IncludePredicateBuilder)
     {
         builder.AppendLine("Public Module PredicateBuilder\r\n    <System.Runtime.CompilerServices.Extension> _\r\n    Public Function [And](Of T)(ByVal expr1 As Expression(Of Func(Of T, Boolean)), ByVal expr2 As Expression(Of Func(Of T, Boolean))) As Expression(Of Func(Of T, Boolean))\r\n        Dim invokedExpr As Expression = Expression.Invoke(expr2, expr1.Parameters.Cast(Of Expression)())\r\n        Return Expression.Lambda(Of Func(Of T, Boolean))(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters)\r\n    End Function\r\n\r\n    Public Function [False](Of T)() As Expression(Of Func(Of T, Boolean))\r\n      Return Function(f) False\r\n    End Function\r\n\r\n    <System.Runtime.CompilerServices.Extension> _\r\n    Public Function [Or](Of T)(ByVal expr1 As Expression(Of Func(Of T, Boolean)), ByVal expr2 As Expression(Of Func(Of T, Boolean))) As Expression(Of Func(Of T, Boolean))\r\n        Dim invokedExpr As Expression = Expression.Invoke(expr2, expr1.Parameters.Cast(Of Expression)())\r\n        Return Expression.Lambda(Of Func(Of T, Boolean))(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters)\r\n    End Function\r\n\r\n    Public Function [True](Of T)() As Expression(Of Func(Of T, Boolean))\r\n      Return Function(f) True\r\n    End Function\r\n\r\nEnd Module\r\n");
     }
     builder.AppendLine("Public Class UserQuery");
     if (query.QueryBaseClassName != null)
     {
         builder.AppendLine("  Inherits " + query.QueryBaseClassName);
     }
     builder.AppendLine();
     builder.AppendLine();
     DataContextDriver driver = query.GetDriver(true);
     if (driver != null)
     {
         ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, query.Repository);
         builder.Append("  Public Sub New (");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select "ByVal " + p.ParameterName + " As " + p.FullTypeName).ToArray<string>()));
         builder.AppendLine(")");
         builder.Append("    MyBase.New(");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
         builder.AppendLine(")");
         builder.AppendLine("  End Sub");
         builder.AppendLine();
     }
     builder.AppendLine("  Private Sub RunUserAuthoredQuery()");
     if (query.QueryKind == QueryLanguage.VBExpression)
     {
         builder.Append("Dim linqPadQuery = ");
     }
     else if (query.QueryKind == QueryLanguage.VBProgram)
     {
         builder.AppendLine("  Main\r\nEnd Sub");
     }
     return builder.ToString();
 }
 public override string GetHeader(QueryCore q)
 {
     StringBuilder builder = new StringBuilder("#define LINQPAD\r\n");
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "using " + n + ";").ToArray<string>()));
     if (q.IncludePredicateBuilder)
     {
         builder.AppendLine("public static class PredicateBuilder\r\n{\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> True<T> () { return f => true; }\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> False<T> () { return f => false; }\r\n\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> Or<T> (this System.Linq.Expressions.Expression<Func<T, bool>> expr1, System.Linq.Expressions.Expression<Func<T, bool>> expr2)\r\n\t{\r\n\t\tSystem.Linq.Expressions.Expression invokedExpr = System.Linq.Expressions.Expression.Invoke (\r\n\t\t  expr2, expr1.Parameters.Cast<System.Linq.Expressions.Expression> ());\r\n\r\n\t\treturn System.Linq.Expressions.Expression.Lambda<Func<T, bool>> (\r\n\t\t  System.Linq.Expressions.Expression.OrElse (expr1.Body, invokedExpr), expr1.Parameters);\r\n\t}\r\n\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> And<T> (this System.Linq.Expressions.Expression<Func<T, bool>> expr1, System.Linq.Expressions.Expression<Func<T, bool>> expr2)\r\n\t{\r\n\t\tSystem.Linq.Expressions.Expression invokedExpr = System.Linq.Expressions.Expression.Invoke (\r\n\t\t  expr2, expr1.Parameters.Cast<System.Linq.Expressions.Expression> ());\r\n\r\n\t\treturn System.Linq.Expressions.Expression.Lambda<Func<T, bool>> (\r\n\t\t  System.Linq.Expressions.Expression.AndAlso (expr1.Body, invokedExpr), expr1.Parameters);\r\n\t}\r\n}");
     }
     builder.Append("\r\npublic partial class UserQuery");
     if (q.QueryBaseClassName != null)
     {
         builder.Append(" : " + q.QueryBaseClassName);
     }
     builder.AppendLine("\r\n{");
     DataContextDriver driver = q.GetDriver(true);
     if (driver != null)
     {
         builder.Append("  public UserQuery (");
         ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, q.Repository);
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.FullTypeName + " " + p.ParameterName).ToArray<string>()));
         builder.Append(") : base (");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
         builder.AppendLine(") { }");
     }
     builder.AppendLine("\r\n  [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]");
     builder.AppendLine("  void RunUserAuthoredQuery()");
     builder.AppendLine("  {");
     if (q.QueryKind == QueryLanguage.Expression)
     {
         builder.AppendLine("  LINQPad.Extensions.Dump<object> (");
     }
     else if (q.QueryKind == QueryLanguage.Program)
     {
         builder.AppendLine("  Main();");
         builder.AppendLine("}");
     }
     return builder.ToString();
 }
 public override string GetHeader(QueryCore q)
 {
     StringBuilder builder = new StringBuilder();
     if (q.QueryKind == QueryLanguage.FSharpExpression)
     {
         builder.AppendLine("namespace global\r\n");
     }
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "open " + n).ToArray<string>()));
     builder.AppendLine("open LINQPad.FSharpExtensions");
     if (q.QueryKind == QueryLanguage.FSharpProgram)
     {
         builder.AppendLine("let Dump = Extensions.Dump");
     }
     DataContextDriver driver = q.GetDriver(true);
     StringBuilder builder2 = new StringBuilder();
     if (q.QueryKind == QueryLanguage.FSharpExpression)
     {
         builder.Append("\r\ntype UserQuery(");
         if ((driver != null) && (q.QueryKind == QueryLanguage.FSharpExpression))
         {
             builder2.Append(" inherit " + q.QueryBaseClassName + "(");
             ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, q.Repository);
             builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName + " : " + p.FullTypeName).ToArray<string>()));
             builder.Append(") as this ");
             builder2.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
             builder2.Append(")");
         }
         else
         {
             builder.Append(")");
         }
         builder.AppendLine(" = class");
         if (builder2.Length > 0)
         {
             builder.AppendLine(builder2.ToString());
         }
         builder.AppendLine(" member private dc.RunUserAuthoredQuery() =");
         builder.AppendLine("  (");
     }
     return builder.ToString();
 }