示例#1
0
文件: Default.cs 项目: cbsistem/JSIL
        public override SolutionBuilder.BuildResult ProcessBuildResult (VariableSet variables, Configuration configuration, SolutionBuilder.BuildResult buildResult) {
            CopiedOutputGatherer.GatherFromProjectFiles(
                variables, configuration, buildResult
            );

            return base.ProcessBuildResult(variables, configuration, buildResult);
        }
        public void AllProjectsHaveSameOutputDirectory()
        {
            var testPath = Path.Combine("temp", "AllProjectsHaveSameOutputDirectory");
            var sb       = new SolutionBuilder("AllProjectsHaveSameOutputDirectory.sln")
            {
                SolutionPath = Path.Combine(Root, testPath),
                Verbosity    = LoggerVerbosity.Diagnostic,
            };

            var app1 = new XamarinAndroidApplicationProject()
            {
                ProjectName = "App1",
                OutputPath  = Path.Combine("..", "bin", "Debug"),
            };

            sb.Projects.Add(app1);
            var app2 = new XamarinAndroidApplicationProject()
            {
                ProjectName = "App2",
                OutputPath  = Path.Combine("..", "bin", "Debug"),
            };

            sb.Projects.Add(app2);
            Assert.IsTrue(sb.Build(), "Build of solution should have succeeded");
            Assert.IsTrue(sb.ReBuild(), "ReBuild of solution should have succeeded");
            sb.Dispose();
        }
示例#3
0
        private static void CodeBreaker()
        {
            var builder = Rules.CreateSolutionBuilder();

            int breakerAttemptsCount = 0;

            while (true)
            {
                ReadOnlyMemory <CodeColor> guess = InputCode($"Input guess #{++breakerAttemptsCount}: ");
                Response response = InputResponse();
                builder.AddResponse(guess, response);

                SolutionBuilder <CodeColor> .SolutionsAnalysis analysis = builder.AnalyzeSolutions(CancellationToken.None);
                analysis.ApplyAnalysisBackToBuilder();
                if (analysis.ViableSolutionsFound == 1)
                {
                    Console.WriteLine("Solution found!");
                    break;
                }

                Console.WriteLine($"{analysis.ViableSolutionsFound} solutions remaining.");

                PrintProbabilities(analysis);
                PrintSuggestedGuess(builder, CancellationToken.None);
            }
        }
        public void BeforeAll()
        {
            _solutionName = "MySolution.sln";
            _fullFilePath = @"C:\where I am\A Solution\MySolution.sln";
            _projectOne = Builder<Project>.CreateNew().Build();
            _projectTwo = Builder<Project>.CreateNew().Build();
            _nuspec1 = Builder<NuSpecFile>.CreateNew().Build();
            _nuspec2 = Builder<NuSpecFile>.CreateNew().Build();

            var solutionFileContents = GetSolutionFileContents();

            var fileSystem = new Mock<IFileSystem>();
            fileSystem.Setup(fs => fs.FindFullFilePath(_solutionName)).Returns(_fullFilePath);
            fileSystem.Setup(fs => fs.ReadFile(_fullFilePath)).Returns(solutionFileContents);
            fileSystem.Setup(fs => fs.GetDirectory(_fullFilePath)).Returns("");

            var projectBuilder = new Mock<IBuilder<Project, BuildProjectRequest>>();
            projectBuilder.Setup(b => b.Build(It.Is<BuildProjectRequest>(projectRequest => projectRequest.ProjectFilePath == "Project1\\Project1.csproj"))).Returns(_projectOne);
            projectBuilder.Setup(b => b.Build(It.Is<BuildProjectRequest>(projectRequest => projectRequest.ProjectFilePath == "Project2\\Project2.csproj"))).Returns(_projectTwo);

            var nuspecBuilder = new Mock<IBuilder<NuSpecFile, string>>();
            nuspecBuilder.Setup(b => b.Build("spec1")).Returns(_nuspec1);
            nuspecBuilder.Setup(b => b.Build("spec2")).Returns(_nuspec2);

            var builder = new SolutionBuilder(fileSystem.Object, projectBuilder.Object, nuspecBuilder.Object);

            var request = new BuildSolutionRequest()
                .WithSolutionName(_solutionName)
                .WithNuSpec("spec1")
                .WithNuSpec("spec2");

            _solution = builder.Build(request);
        }
示例#5
0
        static void Main(String[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("usage: sqlbuilder <input file>");
                return;
            }
            String fileName = Path.GetFullPath(args[0]);

            if (!File.Exists(fileName))
            {
                Console.WriteLine($"file not found: {fileName}");
                return;
            }

            try
            {
                var sb = new SolutionBuilder();
                var mb = new ModelBuilder();
                sb.BuildSolution(fileName, mb);
                Console.WriteLine(mb.ToString());
            } catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
示例#6
0
        public void Builds_solution_to_a_particular_directory()
        {
            SolutionBuilder builder = new SolutionBuilder();
            bool result = builder.Build(@"D:\SourceControl\Seacrest\src\Seacrest.sln", _outDir);

            Assert.IsTrue(result);
        }
        [DataRow("Windows Form Designer GeNeRaTed code")] // legacy Windows Forms used to include generated code in dev files, surrounded by such a region
        public void Issues_Raised_On_Partially_Generated_Legacy_WinForms_File(string regionName)
        {
            var content =
                $@"namespace PartiallyGenerated
{{
    class MyClass
    {{
        void HandWrittenEventHandler()
        {{
            ; // Noncompliant
        }}

#region {regionName}
        void GeneratedStuff()
        {{
            ; // Noncompliant
        }}
#endregion
    }}
}}";
            var compilation = SolutionBuilder
                              .Create()
                              .AddProject(AnalyzerLanguage.CSharp, createExtraEmptyFile: false)
                              .AddSnippet(content, "Foo.cs")
                              .GetCompilation();

            DiagnosticVerifier.Verify(compilation, new CS.EmptyStatement(), CompilationErrorBehavior.FailTest, compilation.SyntaxTrees.First().GetText());
        }
        public IOSApplicationContext(AppDelegate appDelegate, NavigationController controller,
                                     ApplicationSettings settings, CustomExceptionHandler exceptionHandler)
        {
            ApplicationBackground += () => { };
            ApplicationRestore    += () => { };

            GlobalVariables = new Dictionary <string, object>();

            Settings          = settings;
            _controller       = controller;
            _exceptionHandler = exceptionHandler;

            LocationProvider          = new GpsProvider();
            LocationTracker           = new GPSTracker();
            GalleryProvider           = new GalleryProvider(controller, this);
            CameraProvider            = new CameraProvider(controller, this);
            DialogProvider            = new DialogProvider(this);
            DisplayProvider           = new DisplayProvider();
            ClipboardProvider         = new ClipboardProvider();
            EmailProvider             = new EmailProvider(settings, appDelegate);
            JokeProviderInternal      = new JokeProvider();
            LocalNotificationProvider = new LocalNotificationProvider();
            WebProvider = new WebProvider();

            var builder = new SolutionBuilder(this);

            builder.Build();

            StyleSheetContext.Current.Scale = UIScreen.MainScreen.Scale;
        }
        private static void VerifyEmpty(string name, string content, DiagnosticAnalyzer diagnosticAnalyzer, CompilationErrorBehavior checkMode = CompilationErrorBehavior.Default)
        {
            AnalyzerLanguage language;

            if (name.EndsWith(".cs"))
            {
                language = AnalyzerLanguage.CSharp;
            }
            else if (name.EndsWith(".vb"))
            {
                language = AnalyzerLanguage.VisualBasic;
            }
            else
            {
                throw new ArgumentException($"Was expecting the file name to end with '.cs' or '.vb', got '{name}'.", nameof(name));
            }

            var compilation = SolutionBuilder
                              .Create()
                              .AddProject(language, createExtraEmptyFile: false)
                              .AddSnippet(content, name)
                              .GetCompilation();

            DiagnosticVerifier.VerifyNoIssueReported(compilation, diagnosticAnalyzer, checkMode);
        }
示例#10
0
        public AndroidApplicationContext(BaseScreen baseActivity, Settings settings, Action loadComplete)
        {
            ApplicationBackground += () => { };
            ApplicationRestore    += () => { };

            GlobalVariables = new Dictionary <string, object>();

            _baseActivity = baseActivity;
            _settings     = settings;
            _loadComplete = loadComplete;

            LocationProvider          = new GpsProvider(_baseActivity);
            LocationTracker           = new GpsTracker(_baseActivity);
            GalleryProvider           = new GalleryProvider(_baseActivity, this);
            CameraProvider            = new CameraProvider(_baseActivity, this);
            DialogProvider            = new DialogProvider(_baseActivity, this);
            DisplayProvider           = new DisplayProvider();
            ClipboardProvider         = new ClipboardProvider(_baseActivity);
            EmailProvider             = new EmailProvider(_settings, _baseActivity);
            JokeProviderInternal      = new JokeProvider(_baseActivity);
            LocalNotificationProvider = new LocalNotificationProvider(_baseActivity);
            WebProvider = new WebProvider(_baseActivity);

            var builder = new SolutionBuilder(this);

            builder.Build();

            _commonData = ValueStackContext.Current.CreateCommonData("Android");
        }
        public void SetUp()
        {
            theScenario = SolutionScenario.Create(scenario =>
            {
                scenario.Solution("Test", test =>
                {
                    test.SolutionDependency("FubuCore", "1.2.0.0", UpdateMode.Float);
                    test.SolutionDependency("UnneededAnywhereButHere", "1.2.0.0", UpdateMode.Float);

                    test.ProjectDependency("Test1", "FubuCore");
                    test.ProjectDependency("Test1", "UnneededAnywhereButHere");

                    test.ProjectDependency("Test2", "FubuCore");

                    test.LocalDependency("FubuCore", "1.2.0.0");
                    test.LocalDependency("UnneededAnywhereButHere", "1.2.0.0");
                });
            });

            theSolution = theScenario.Find("Test");

            RippleOperation
            .With(theSolution)
            .Execute <RemoveInput, RemoveCommand>(new RemoveInput {
                Nuget = "FubuCore", ProjectFlag = "Test1"
            });
            RippleOperation
            .With(theSolution)
            .Execute <RemoveInput, RemoveCommand>(new RemoveInput {
                Nuget = "UnneededAnywhereButHere", ProjectFlag = "Test1"
            });

            theSolution = SolutionBuilder.ReadFrom(theScenario.DirectoryForSolution("Test"));
        }
示例#12
0
 public IEnumerable <Solution> FindSolutions()
 {
     if (RippleFileSystem.IsSolutionDirectory())
     {
         yield return(SolutionBuilder.ReadFromCurrentDirectory());
     }
 }
示例#13
0
        /// <summary>
        /// Creates a new <see cref="SolutionBuilder{TNodeState}"/> to represent a game.
        /// </summary>
        /// <returns>The newly initialized instance.</returns>
        public static SolutionBuilder <CodeColor> CreateSolutionBuilder()
        {
            var possibleNodeValues = Enum.GetValues(typeof(CodeColor)).Cast <CodeColor>().ToImmutableArray();
            var builder            = new SolutionBuilder <CodeColor>(Nodes, possibleNodeValues);

            return(builder);
        }
示例#14
0
        public void WrongCompilationBeingUsed()
        {
            const string firstSnippet     = @"
public class Foo
{
    private static int Original = 42;
    private int Field = Original;
}";
            const string secondSnippet    = @"
public class Bar
{
    private int Field = 42;
    public int Method()
    {
        return Field;
    }
}";
            var          firstCompilation = SolutionBuilder.Create().AddProject(AnalyzerLanguage.CSharp, createExtraEmptyFile: false)
                                            .AddSnippet(firstSnippet)
                                            .GetCompilation();
            var secondCompilation = SolutionBuilder.Create().AddProject(AnalyzerLanguage.CSharp, createExtraEmptyFile: false)
                                    .AddSnippet(secondSnippet)
                                    .GetCompilation();
            var secondCompilationReturnExpression = secondCompilation.SyntaxTrees.Single().GetRoot().DescendantNodes().OfType <ReturnStatementSyntax>().Single().Expression;
            var firstCompilationFinder            = new CSharpConstantValueFinder(firstCompilation.GetSemanticModel(firstCompilation.SyntaxTrees.Single()));

            firstCompilationFinder.FindConstant(secondCompilationReturnExpression).Should().BeNull();
            var secondCompilationFinder = new CSharpConstantValueFinder(secondCompilation.GetSemanticModel(secondCompilation.SyntaxTrees.Single()));

            secondCompilationFinder.FindConstant(secondCompilationReturnExpression).Should().NotBeNull();
        }
        public void FieldDeclaredInAnotherSyntaxTree()
        {
            const string code1       = @"
public partial class Sample
{
    private static int Original = 42;
    private int Field = Original;
}";
            const string code2       = @"
public partial class Sample
{
    public int Method()
    {
        return Field;
    }
}";
            var          compilation = SolutionBuilder.Create().AddProject(AnalyzerLanguage.CSharp, createExtraEmptyFile: false)
                                       .AddSnippet(code1)
                                       .AddSnippet(code2)
                                       .GetCompilation();
            var tree             = compilation.SyntaxTrees.Single(x => x.GetRoot().DescendantNodes().OfType <MethodDeclarationSyntax>().Any());
            var returnExpression = tree.GetRoot().DescendantNodes().OfType <ReturnStatementSyntax>().Single().Expression;
            var finder           = new CSharpConstantValueFinder(compilation.GetSemanticModel(tree));

            finder.FindConstant(returnExpression).Should().Be(42);
        }
示例#16
0
        public void SetUp()
        {
            theScenario = SolutionGraphScenario.Create(scenario =>
            {
                scenario.Solution("Test", test =>
                {
                    test.SolutionDependency("FubuMVC.Core", "1.0.0.0", UpdateMode.Float);
                    test.ProjectDependency("Test", "FubuMVC.Core");
                });
            });

            FeedScenario.Create(scenario =>
            {
                scenario.For(Feed.Fubu)
                .Add("FubuCore", "1.1.0.0")
                .Add("Bottles", "1.0.0.5")
                .Add("FubuMVC.Core", "1.0.0.0")
                .ConfigureRepository(fubu =>
                {
                    fubu.ConfigurePackage("FubuMVC.Core", "1.0.0.0", mvc =>
                    {
                        mvc.DependsOn("FubuCore");
                        mvc.DependsOn("Bottles");
                    });
                });
            });

            theSolution = theScenario.Find("Test");

            RippleOperation
            .With(theSolution)
            .Execute <FixInput, FixCommand>();

            theSolution = SolutionBuilder.ReadFrom(theScenario.DirectoryForSolution("Test"));
        }
示例#17
0
        public void MethodsShouldUseBaseTypes_Internals()
        {
            var solution = SolutionBuilder.Create()
                           .AddProject(AnalyzerLanguage.CSharp)
                           .AddSnippet(@"
internal interface IFoo
{
    bool IsFoo { get; }
}

public class Foo : IFoo
{
    public bool IsFoo { get; set; }
}
").GetSolution()
                           .AddProject(AnalyzerLanguage.CSharp)
                           .AddProjectReference(sln => sln.ProjectIds[0])
                           .AddSnippet(@"
internal class Bar
{
    public void MethodOne(Foo foo)
    {
        var x = foo.IsFoo;
    }
}
").GetSolution();

            foreach (var compilation in solution.Compile())
            {
                DiagnosticVerifier.Verify(compilation, new MethodsShouldUseBaseTypes());
            }
        }
示例#18
0
        public static void AddBus(Bus template, string srcDirectory, string testDirectory, string projectBaseName, string solutionDirectory, IFileSystem fileSystem)
        {
            var messagesDirectory = Path.Combine(solutionDirectory, "Messages");

            var massTransitPackages = new Dictionary <string, string> {
                { "MassTransit", "7.2.4" },
                { "MassTransit.AspNetCore", "7.2.4" },
                { "MassTransit.Extensions.DependencyInjection", "7.2.4" },
                { "MassTransit.RabbitMQ", "7.2.4" }
            };
            var webApiClassPath = ClassPathHelper.WebApiProjectClassPath(srcDirectory, projectBaseName);

            Utilities.AddPackages(webApiClassPath, massTransitPackages);

            WebApiServiceExtensionsBuilder.CreateMassTransitServiceExtension(srcDirectory, projectBaseName, fileSystem);
            foreach (var env in template.Environments)
            {
                WebApiAppSettingsModifier.AddRmq(srcDirectory, env, projectBaseName, fileSystem);
                StartupModifier.RegisterMassTransitService(srcDirectory, env.EnvironmentName, projectBaseName);
            }

            IntegrationTestFixtureModifier.AddMassTransit(testDirectory, projectBaseName);

            SolutionBuilder.BuildMessagesProject(solutionDirectory);

            Utilities.AddProjectReference(webApiClassPath, @"..\..\..\Messages\Messages.csproj");
        }
示例#19
0
        public static void VerifyUtilityAnalyzer <TMessage>(IEnumerable <string> paths, UtilityAnalyzerBase diagnosticAnalyzer,
                                                            string protobufPath, Action <IList <TMessage> > verifyProtobuf, CompilationErrorBehavior checkMode = CompilationErrorBehavior.Default)
            where TMessage : IMessage <TMessage>, new()
        {
            var solutionBuilder = SolutionBuilder.CreateSolutionFromPaths(paths);

            foreach (var compilation in solutionBuilder.Compile())
            {
                DiagnosticVerifier.Verify(compilation, diagnosticAnalyzer, checkMode);

                verifyProtobuf(ReadProtobuf(protobufPath).ToList());
            }

            IEnumerable <TMessage> ReadProtobuf(string path)
            {
                using (var input = File.OpenRead(path))
                {
                    var parser = new MessageParser <TMessage>(() => new TMessage());
                    while (input.Position < input.Length)
                    {
                        yield return(parser.ParseDelimitedFrom(input));
                    }
                }
            }
        }
示例#20
0
        public static void ScaffoldApi(string buildSolutionDirectory, ApiTemplate template, IFileSystem fileSystem)
        {
            var projectName = template.ProjectName;

            AnsiConsole.Status()
            .AutoRefresh(true)
            .Spinner(Spinner.Known.Dots2)
            .Start($"[yellow]Creating {template.ProjectName} [/]", ctx =>
            {
                FileParsingHelper.RunPrimaryKeyGuard(template.Entities);
                FileParsingHelper.RunSolutionNameAssignedGuard(projectName);
                FileParsingHelper.SolutionNameDoesNotEqualEntityGuard(projectName, template.Entities);

                // add an accelerate.config.yaml file to the root?
                var bcDirectory   = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{projectName}";
                var srcDirectory  = Path.Combine(bcDirectory, "src");
                var testDirectory = Path.Combine(bcDirectory, "tests");
                fileSystem.Directory.CreateDirectory(srcDirectory);
                fileSystem.Directory.CreateDirectory(testDirectory);

                ctx.Spinner(Spinner.Known.BouncingBar);
                ctx.Status($"[bold blue]Building {projectName} Projects [/]");
                SolutionBuilder.AddProjects(buildSolutionDirectory, srcDirectory, testDirectory, template.DbContext.Provider, template.DbContext.DatabaseName, projectName, template.AddJwtAuthentication, fileSystem);

                // add all files based on the given template config
                ctx.Status($"[bold blue]Scaffolding Files for {projectName} [/]");
                RunTemplateBuilders(bcDirectory, srcDirectory, testDirectory, template, fileSystem);
                WriteLogMessage($"File scaffolding for {template.ProjectName} was successful");
            });
        }
示例#21
0
        public void can_read_the_solution()
        {
            var solution = SolutionBuilder.ReadFrom(theSolutionDir);

            solution.FindProject("ProjectA").ShouldNotBeNull();
            solution.FindProject("ProjectB").ShouldNotBeNull();
            solution.FindProject("ProjectC").ShouldNotBeNull();
        }
        private static void VerifyAnalyzer(string snippit, OptionStrict optionStrict)
        {
            var project     = SolutionBuilder.Create().AddProject(AnalyzerLanguage.VisualBasic).AddSnippet(snippit);
            var options     = new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optionStrict: optionStrict);
            var compilation = project.GetCompilation(null, options);

            DiagnosticVerifier.Verify(compilation, new OptionStrictOn(), CompilationErrorBehavior.Default);
        }
        public void OptionExplicitOn_IsOffForProject()
        {
            var project     = SolutionBuilder.Create().AddProject(AnalyzerLanguage.VisualBasic).AddSnippet("' Noncompliant ^1#0 {{Configure 'Option Explicit On' for assembly 'project0'.}}");
            var options     = new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optionExplicit: false); // optionExplicit is true by default => tested in other tests
            var compilation = project.GetCompilation(null, options);

            DiagnosticVerifier.Verify(compilation, new OptionExplicitOn(), CompilationErrorBehavior.Default);
        }
示例#24
0
        public Solution Find(string name)
        {
            var solution = SolutionBuilder.ReadFrom(_directory.AppendPath(name));

            solution.UseCache(NugetFolderCache.For(_cacheDirectory, solution));

            return(solution);
        }
示例#25
0
        public override SolutionBuilder.BuildResult ProcessBuildResult(
            VariableSet variables, Configuration configuration, SolutionBuilder.BuildResult buildResult
        )
        {
            Common.ProcessContentProjects(variables, configuration, buildResult, ContentProjectsProcessed);

            return base.ProcessBuildResult(variables, configuration, buildResult);
        }
        public void GenerateSolution(string masterConfiguration,
                                     string[] externalDefineConstants,
                                     PropertyElement[] propertyOverrides,
                                     string[] configurationFilter = null)
        {
            Reader.ReadFullSolution(propertyOverrides, masterConfiguration, configurationFilter);
            projectIdLookup = Reader.Modules
                              .SelectMany(kvp => kvp.Value.ProjectIdLookup)
                              .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            ValidateProjectIds();

            externalDefineConstants = externalDefineConstants ?? new string[0];

            Log.Heading("Generating solution '{0}' for master configuration '{1}'",
                        Reader.Solution.Name,
                        masterConfiguration);

            if (externalDefineConstants.Length > 0)
            {
                Log.Info("with external define constans:");
                Log.IndentedCollection(externalDefineConstants, Log.Info);
            }

            using (new CompositeDisposable(
                       new Log.ScopedIndent(),
                       new Log.ScopedTimer(Log.Level.Info, "Generate Solution")))
            {
                if (string.IsNullOrEmpty(masterConfiguration))
                {
                    masterConfiguration = Reader.Solution.ConfigurationGroups.Keys.First();
                    Log.Info("No master configuration was provided. Using default '{0}'.", masterConfiguration);
                }

                HashSet <string> includedProjects    = Reader.Solution.IncludedProjects;
                HashSet <string> generatableProjects = includedProjects
                                                       .Where(p => Reader.Solution.CanGenerateProject(p))
                                                       .ToHashSet();

                bool generateAll = includedProjects.SetEquals(generatableProjects);

                GenerateSolutionFiles("", Reader.Modules.Values, masterConfiguration, includedProjects,
                                      externalDefineConstants);

                if (Reader.Solution.GeneratedProjectsPatterns.Count > 0 && !generateAll)
                {
                    var builder = new SolutionBuilder(Reader.Solution, masterConfiguration);
                    builder.BuildAllConfigurations();

                    // Generate new solution with references to those DLLs.
                    IEnumerable <Module> updatedModules = ReplacePrebuiltReferences(generatableProjects);
                    GenerateSolutionFiles("-small", updatedModules, masterConfiguration, generatableProjects,
                                          externalDefineConstants);
                }
            }
        }
示例#27
0
        public Application(IAbout a)
        {
            var s = new InternalSaveActionSprite();

            s.AttachSpriteTo(a.Content);

            s.WebService = new ApplicationWebService();

            var pp = new ProjectNameInput();

            pp.AttachControlTo(a.Content);

            var Files = new IHTMLDiv().AttachTo(a.Content);

            s.WhenReady(
                i =>
            {
                Action Update = delegate
                {
                    var sln = new SolutionBuilder
                    {
                        Name = pp.ProjectName.Text
                    };

                    i.FileName = sln.Name + ".zip";
                    i.Clear();

                    Files.Clear();

                    sln.WriteTo(
                        (SolutionFile f) =>
                    {
                        new IHTMLPre {
                            innerText = f.Name
                        }.AttachTo(Files);

                        i.Add(f.Name, f.Content);
                    }
                        );
                };

                pp.UpdateButton.TextChanged +=
                    delegate
                {
                };

                pp.UpdateButton.Click +=
                    delegate
                {
                    Update();
                };

                Update();
            }
                );
        }
示例#28
0
        public static void VerifyNoExceptionThrown(string path, IEnumerable <DiagnosticAnalyzer> diagnosticAnalyzers)
        {
            var compilation = SolutionBuilder
                              .Create()
                              .AddProject(AnalyzerLanguage.FromPath(path))
                              .AddDocument(path)
                              .GetCompilation();

            var diagnostics = DiagnosticVerifier.GetAllDiagnostics(compilation, diagnosticAnalyzers);
        }
示例#29
0
        private Compilation GetEntityFrameworkMigrationCompilation()
        {
            var solutionBuilder = SolutionBuilder.CreateSolutionFromPaths(
                new string[] { @"TestCases\Performance\Bug2474_EntityFrameworkMigration.cs" },
                additionalReferences: GetEntityFrameworkReferencesNetCore("2.0.0"));

            var compilation = solutionBuilder.Compile(new CSharpParseOptions(LanguageVersion.Latest)).Single();

            return(compilation);
        }
        public void DisablingRequestValidation_CS_WebConfig(string root)
        {
            var webConfigPath = Path.Combine(root, WebConfig);

            DiagnosticVerifier.VerifyExternalFile(
                SolutionBuilder.Create().AddProject(AnalyzerLanguage.CSharp).GetCompilation(),
                new CS.DisablingRequestValidation(AnalyzerConfiguration.AlwaysEnabled),
                File.ReadAllText(webConfigPath),
                TestHelper.CreateSonarProjectConfig(root, TestHelper.CreateFilesToAnalyze(root, webConfigPath)));
        }
示例#31
0
        private static void VerifyEmpty(string name, string content, DiagnosticAnalyzer diagnosticAnalyzer)
        {
            var compilation = SolutionBuilder
                              .Create()
                              .AddProject(AnalyzerLanguage.CSharp, createExtraEmptyFile: false)
                              .AddSnippet(content, name)
                              .GetCompilation();

            DiagnosticVerifier.VerifyNoIssueReported(compilation, diagnosticAnalyzer);
        }
示例#32
0
        public static void VerifyAnalyzer(IEnumerable <string> paths, SonarDiagnosticAnalyzer diagnosticAnalyzer,
                                          IEnumerable <ParseOptions> options = null, params MetadataReference[] additionalReferences)
        {
            var solutionBuilder = SolutionBuilder.CreateSolutionFromPaths(paths, additionalReferences);

            foreach (var compilation in solutionBuilder.Compile(options?.ToArray()))
            {
                DiagnosticVerifier.Verify(compilation, diagnosticAnalyzer);
            }
        }
        public static void BeforeAll(TestContext context)
        {
            var solutionBuilder = new SolutionBuilder();
            var request = new BuildSolutionRequest()
                .WithSolutionName("NuGetSolutionValidator")
                .WithProjects(p => p.Name != "NugetSolutionValidator.Tests")
                .WithNuSpec("NuGetSolutionValidator")
                .WithNuSpecProjectSet("NuGetSolutionValidator", new[] { "NuGetSolutionValidator.NUnit" });

            _solution = solutionBuilder.Build(request);
        }
        public void DisablingRequestValidation_VB_WebConfig()
        {
            var root          = @"TestCases\WebConfig\DisablingRequestValidation\Values";
            var webConfigPath = Path.Combine(root, WebConfig);

            DiagnosticVerifier.VerifyExternalFile(
                SolutionBuilder.Create().AddProject(AnalyzerLanguage.VisualBasic).GetCompilation(),
                new VB.DisablingRequestValidation(AnalyzerConfiguration.AlwaysEnabled),
                File.ReadAllText(webConfigPath),
                TestHelper.CreateSonarProjectConfig(root, TestHelper.CreateFilesToAnalyze(root, webConfigPath)));
        }
示例#35
0
        public static void VerifyNoIssueReportedInTest(string path, SonarDiagnosticAnalyzer diagnosticAnalyzer,
                                                       IEnumerable <MetadataReference> additionalReferences = null)
        {
            var compilation = SolutionBuilder.Create()
                              .AddTestProject(AnalyzerLanguage.FromPath(path))
                              .AddReferences(additionalReferences)
                              .AddDocument(path)
                              .GetCompilation();

            DiagnosticVerifier.VerifyNoIssueReported(compilation, diagnosticAnalyzer);
        }
        public void BeforeAll()
        {
            var solutionBuilder = new SolutionBuilder();
            var request = new BuildSolutionRequest()
                .WithSolutionName("NuGetSolutionValidator")
                .WithProjects(p => p.Name.Contains("SampleProject"))
                //.WithNuSpec("NuGetSolutionValidator")
                //.WithNuSpecProjectSet("NuGetSolutionValidator", new[] { "NuGetSolutionValidator.NUnit" })
                ;

            _solution = solutionBuilder.Build(request);
        }
        public static void WriteConditionalCompilation(this SolutionProjectLanguage Language, SolutionFile File, PseudoIfExpression If, SolutionBuilder Context)
        {
            File.WriteSpace(PreprocessorDirectives.@if);
            Language.WritePseudoExpression(File, If.Expression, Context);
            File.WriteLine();

            Language.WriteMethodBody(File, If.TrueCase, Context);

            if (If.FalseCase != null)
            {
                File.WriteLine(PreprocessorDirectives.@else);
                Language.WriteMethodBody(File, If.FalseCase, Context);
            }

            File.WriteLine(PreprocessorDirectives.@endif);
        }
        public override void WriteType(SolutionFile File, SolutionProjectLanguageType Type, SolutionBuilder Context)
        {
            // http://msdn.microsoft.com/en-us/library/dd233205.aspx

            File.Write(this, Context, Type.Comments);

            File.Region(
                delegate
                {
                    WriteNamespace(File, Type.Namespace,
                        delegate
                        {
                            File.WriteUsingNamespaceList(this, Type);

                            File.WriteLine();

                            this.WriteSummary(
                                File,
                                Type.Summary
                            );

                            File.Region(
                                delegate
                                {
                                    File.WriteIndent();

                                    var Constructor = Type.Methods.SingleOrDefault(k => k.IsConstructor);


                                    if (Type.IsStatic)
                                    {
                                        File.WriteSpace(Keywords.@module);
                                        WriteTypeName(File, Type);
                                        File.WriteSpace();
                                        File.Write("=");

                                        File.WriteLine();

                                    }
                                    else
                                    {
                                        File.Write("[<Sealed>]");
                                        File.WriteLine();
                                        File.WriteIndent();

                                        File.WriteSpace(Keywords.type);

                                        if (Type.IsInternal)
                                        {
                                            File.WriteSpace(Keywords.@internal);
                                        }

                                        WriteTypeName(File, Type);
                                        File.Write("(");

                                        if (Constructor != null)
                                            this.InternalWriteParameters(File, Constructor, Constructor.Parameters.ToArray());

                                        File.WriteSpace(")");

                                        File.WriteSpace(Keywords.@as);
                                        File.WriteSpace("me");

                                        File.WriteSpace("=");
                                        File.WriteLine();

                                        File.Indent(this,
                                            delegate
                                            {
                                                if (Type.BaseType != null)
                                                {
                                                    File.WriteIndent();
                                                    File.WriteSpace(Keywords.@inherit);

                                                    WriteTypeName(File, Type.BaseType);
                                                    File.Write("(");
                                                    File.WriteSpace(")");
                                                    File.WriteLine();
                                                }

                                                // only need this if there are any members beyond ctor?
                                                File.WriteIndent();
                                                File.WriteSpace(Keywords.@let);
                                                File.Write("this");
                                                File.WriteSpaces("=");
                                                File.Write("me");
                                                File.WriteLine();

                                                File.WriteLine();

                                                File.WriteIndent();
                                                File.WriteSpace(Keywords.@do);
                                                File.Write("()");
                                                File.WriteLine();

                                                File.WriteLine();
                                            }
                                        );


                                    }

                                    // .ctor !

                                    File.Indent(this,
                                        delegate
                                        {
                                            if (!Type.IsStatic)
                                            {
                                                #region Fields with FieldConstructor
                                                Type.Fields.WithEach(
                                                    Field =>
                                                    {
                                                        // http://msdn.microsoft.com/en-us/library/dd469494.aspx




                                                        if (Field.FieldConstructor != null)
                                                        {
                                                            File.WriteIndent().WriteSpace(Keywords.let).Write(Field.Name).WriteSpaces("=");
                                                            this.WritePseudoCallExpression(File, Field.FieldConstructor, Context);
                                                        }
                                                        else
                                                        {
                                                            // first asignment shall do a let
                                                            if (Field.IsReadOnly)
                                                                return;

                                                            File.WriteIndent().WriteSpace(Keywords.let).WriteSpace(Keywords.mutable);
                                                            File.Write(Field.Name).WriteSpaces(":");
                                                            WriteTypeName(File, Field.FieldType);

                                                            File.WriteSpaces("=").Write(Keywords.@null);
                                                        }

                                                        File.WriteLine();
                                                    }
                                                );
                                                #endregion


                                                if (Constructor != null)
                                                {
                                                    this.WriteMethodBody(
                                                        File, Constructor.Code, Context
                                                    );
                                                }

                                                File.WriteLine();
                                                File.WriteLine();
                                            }

                                            foreach (var item in (from m in Type.Methods where !m.IsConstructor select m).ToArray())
                                            {
                                                if (item.DeclaringType == null)
                                                    item.DeclaringType = Type;

                                                this.WriteMethod(
                                                    File,
                                                    item,
                                                    Context
                                                );

                                                File.WriteLine();
                                            }



                                        }
                                    );
                                }
                            );
                        }
                    );
                }
            );

        }
        public override void WriteMethodBody(SolutionFile File, SolutionProjectLanguageCode Code, SolutionBuilder Context)
        {

            var History = Code.History.ToArray();

            for (int i = 0; i < History.Length; i++)
            {
                var IsReturnStatement = false;

                Code.OwnerMethod.With(
                    m =>
                    {
                        if (m.ReturnType == null)
                            return;

                        if (m.IsConstructor)
                            return;

                        IsReturnStatement = i == History.Length - 1;
                    }
                );


                var item = History[i];

                #region Comment
                {
                    var Comment = item as string;
                    if (Comment != null)
                    {
                        File.WriteIndent();
                        this.WriteCommentLine(File, Comment);
                    }
                }

                {
                    var Comment = item as SolutionFileComment;
                    if (Comment != null)
                    {
                        Comment.WriteTo(File, this, Context);
                        return;
                    }
                }
                #endregion

                #region If
                var If = item as PseudoIfExpression;

                if (If != null)
                {
                    if (If.IsConditionalCompilationDirective)
                    {
                        this.WriteConditionalCompilation(File, If, Context);

                    }
                    else
                    {

                        File.WriteIndent();
                        File.WriteSpace(Keywords.@if);
                        WritePseudoExpression(File, If.Expression, Context);
                        File.WriteSpace();
                        File.Write(Keywords.@then);
                        File.WriteLine();

                        WriteMethodBody(File, If.TrueCase, Context);

                        if (If.FalseCase != null)
                        {
                            File.WriteIndent();
                            File.WriteSpace(Keywords.@else);
                            File.WriteLine();

                            WriteMethodBody(File, If.FalseCase, Context);
                        }
                    }

                    return;
                }
                #endregion

                #region Lambda
                var Lambda = item as PseudoCallExpression;

                if (Lambda != null)
                {
                    if (Lambda.Comment != null)
                        Lambda.Comment.WriteTo(File, this, Context);

                    if (Lambda.Method != null)
                    {
                        File.WriteIndent();

                        if (IsReturnStatement)
                        {
                            WritePseudoCallExpression(File, Lambda, Context);
                        }
                        else
                        {
                            var ImplicitField = default(SolutionProjectLanguageField);

                            if (Lambda.Method.IsProperty && Lambda.Object is PseudoThisExpression)
                                ImplicitField = Code.OwnerMethod.DeclaringType.Fields.FirstOrDefault(
                                    k => k.Name == Lambda.Method.Name.SkipUntilIfAny("set_") && k.IsReadOnly
                                );

                            if (ImplicitField != null)
                            {
                                File.WriteSpace(Keywords.let).Write(ImplicitField.Name).WriteSpaces("=");


                                WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                            }
                            else
                            {

                                File.WriteSpace(Keywords.@do);

                                // we could group next similar statements in a single do
                                WritePseudoCallExpression(File, Lambda, Context);

                                if (Lambda.Method.ReturnType != null)
                                {
                                    File.WriteSpaces("|>");
                                    File.Write(Keywords.ignore);
                                }
                            }
                        }

                        File.WriteLine();
                    }
                }
                #endregion

            }



        }
        public override void WriteAssemblyAttribute(SolutionFile File, SolutionProjectLanguageAttribute Attribute, SolutionBuilder Context)
        {
            // http://msdn.microsoft.com/en-us/library/dd233179.aspx

            File.WriteIndent();
            File.Write("[");
            File.Write("<");
            File.Write(Keywords.assembly);
            File.Write(": ");

            this.WriteTypeName(File, Attribute.Type);
            File.Write("(");

            var args = new List<Action>();

            if (Attribute.Parameters != null)
            {
                args.AddRange(
                    from item in Attribute.Parameters
                    select (Action)delegate
                    {
                        this.WritePseudoExpression(File, item, Context);
                    }
                );
            }


            if (Attribute.Properties != null)
            {
                args.AddRange(
                    from item in Attribute.Properties.ToArray()
                    select (Action)delegate
                    {
                        this.WritePseudoCallExpression(File,
                            new PseudoCallExpression
                            {
                                IsAttributeContext = true,
                                Method = item.Key,
                                ParameterExpressions = new[] {
										item.Value
									}
                            }
                            , Context
                        );
                    }
                );

            }

            Action Separator = delegate
            {
                File.Write(",");
                File.WriteSpace();
            };

            var BeforeSeparator = args.ToArray();
            var AfterSeparator = BeforeSeparator.SelectWithSeparator(Separator).ToArray();

            AfterSeparator.Invoke();

            File.Write(")");
            File.Write(">");
            File.Write("]");

            File.WriteSpace();
            File.Write(Keywords.@do);
            File.Write("()");

            File.WriteLine();
        }
        public override void WriteMethod(SolutionFile File, SolutionProjectLanguageMethod Method, SolutionBuilder Context)
        {
            #region WriteMethodBody
            Action WriteMethodBody =
                delegate
                {
                    this.WriteMethodBody(File, Method.Code, Context);

                    if (!Method.IsConstructor)
                    {
                        File.WriteIndent();

                        // empty?
                        var IsStatic = Method.IsStatic;

                        if (Method.DeclaringType != null)
                            if (Method.DeclaringType.IsStatic)
                                IsStatic = true;

                        if (IsStatic)
                        {
                            File.Write("0");
                        }
                        else
                        {
                            if (Method.ReturnType == null)
                                File.Write("()");
                        }

                        File.WriteLine();
                    }
                };
            #endregion


            if (Method.IsLambda)
            {
                var Parameters = Method.Parameters.ToQueue();

                var rec = default(Action<bool>);

                rec = WriteIndent =>
                {
                    if (WriteIndent)
                        File.WriteIndent();

                    File.WriteSpace(Keywords.fun);

                    if (Parameters.Count == 0)
                    {
                        File.Write("(").Write(")").WriteSpace();
                    }
                    else
                    {
                        InternalWriteParameters(File, Method, Parameters.Dequeue());
                    }

                    File.WriteSpaces("->").WriteLine();

                    File.Indent(this,
                        delegate
                        {
                            if (Parameters.Count == 0)
                                WriteMethodBody();
                            else
                                rec(true);
                        }
                    );

                };

                rec(false);

            }
            else
            {
                this.WriteSummary(File, Method.Summary, Method.Parameters.ToArray());


                File.WriteIndent();

                if (Method.Name == "Main")
                {
                    File.Write("[<Microsoft.FSharp.Core.EntryPoint>]");
                    File.WriteLine();
                    File.WriteIndent();
                }

                if (Method.DeclaringType.IsStatic)
                {
                    File.WriteSpace(Keywords.let);
                }
                else
                {
                    if (Method.IsOverride)
                        File.WriteSpace(Keywords.@override);
                    else
                        File.WriteSpace(Keywords.member);

                    File.Write("this").Write(".");
                }
                File.Write(Method.Name);
                File.Write("(");
                InternalWriteParameters(File, Method, Method.Parameters.ToArray());
                File.Write(")");
                File.WriteSpace().WriteLine("=");
                File.Indent(this, WriteMethodBody);
            }


        }
        public override void WritePseudoCallExpression(SolutionFile File, PseudoCallExpression Lambda, SolutionBuilder Context)
        {
            if (Lambda.Method.Name == SolutionProjectLanguageMethod.op_Implicit)
            {
                WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                return;
            }

            if (Lambda.Method.OperatorName != null)
            {
                if (Lambda.ParameterExpressions.Length == 2)
                {
                    WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                    File.WriteSpaces(Lambda.Method.OperatorName);
                    WritePseudoExpression(File, Lambda.ParameterExpressions[1], Context);

                    return;
                }
            }

            if (Lambda.Method.IsConstructor)
            {
                File.Write(Keywords.New);
                File.WriteSpace();
                WriteTypeName(File, Lambda.Method.DeclaringType);
                InternalWriteParameterList(File, Lambda, Context);
                return;
            }

            if (Lambda.Method.IsEvent)
            {
                if (Lambda.Method.Name.StartsWith("add_"))
                {
                    File.WriteSpace(Keywords.AddHandler);
                }
            }

            var Objectless = true;

            if (IsExtensionMethod(Lambda))
            {
                WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                Objectless = false;
            }
            else
            {
                if (Lambda.Method.IsStatic)
                {
                    if (Lambda.Method.DeclaringType != null)
                    {
                        WriteTypeName(File, Lambda.Method.DeclaringType);
                        Objectless = false;
                    }
                }
                else
                {
                    if (Lambda.Object != null)
                    {
                        WritePseudoExpression(File, Lambda.Object, Context);
                        Objectless = false;
                    }
                }
            }


            if (Lambda.Method.Name == "Invoke")
            {
                // in c# we can omit the .Invoke on a delegate
            }
            else
            {
                var Target = Lambda.Method.Name;

                if (Lambda.Method.IsProperty)
                {
                    Target = Target.SkipUntilIfAny("set_").SkipUntilIfAny("get_");
                }
                else if (Lambda.Method.IsEvent)
                {
                    Target = Target.SkipUntilIfAny("add_").SkipUntilIfAny("remove_");
                }

                if (!Objectless)
                {
                    File.Write(".");
                }

                File.Write(
                    new SolutionFileWriteArguments
                    {
                        Fragment = SolutionFileTextFragment.None,
                        Text = Target,
                        Tag = Lambda.Method
                    }
                );
            }

            if (Lambda.Method.IsEvent)
            {
                if (Lambda.Method.Name.StartsWith("add_"))
                {
                    File.WriteSpace(",");
                    WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                }
            }
            else if (Lambda.Method.IsProperty)
            {

                if (Lambda.ParameterExpressions.Length == 1)
                {
                    File.WriteSpace();

                    if (Lambda.IsAttributeContext)
                    {
                        File.Write(":=");
                    }
                    else
                    {
                        File.Write("=");
                    }

                    File.WriteSpace();
                    WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                }

            }
            else
            {

                InternalWriteParameterList(File, Lambda, Context);
            }


        }
        private void InternalWriteParameterList(SolutionFile File, PseudoCallExpression Lambda, SolutionBuilder Context)
        {
            File.Write("(");

            #region HasComplexParameter
            var HasComplexParameter = Lambda.ParameterExpressions.Any(
                k =>
                {
                    if (k is XElement)
                        return true;

                    // anonymous method!
                    if (k is SolutionProjectLanguageMethod)
                        return true;


                    var Call = k as PseudoCallExpression;
                    if (Call != null)
                    {
                        // what? :) 
                        if (Call.XLinq != null)
                            return true;
                    }

                    
                    return false;
                }
            );
            #endregion

            Action Body =
                delegate
                {
                    var Parameters = Lambda.ParameterExpressions.ToArray();

                    var FirstParameter = 0;

                    if (IsExtensionMethod(Lambda))
                        FirstParameter = 1;

                    for (int i = FirstParameter; i < Parameters.Length; i++)
                    {
                        if (i > FirstParameter)
                        {
                            if (HasComplexParameter)
                            {
                                File.WriteLine(",");
                                File.WriteIndent();
                            }
                            else
                            {
                                File.WriteSpace(",");
                            }
                        }

                        var Parameter = Parameters[i];

                        WritePseudoExpression(File, Parameter, Context);
                    }
                };

            if (HasComplexParameter)
            {
                File.WriteLine();
                File.Indent(this,
                    delegate
                    {
                        if (Lambda.ParameterExpressions.FirstOrDefault() is XElement)
                        {
                            // xlinq has no indent...
                        }
                        else
                        {
                            File.WriteIndent();
                        }

                        Body();

                        //File.WriteLine();
                    }
                );
                File.WriteIndent();
            }
            else
            {
                Body();
            }

            File.Write(")");
        }
        public override void WriteAssemblyAttribute(SolutionFile File, SolutionProjectLanguageAttribute Attribute, SolutionBuilder Context)
        {
            File.Write("[");
            File.Write(Keywords.assembly);
            File.Write(": ");

            this.WriteTypeName(File, Attribute.Type);
            File.Write("(");

            var args = new List<Action>();

            if (Attribute.Parameters != null)
            {
                args.AddRange(
                    from item in Attribute.Parameters
                    select (Action)delegate
                    {
                        this.WritePseudoExpression(File, item, Context);
                    }
                );
            }


            if (Attribute.Properties != null)
            {
                args.AddRange(
                    from item in Attribute.Properties.ToArray()
                    select (Action)delegate
                    {
                        this.WritePseudoCallExpression(File,
                            new PseudoCallExpression
                            {
                                Method = item.Key,
                                ParameterExpressions = new[] {
										item.Value
									}
                            }, Context
                        );
                    }
                );

            }

            Action Separator = delegate
            {
                File.Write(", ");
            };

            var BeforeSeparator = args.ToArray();
            var AfterSeparator = BeforeSeparator.SelectWithSeparator(Separator).ToArray();

            AfterSeparator.Invoke();

            File.Write(")");
            File.Write("]");

            File.WriteLine();
        }
示例#45
0
文件: Base.cs 项目: Don191/JSIL
 public abstract bool IsAppropriateForSolution (SolutionBuilder.BuildResult buildResult);
示例#46
0
 public override bool IsAppropriateForSolution(SolutionBuilder.BuildResult buildResult)
 {
     return buildResult.TargetFilesUsed.Any(
         (targetFile) => targetFile.Contains(@"XNA Game Studio\v4.0")
     );
 }
示例#47
0
文件: Base.cs 项目: Don191/JSIL
 public virtual SolutionBuilder.BuildResult ProcessBuildResult (
     VariableSet variables, Configuration configuration, SolutionBuilder.BuildResult buildResult
 ) {
     return buildResult;
 }
        public override void WritePseudoExpression(SolutionFile File, object Parameter, SolutionBuilder Context)
        {
            var Code = Parameter as string;
            if (Code != null)
            {
                File.Write(Code);
                return;
            }

            var Argument = Parameter as SolutionProjectLanguageArgument;
            if (Argument != null)
            {
                File.Write(Argument.Name);
                return;
            }

            {
                var Constant = Parameter as PseudoStringConstantExpression;
                if (Constant != null)
                {
                    var Value = (string)Constant.Value;
                    File.Write(SolutionFileTextFragment.String,
                        // jsc escape string
                        "@\"" + Value.Replace("\"", "\"\"") + "\""
                    );
                    return;
                }
            }

            {
                var Constant = Parameter as PseudoInt32ConstantExpression;
                if (Constant != null)
                {
                    File.Write("" + Constant.Value);
                    return;
                }
            }

            {
                var Constant = Parameter as PseudoDoubleConstantExpression;
                if (Constant != null)
                {
                    var Value = "" + Constant.Value;
                    if (!Value.Contains("."))
                        Value += ".0";

                    File.Write(Value);
                    return;
                }
            }
            var Call = Parameter as PseudoCallExpression;
            if (Call != null)
            {
                WritePseudoCallExpression(File, Call, Context);
                return;
            }

            var This = Parameter as PseudoThisExpression;
            if (This != null)
            {
                File.Write(Keywords.@this);
                return;
            }

            var Base = Parameter as PseudoBaseExpression;
            if (Base != null)
            {
                File.Write(Keywords.@base);
                return;
            }


            var Type = Parameter as SolutionProjectLanguageType;
            if (Type != null)
            {
                File.Write(Keywords.@typeof);
                File.Write("(");
                WriteTypeName(File, Type);
                File.Write(")");
                return;
            }

            var XElement = Parameter as XElement;
            if (XElement != null)
            {
                WritePseudoCallExpression(File, XElement.ToPseudoCallExpression(), Context);
                return;
            }

            var Method = Parameter as SolutionProjectLanguageMethod;
            if (Method != null)
            {
                WriteMethod(File, Method, Context);
                return;
            }

            // F# match would be awesome here? :)
            var Field = Parameter as SolutionProjectLanguageField;
            if (Field != null)
            {
                // DeclaringType Object?
                File.Write(Field.Name);
            }


            #region PseudoArrayExpression
            var Array = Parameter as PseudoArrayExpression;
            if (Array != null)
            {
                File.Indent(this,
                    delegate
                    {
                        File.WriteLine();
                        File.WriteIndent();

                        File.Write(Keywords.@new);
                        File.WriteSpace();

                        WriteTypeName(File, Array.ElementType);
                        File.Write("[]");

                        File.WriteSpace();
                        File.Write("{");

                        File.Indent(this,
                            delegate
                            {
                                File.WriteLine();
                                File.WriteIndent();

                                Func<object, Action> AtWritePseudoExpression = k => () => WritePseudoExpression(File, k, Context);

                                Action WriteSeparator =
                                    delegate
                                    {
                                        File.Write(",");
                                        File.WriteLine();
                                        File.WriteIndent();
                                    };

                                Array.Items.ToArray().Select(AtWritePseudoExpression).SelectWithSeparator(WriteSeparator).Invoke();

                            }
                        );

                        File.WriteLine();
                        File.WriteIndent();

                        File.Write("}");

                    }
                );

                File.WriteLine();
                File.WriteIndent();

                return;
            }
            #endregion

        }
        public override void WriteType(SolutionFile File, SolutionProjectLanguageType Type, SolutionBuilder Context)
        {
            File.Write(this, Context, Type.Comments);

            File.WriteUsingNamespaceList(this, Type);


            File.WriteLine();

            File.Region(
                delegate
                {
                    WriteNamespace(File, Type.Namespace,
                        delegate
                        {

                            if (Type.Summary != null)
                                this.WriteSummary(
                                    File,
                                    Type.Summary
                                );

                            File.Region(
                                delegate
                                {
                                    File.WriteIndent();

                                    if (Type.IsInternal)
                                    {
                                        File.WriteSpace(Keywords.@internal);
                                    }
                                    else
                                    {
                                        File.WriteSpace(Keywords.@public);
                                    }

                                    if (Type.IsStatic)
                                    {
                                        File.WriteSpace(Keywords.@static);
                                    }


                                    if (Type.IsSealed)
                                    {
                                        File.WriteSpace(Keywords.@sealed);
                                    }

                                    if (Type.IsPartial)
                                    {
                                        File.WriteSpace(Keywords.@partial);
                                    }


                                    if (Type.IsInterface)
                                    {
                                        File.WriteSpace(Keywords.@interface);
                                    }
                                    else
                                    {
                                        File.WriteSpace(Keywords.@class);
                                    }

                                    File.Write(Type);

                                    if (Type.BaseType != null)
                                    {
                                        File.WriteSpaces(":");
                                        WriteTypeName(File, Type.BaseType);
                                    }

                                    File.WriteLine();

                                    File.WriteIndent();
                                    File.WriteLine("{");
                                    File.Indent(this,
                                        delegate
                                        {
                                            #region Fields
                                            Type.Fields.WithEach(
                                                Field =>
                                                {
                                                    this.WriteSummary(File, Field.Summary);

                                                    File.WriteIndent();

                                                    if (Field.IsPrivate)
                                                    {
                                                        File.WriteSpace(Keywords.@private);
                                                    }
                                                    else
                                                    {
                                                        File.WriteSpace(Keywords.@public);
                                                    }

                                                    if (Field.IsReadOnly)
                                                    {
                                                        File.WriteSpace(Keywords.@readonly);
                                                    }

                                                    WriteTypeName(File, Field.FieldType);
                                                    File.WriteSpace().Write(Field.Name);

                                                    if (Field.FieldConstructor != null)
                                                    {
                                                        File.WriteSpaces("=");
                                                        this.WritePseudoCallExpression(File, Field.FieldConstructor, Context);
                                                    }

                                                    File.WriteLine(";");

                                                    File.WriteLine();
                                                }
                                            );


                                            #endregion


                                            #region Properties
                                            foreach (var m in Type.Properties.ToArray())
                                            {
                                                File.WriteIndent();

                                                if (Type.IsInterface)
                                                {

                                                }
                                                else
                                                {
                                                    File.Write(Keywords.@public);
                                                    File.WriteSpace();

                                                    if (m.IsStatic)
                                                    {
                                                        File.Write(Keywords.@static);
                                                        File.WriteSpace();
                                                    }
                                                }

                                                WriteTypeName(File, m.PropertyType);
                                                File.WriteSpace();
                                                File.Write(m.Name);

                                                if (m.IsAutoProperty)
                                                {
                                                    File.WriteSpace();
                                                    File.Write("{");
                                                }
                                                else
                                                {
                                                    File.WriteLine();
                                                    File.WriteIndent();
                                                    File.WriteLine("{");
                                                }


                                                Action<SolutionProjectLanguageMethod, Keyword> Property = (mm, kk) =>
                                                {
                                                    if (mm != null)
                                                    {
                                                        if (m.IsAutoProperty)
                                                        {
                                                            File.WriteSpace();
                                                        }
                                                        else
                                                        {
                                                            File.WriteIndent();
                                                        }
                                                        File.Write(kk);
                                                        if (mm.Code == null)
                                                        {
                                                            File.Write(";");
                                                            if (m.IsAutoProperty)
                                                            {
                                                            }
                                                            else
                                                            {
                                                                File.WriteLine();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            File.WriteLine();
                                                            this.WriteMethodBody(File, mm.Code, Context);
                                                        }
                                                    }
                                                };

                                                Action PropertyBody = delegate
                                                {
                                                    Property(m.GetMethod, Keywords.get);
                                                    Property(m.SetMethod, Keywords.set);
                                                };

                                                Action<Action> PropertyIndent = Body => File.Indent(this, Body);

                                                if (m.IsAutoProperty)
                                                {
                                                    PropertyBody();
                                                    File.WriteSpace();
                                                }
                                                else
                                                {
                                                    File.Indent(this, PropertyBody);
                                                    File.WriteIndent();
                                                }


                                                File.WriteLine("}");
                                            }
                                            #endregion

                                            if (Type.Properties.Any())
                                                File.WriteLine();

                                            foreach (var item in Type.Methods.ToArray())
                                            {
                                                if (item.DeclaringType == null)
                                                    item.DeclaringType = Type;

                                                this.WriteMethod(
                                                    File,
                                                    item,
                                                    Context
                                                );

                                                File.WriteLine();
                                            }


                                        }
                                    );

                                    File.WriteIndent().WriteLine("}");
                                }
                            );
                        }
                    );


                }
            );

        }
示例#50
0
 public override bool IsAppropriateForSolution(SolutionBuilder.BuildResult buildResult)
 {
     // Normally we'd return true so that this profile is always selected, but this is our fallback profile.
     return false;
 }
        public override void WritePseudoExpression(SolutionFile File, object Parameter, SolutionBuilder Context)
        {
            var Code = Parameter as string;
            if (Code != null)
            {
                File.Write(Code);
                return;
            }


            var Argument = Parameter as SolutionProjectLanguageArgument;
            if (Argument != null)
            {
                File.Write(Argument.Name);
                return;
            }

            {
                var Constant = Parameter as PseudoStringConstantExpression;
                if (Constant != null)
                {
                    var Value = (string)Constant.Value;
                    File.Write(SolutionFileTextFragment.String,
                        // jsc escape string
                        "\"" + Value.Replace("\"", "\"\"") + "\""
                    );
                    return;
                }
            }


            {
                var Constant = Parameter as PseudoInt32ConstantExpression;
                if (Constant != null)
                {
                    File.Write("" + Constant.Value);
                    return;
                }
            }

            {
                var Constant = Parameter as PseudoDoubleConstantExpression;
                if (Constant != null)
                {
                    var Value = "" + Constant.Value;
                    if (!Value.Contains("."))
                        Value += ".0";

                    File.Write(Value);
                    return;
                }
            }

            var Call = Parameter as PseudoCallExpression;
            if (Call != null)
            {
                WritePseudoCallExpression(File, Call, Context);
                return;
            }

            var This = Parameter as PseudoThisExpression;
            if (This != null)
            {
                File.Write(Keywords.Me);
                return;
            }

            var Base = Parameter as PseudoBaseExpression;
            if (Base != null)
            {
                File.Write(Keywords.MyBase);
                return;
            }


            var Type = Parameter as SolutionProjectLanguageType;
            if (Type != null)
            {
                File.Write(Keywords.@GetType);
                File.Write("(");
                WriteTypeName(File, Type);
                File.Write(")");
                return;
            }

            var XElement = Parameter as XElement;
            if (XElement != null)
            {
                var x = File.IndentStack;

                var xx = XElement.Nodes().Last() as XText;
                if (xx != null)
                {
                    var Padding = xx.Value.SkipUntilLastOrEmpty("\n");
                    File.Write(Padding);
                }

                File.IndentStack = new Stack<Action>();
                File.WriteXElement(XElement);

                File.IndentStack = x;
                File.WriteLine();
                File.WriteIndent();
                return;
            }

            var Method = Parameter as SolutionProjectLanguageMethod;
            if (Method != null)
            {
                WriteMethod(File, Method, Context);
                return;
            }

            // F# match would be awesome here? :)
            var Field = Parameter as SolutionProjectLanguageField;
            if (Field != null)
            {
                // DeclaringType Object?
                File.Write(Field.Name);
                return;
            }

        }
        public override void WriteMethod(SolutionFile File, SolutionProjectLanguageMethod m, SolutionBuilder Context)
        {
            if (!m.IsLambda)
                if (m.Summary != null)
                    this.WriteSummary(File, m.Summary, m.Parameters.ToArray());

            File.Region(
                delegate
                {
                    if (m.IsLambda)
                    {
                        var Parameters = m.Parameters.ToArray();

                        if (Parameters.Length != 1)
                            File.Write("(");


                        for (int i = 0; i < Parameters.Length; i++)
                        {
                            if (i > 0)
                            {
                                File.WriteSpace(",");
                            }

                            File.Write(Parameters[i].Name);
                        }

                        if (Parameters.Length != 1)
                            File.WriteSpace(")");
                        else
                            File.WriteSpace();

                        File.WriteSpace("=>");

                        if (m.Code.History.Count != 1)
                            File.WriteLine();

                        this.WriteMethodBody(File, m.Code, Context);

                        return;

                    }
                    #region not lambda
                    File.WriteIndent();

                    if (m.IsPrivate)
                    {
                        File.Write(Keywords.@private);
                    }
                    else if (m.IsProtected)
                    {
                        File.Write(Keywords.@protected);
                    }
                    else
                    {
                        File.Write(Keywords.@public);
                    }
                    File.WriteSpace();

                    if (m.IsOverride)
                    {
                        File.WriteSpace(Keywords.@override);
                    }


                    if (m.IsStatic)
                    {
                        File.WriteSpace(Keywords.@static);
                    }

                    if (m.IsConstructor)
                    {
                        WriteTypeName(File, m.DeclaringType);
                    }
                    else
                    {
                        File.WriteSpace(Keywords.@void).Write(m.Name);
                    }
                    #endregion

                    {

                        var Parameters = m.Parameters.ToArray();


                        File.Write("(");


                        for (int i = 0; i < Parameters.Length; i++)
                        {
                            if (i > 0)
                            {
                                File.WriteSpace(",");
                            }

                            this.WriteTypeName(File, Parameters[i].Type);

                            File.WriteSpace();
                            File.Write(Parameters[i].Name);
                        }


                        File.Write(")");
                    }

                    if (m.Code == null)
                    {
                        File.WriteLine(";");
                    }
                    else
                    {
                        File.WriteLine();

                        this.WriteMethodBody(File, m.Code, Context);

                        if (!m.IsLambda)
                        {
                            File.WriteLine();
                        }
                    }
                }
            );
        }
        public override void WritePseudoCallExpression(SolutionFile File, ScriptCoreLib.Ultra.Studio.PseudoExpressions.PseudoCallExpression Lambda, SolutionBuilder Context)
        {
            if (Lambda.Method.IsConstructor)
            {
                File.Write(Keywords.@new);
                File.WriteSpace();
                WriteTypeName(File, Lambda.Method.DeclaringType);
                InternalWriteParameterList(File, Lambda, Context);
                return;
            }

            if (Lambda.Method.OperatorName != null)
            {
                if (Lambda.ParameterExpressions.Length == 2)
                {
                    WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                    File.WriteSpaces(Lambda.Method.OperatorName);
                    WritePseudoExpression(File, Lambda.ParameterExpressions[1], Context);

                    return;
                }
            }


            var Objectless = true;

            if (IsExtensionMethod(Lambda))
            {
                WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                Objectless = false;
            }
            else
            {
                if (Lambda.Method.IsStatic)
                {
                    if (Lambda.Method.DeclaringType != null)
                    {
                        WriteTypeName(File, Lambda.Method.DeclaringType);
                        Objectless = false;
                    }
                }
                else
                {
                    if (Lambda.Object != null)
                    {
                        var Constructor = Lambda.Object as PseudoExpressions.PseudoCallExpression;
                        if (Constructor != null)
                        {
                            if (!Constructor.Method.IsConstructor)
                                Constructor = null;
                        }

                        if (Constructor != null)
                        {
                            File.Write("(");
                        }
                        WritePseudoExpression(File, Lambda.Object, Context);
                        if (Constructor != null)
                        {
                            File.Write(")");
                        }
                        Objectless = false;
                    }
                }
            }



            var Target = Lambda.Method.Name;

            if (Lambda.Method.IsProperty)
            {
                Target = Target.SkipUntilIfAny("set_").SkipUntilIfAny("get_");

            }

            if (!Objectless)
            {
                File.Write(".");
            }

            File.Write(
                new SolutionFileWriteArguments
                {
                    Fragment = SolutionFileTextFragment.None,
                    Text = Target,
                    Tag = Lambda.Method
                }
            );

            if (Lambda.Method.IsProperty)
            {
                if (Lambda.ParameterExpressions.Length == 1)
                {
                    File.WriteSpace();
                    if (Lambda.IsAttributeContext)
                        File.WriteSpace("=");
                    else
                        File.WriteSpace("<-");
                    WritePseudoExpression(File, Lambda.ParameterExpressions[0], Context);
                }

            }
            else
            {
                InternalWriteParameterList(File, Lambda, Context);
            }
        }
        public override void WriteMethodBody(SolutionFile File, SolutionProjectLanguageCode Code, SolutionBuilder Context)
        {
            // should this be an extension method to all languages?

            Action WriteCodeStatements =
                delegate
                {
                    var History = Code.History.ToArray();

                    for (int i = 0; i < History.Length; i++)
                    {
                        var IsReturnStatement = false;

                        Code.OwnerMethod.With(
                            m =>
                            {
                                if (m.ReturnType == null)
                                    return;

                                if (m.IsConstructor)
                                    return;

                                IsReturnStatement = i == History.Length - 1;
                            }
                        );


                        var item = History[i];

                        {
                            var Comment = item as string;
                            if (Comment != null)
                            {
                                File.WriteIndent();
                                this.WriteCommentLine(File, Comment);
                            }
                        }

                        {
                            var Comment = item as SolutionFileComment;
                            if (Comment != null)
                            {
                                Comment.WriteTo(File, this, Context);
                                return;
                            }
                        }

                        var If = item as PseudoIfExpression;

                        if (If != null)
                        {
                            if (If.IsConditionalCompilationDirective)
                            {

                                this.WriteConditionalCompilation(File, If, Context);

                            }
                            else
                            {

                                File.WriteIndent().WriteSpace(Keywords.@if);
                                File.Write("(");
                                WritePseudoExpression(File, If.Expression, Context);
                                File.Write(")");
                                File.WriteLine();

                                WriteMethodBody(File, If.TrueCase, Context);
                                File.WriteLine();

                                if (If.FalseCase != null)
                                {
                                    File.WriteIndent().WriteLine(Keywords.@else);

                                    WriteMethodBody(File, If.FalseCase, Context);
                                }
                            }

                            return;
                        }

                        var Lambda = item as PseudoCallExpression;

                        if (Lambda != null)
                        {
                            if (Code.IsLambdaExpression)
                            {
                                WritePseudoCallExpression(File, Lambda, Context);
                            }
                            else
                            {
                                if (Lambda.Comment != null)
                                    Lambda.Comment.WriteTo(File, this, Context);

                                if (Lambda.Method != null)
                                {
                                    File.WriteIndent();

                                    if (IsReturnStatement)
                                    {
                                        File.WriteSpace(Keywords.@return);
                                    }

                                    WritePseudoCallExpression(File, Lambda, Context);
                                    File.WriteLine(";");
                                }
                            }
                        }
                    }
                };

            Action WriteCodeStatementsAsBlock =
                delegate
                {
                    File.WriteIndent().WriteLine("{");
                    File.Indent(this, WriteCodeStatements);
                    File.WriteIndent().Write("}");
                };

            Code.OwnerIfExpression.With(n => n.IsConditionalCompilationDirective, n => WriteCodeStatementsAsBlock = WriteCodeStatements);

            if (Code.IsLambdaExpression)
                WriteCodeStatementsAsBlock = WriteCodeStatements;

            WriteCodeStatementsAsBlock();
        }
示例#55
0
        public override SolutionBuilder.SolutionBuildResult ProcessBuildResult(Configuration configuration, SolutionBuilder.SolutionBuildResult buildResult)
        {
            Common.ProcessContentProjects(configuration, buildResult, ContentProjectsProcessed);

            return base.ProcessBuildResult(configuration, buildResult);
        }
示例#56
0
文件: Base.cs 项目: robterrell/JSIL
 public virtual SolutionBuilder.SolutionBuildResult ProcessBuildResult(Configuration defaultConfiguration, SolutionBuilder.SolutionBuildResult buildResult)
 {
     return buildResult;
 }
        public override void WriteType(SolutionFile File, SolutionProjectLanguageType Type, SolutionBuilder Context)
        {
            File.Write(this, Context, Type.Comments);




            // should the namespaces be clickable?


            File.WriteUsingNamespaceList(this, Type);

            File.WriteLine();

            File.Region(
                delegate
                {


                    WriteNamespace(File, Type.Namespace,
                        delegate
                        {


                            this.WriteSummary(
                                    File,

                                    Type.Summary
                                );


                            File.Region(
                                delegate
                                {
                                    File.WriteIndent();

                                    if (Type.IsPartial)
                                        File.WriteSpace(Keywords.Partial);

                                    File.WriteSpace(Keywords.Public);

                                    if (Type.IsSealed)
                                    {
                                        File.WriteSpace(Keywords.NotInheritable);
                                    }

                                    if (!Type.IsStatic)
                                    {
                                        File.WriteSpace(Keywords.Class);
                                    }
                                    else
                                    {
                                        File.WriteSpace(Keywords.Module);
                                    }

                                    File.Write(Type);
                                    File.WriteLine();

                                    File.Indent(this,
                                        delegate
                                        {
                                            Type.BaseType.With(
                                                BaseType =>
                                                {
                                                    File.WriteIndent().WriteSpace(Keywords.Inherits);
                                                    WriteTypeName(File, BaseType);
                                                    File.WriteLine();
                                                }
                                            );

                                            #region Fields
                                            Type.Fields.WithEach(
                                                Field =>
                                                {
                                                    this.WriteSummary(File, Field.Summary);

                                                    File.WriteIndent();

                                                    if (Field.IsPrivate)
                                                    {
                                                        File.WriteSpace(Keywords.Private);
                                                    }
                                                    else
                                                    {
                                                        File.WriteSpace(Keywords.Public);
                                                    }

                                                    if (Field.IsReadOnly)
                                                    {
                                                        File.WriteSpace(Keywords.ReadOnly);
                                                    }

                                                    File.WriteSpace(Field.Name);
                                                    File.WriteSpace(Keywords.As);

                                                    if (Field.FieldConstructor == null)
                                                    {
                                                        WriteTypeName(File, Field.FieldType);
                                                    }
                                                    else
                                                    {
                                                        WritePseudoCallExpression(File, Field.FieldConstructor, Context);
                                                    }

                                                    File.WriteLine();

                                                    File.WriteLine();
                                                }
                                            );


                                            #endregion

                                            #region Methods
                                            foreach (var item in Type.Methods.ToArray())
                                            {
                                                if (item.DeclaringType == null)
                                                    item.DeclaringType = Type;

                                                this.WriteMethod(
                                                    File,
                                                    item,
                                                    Context
                                                );


                                                File.WriteLine();
                                            }
                                            #endregion



                                            File.WriteLine();
                                        }
                                    );

                                    File.WriteIndent();
                                    File.Write(Keywords.End);
                                    File.WriteSpace();
                                    if (!Type.IsStatic)
                                    {
                                        File.Write(Keywords.Class);
                                    }
                                    else
                                    {
                                        File.Write(Keywords.Module);
                                    }
                                }
                            );
                            File.WriteLine();

                        }
                    );


                }
            );
            File.WriteLine();

        }
        public StockUltraApplicationBuilder(
                Action<SolutionFile> AddFile,
                SolutionBuilder Context,
                XElement ItemGroupForCompile,
                Action<SolutionProjectLanguageType> NotifyStartupType)
        {
            Context.Interactive.Initialize();

            Func<string, string> ToProjectFile =
                f => Context.Name + "/" + Context.Name + "/" + f;

            #region AddProjectFile
            Func<string, string, SolutionFile> AddProjectFile =
                (f, t) =>
                {
                    var r = new SolutionFile
                    {
                        Name = ToProjectFile(f),
                        Content = t,
                        Context = Context
                    };

                    AddFile(
                        r
                    );

                    return r;
                };
            #endregion

            #region AssemblyInfo

            AssemblyInfoFolder = "Properties";

            if (Context.Language == KnownLanguages.VisualBasic)
                AssemblyInfoFolder = "My Project";

            var AssemblyInfo =
                new SolutionFile
                {
                    Name = ToProjectFile(AssemblyInfoFolder + "/AssemblyInfo" + Context.Language.CodeFileExtension),
                };


            {
                AssemblyInfo.Write(Context.Language, Context, new[] { Context.Interactive.FileHeader });

                AssemblyInfo.WriteLine();

                Context.Language.WriteAssemblyAttributeNamespace(AssemblyInfo, Context.Name,
                    delegate
                    {
                        Context.Language.WriteUsingNamespace(AssemblyInfo, "System.Reflection");

                        AssemblyInfo.WriteLine();

                        // language write assembly attribute

                        Action<string, string> WriteGeneralInformation =
                            (TypeName, Constant) =>
                            {
                                Context.Language.WriteAssemblyAttribute(
                                    AssemblyInfo,
                                    new StockAttributeGeneralInformation(
                                        new SolutionProjectLanguageType { Name = TypeName, Namespace = "System.Reflection" },
                                        Constant
                                    ),
                                    Context
                                );
                            };

                        Context.Language.WriteIndentedComment(AssemblyInfo,
@"General Information about an assembly is controlled through the following 
set of attributes. Change these attribute values to modify the information
associated with an assembly."
                        );

                        //[assembly: AssemblyTitle("Ultra Application")]
                        //[assembly: AssemblyDescription("Ultra Application. Write javascript, flash and java applets within a C# project. http://jsc-solutions.net")]
                        //[assembly: AssemblyConfiguration("")]
                        //[assembly: AssemblyCompany("jsc-solutions.net")]
                        //[assembly: AssemblyProduct("UltraApplication")]
                        //[assembly: AssemblyCopyright("Copyright © jsc-solutions.net 2010")]

                        WriteGeneralInformation("AssemblyTitle", Context.Name);
                        WriteGeneralInformation("AssemblyDescription", Context.Description);
                        WriteGeneralInformation("AssemblyCompany", Context.Company);


                        WriteGeneralInformation("AssemblyProduct", Context.Name.Replace(" ", ""));
                        WriteGeneralInformation("AssemblyCopyright", "Copyright © " + Context.Company + " " + DateTime.Now.Year);
                        WriteGeneralInformation("AssemblyVersion", "1.0.0.0");
                        WriteGeneralInformation("AssemblyFileVersion", "1.0.0.0");

                        Context.Language.WriteAssemblyAttribute(
                            AssemblyInfo,
                            new StockAttributeObfuscation(),
                            Context
                        );
                    }
                );

            }

            ItemGroupForCompile.Add(
                new XElement("Compile",
                    new XAttribute("Include",
                        AssemblyInfoFolder + @"\AssemblyInfo" + Context.Language.CodeFileExtension
                    )
                )
            );


            AddFile(AssemblyInfo);
            #endregion




            #region Design/App.css
            var DesignStyle =
               new SolutionFile
               {
                   Name = ToProjectFile("Design/App.css"),
                   Content = "h1 { color: blue; }"
               };

            ItemGroupForCompile.Add(
                new XElement("Content",
                    new XAttribute("Include",
                        @"Design\App.css"
                    )
                )
            );

            AddFile(DesignStyle);

            #endregion

            #region Design/App.htm
            var DefaultPageElement =
                new XElement("html",
                    new XElement("head",
                // visual studio does
                        new XElement("title", "App")
                    ),
                    Context.ApplicationPage
                );

            var DefaultPage =
                new SolutionFile
                {
                    Name = ToProjectFile("Design/App.htm"),
                };

            DefaultPage.WriteHTMLElement(DefaultPageElement);


            ItemGroupForCompile.Add(
                new XElement("Content",
                    new XAttribute("Include",
                        @"Design\App.htm"
                    )
                )
            );

            AddFile(DefaultPage);

            #endregion


            #region RaiseGenerateHTMLFiles
            Context.Interactive.RaiseGenerateHTMLFiles(
                item =>
                {
                    var f =
                        new SolutionFile
                        {
                            Name = ToProjectFile(item.Name),
                            DependentUpon = DefaultPage
                        };

                    f.WriteHTMLElement(item.Content);

                    ItemGroupForCompile.Add(
                        new XElement("Content",
                            new XAttribute("Include",
                                item.Name.Replace("/", "\\")
                            ),
                            new XElement("DependentUpon", DefaultPage.Name.SkipUntilLastIfAny("/"))

                        )
                    );

                    AddFile(f);

                }
            );
            #endregion

            var AddTypeFiles = new Dictionary<SolutionProjectLanguageType, SolutionFile>();

            #region AddTypeWithoutMerge
            Action<SolutionProjectLanguageType, string> AddTypeWithoutMerge =
                (SourceType, IncludeName) =>
                {
                    var Folder = SourceType.Namespace.SkipUntilIfAny(Context.Name + ".");
                    var Include = "";

                    if (Folder != "")
                        if (Folder != Context.Name)
                            Include += Folder.Replace(".", "/") + "/";

                    Include += IncludeName + Context.Language.CodeFileExtension;

                    var SourceFile =
                        new SolutionFile
                        {
                            Name = ToProjectFile(Include),
                            ContextType = SourceType
                        };

                    AddTypeFiles[SourceType] = SourceFile;

                    Context.Language.WriteType(SourceFile, SourceType, Context);

                    var Compile =
                        new XElement("Compile",
                            new XAttribute("Include",
                                Include.Replace("/", "\\")
                            )
                        );

                    if (SourceType.BaseType != null)
                    {
                        if (SourceType.BaseType is KnownStockTypes.System.Windows.Forms.UserControl)
                            Compile.Add(
                                new XElement("SubType", SourceType.BaseType.Name)
                            );

                        if (SourceType.BaseType is KnownStockTypes.System.ComponentModel.Component)
                            Compile.Add(
                                new XElement("SubType", SourceType.BaseType.Name)
                            );
                    }


                    if (SourceType.DependentUpon != null)
                    {
                        SourceFile.DependentUpon = AddTypeFiles[SourceType.DependentUpon];

                        if (Context.Language.SupportsDependentUpon())
                        {
                            // F# does not?

                            Compile.Add(
                                new XElement("DependentUpon", SourceFile.DependentUpon.Name.SkipUntilLastIfAny("/"))
                            );
                        }
                    }

                    ItemGroupForCompile.Add(Compile);
                    AddFile(SourceFile);
                };
            #endregion

            #region AddType
            Action<SolutionProjectLanguageType> AddType =
                SourceType =>
                {
                    // if partial is not supported then
                    // we need to merge the types
                    // later we may need to have an identity object? :)

                    if (!Context.Language.SupportsPartialTypes())
                    {
                        SourceType.DependentPartialTypes.WithEach(
                              PartialType =>
                              {
                                  SourceType.Fields.AddRange(PartialType.Type.Fields);
                                  SourceType.Methods.AddRange(PartialType.Type.Methods);
                              }
                        );

                        SourceType.DependentPartialTypes = null;
                    }

                    AddTypeWithoutMerge(
                        SourceType,
                        SourceType.Name
                    );

                    SourceType.DependentPartialTypes.WithEach(
                        PartialType =>
                        {
                            PartialType.Type.DependentUpon = SourceType;

                            AddTypeWithoutMerge(
                                PartialType.Type,
                                PartialType.Name
                            );
                        }
                    );
                };
            #endregion



            Context.Interactive.RaiseGenerateTypes(AddType);


            // http://thevalerios.net/matt/2009/01/assembly-information-for-f-console-applications/

            #region ApplicationWebService

            var ApplicationWebServiceType = Context.Interactive.ApplicationWebServiceType;

            ApplicationWebServiceType.Namespace = Context.Name;

            AddType(ApplicationWebServiceType);

            #endregion




            #region Application

            var ApplicationType = Context.Interactive.ApplicationType;

            ApplicationType.Namespace = Context.Name;

            ApplicationType.UsingNamespaces.Add("System");
            ApplicationType.UsingNamespaces.Add("System.Text");
            ApplicationType.UsingNamespaces.Add("System.Linq");
            ApplicationType.UsingNamespaces.Add("System.Xml.Linq");
            ApplicationType.UsingNamespaces.Add("System.Collections.Generic");
            ApplicationType.UsingNamespaces.Add("System.Threading.Tasks");

            ApplicationType.UsingNamespaces.Add("ScriptCoreLib");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript.DOM");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript.DOM.HTML");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript.Components");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript.Extensions");
            
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.JavaScript.Windows.Forms");

            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.Extensions");
            ApplicationType.UsingNamespaces.Add("ScriptCoreLib.Delegates");

            ApplicationType.UsingNamespaces.Add(Context.Name + ".HTML.Pages");
            ApplicationType.UsingNamespaces.Add(Context.Name + ".Design");

            // css

            //var DefaultStyle = new SolutionProjectLanguageType
            //{
            //    Name = "DefaultStyle"
            //};

            //var DefaultStyleField = DefaultStyle.ToInitializedField("style");

            //ApplicationType.Fields.Add(DefaultStyleField);



            var ApplicationConstructor = new StockMethodApplication(
                ApplicationType, Context.Interactive/*, DefaultStyleField*/);

            ApplicationType.Methods.Add(ApplicationConstructor);


            AddType(ApplicationType);

            #endregion


            #region Program

            var ProgramType = Context.Interactive.ProgramType;

            ProgramType.Namespace = Context.Name;


            ProgramType.UsingNamespaces.Add("System");
            ProgramType.UsingNamespaces.Add("jsc.meta.Commands.Rewrite.RewriteToUltraApplication");
            AddType(ProgramType);

            NotifyStartupType(ProgramType);

            #endregion



            #region packages

            new XElement("packages", new XComment("http://my.jsc-solutions.net")).With(
                //new XElement("packages").With(
              packages =>
              {
                  Context.NuGetReferences.WithEach(
                      n =>
                          packages.Add(
                              new XElement("package",

                                  // why wont it work implicitly?
                                  content: new object[] {
                                        new XAttribute("id", n.id),
                                        new XAttribute("version", n.version),
                                        new XAttribute("targetFramework", "net40")
                                    }

                              )
                          )
                  );

                  ItemGroupForCompile.Add(
                      new XElement("None",
                          new XAttribute("Include",
                              "packages.config"
                          )
                      )
                  );


                  var packages_config = new SolutionFile
                  {
                      Name = ToProjectFile("packages.config"),

                  };

                  packages_config.WriteXElement(packages);

                  AddFile(packages_config);
              }
          );
            #endregion
        }
        public override void WriteMethodBody(SolutionFile File, SolutionProjectLanguageCode Code, SolutionBuilder Context)
        {
            // should this be an extension method to all languages?

            Action WriteCodeStatements =
             delegate
             {

                 var History = Code.History.ToArray();

                 for (int i = 0; i < History.Length; i++)
                 {
                     var IsReturnStatement = false;

                     Code.OwnerMethod.With(
                          m =>
                          {
                              if (m.ReturnType == null)
                                  return;

                              if (m.IsConstructor)
                                  return;

                              IsReturnStatement = i == History.Length - 1;
                          }
                     );


                     var item = History[i];


                     #region Comment
                     {
                         var Comment = item as string;
                         if (Comment != null)
                         {
                             File.WriteIndent();
                             this.WriteCommentLine(File, Comment);
                         }
                     }

                     {
                         var Comment = item as SolutionFileComment;
                         if (Comment != null)
                         {
                             Comment.WriteTo(File, this, Context);
                             return;
                         }
                     }
                     #endregion


                     #region If
                     var If = item as PseudoIfExpression;

                     if (If != null)
                     {
                         Func<SolutionFile> WriteDirectiveOrIndent = File.WriteIndent;


                         if (If.IsConditionalCompilationDirective)
                         {
                             WriteDirectiveOrIndent = File.WriteDirective;
                         }

                         WriteDirectiveOrIndent().WriteSpace(Keywords.If);
                         WritePseudoExpression(File, If.Expression, Context);
                         File.WriteSpace();
                         File.WriteLine(Keywords.Then);

                         WriteMethodBody(File, If.TrueCase, Context);

                         if (If.FalseCase != null)
                         {
                             WriteDirectiveOrIndent().WriteLine(Keywords.Else);

                             WriteMethodBody(File, If.FalseCase, Context);
                         }

                         WriteDirectiveOrIndent().WriteSpace(Keywords.End).WriteLine(Keywords.@If);

                         return;
                     }
                     #endregion


                     #region Lambda
                     var Lambda = item as PseudoCallExpression;

                     if (Lambda != null)
                     {
                         if (Code.IsLambdaExpression)
                         {
                             WritePseudoCallExpression(File, Lambda, Context);
                         }
                         else
                         {

                             if (Lambda.Comment != null)
                                 Lambda.Comment.WriteTo(File, this, Context);

                             if (Lambda.Method != null)
                             {
                                 File.WriteIndent();

                                 if (IsReturnStatement)
                                 {
                                     File.WriteSpace(Keywords.@Return);
                                 }


                                 WritePseudoCallExpression(File, Lambda, Context);
                                 File.WriteLine();
                             }
                         }
                     }
                     #endregion

                 }

             };

            if (Code.IsConditionalCompilationDirectiveCode)
                WriteCodeStatements();
            else
                File.Indent(this, WriteCodeStatements);


        }
        public override void WriteMethod(SolutionFile File, SolutionProjectLanguageMethod Method, SolutionBuilder Context)
        {
            var m = Method;

            if (!m.IsLambda)
                this.WriteSummary(File, m.Summary, m.Parameters.ToArray());


            File.Region(
                delegate
                {
                    if (m.IsLambda)
                    {
                        if (Method.IsFunction)
                            File.WriteSpace(Keywords.Function);
                        else
                            File.WriteSpace(Keywords.Sub);
                    }
                    else
                    {
                        File.WriteIndent();

                        if (m.IsProtected)
                            File.WriteSpace(Keywords.Protected);
                        else
                            File.WriteSpace(Keywords.Public);

                        if (m.IsStatic)
                        {
                            var IsModule = false;

                            if (m.DeclaringType != null)
                            {
                                if (m.DeclaringType.IsStatic)
                                {
                                    IsModule = true;
                                }
                            }

                            if (IsModule)
                            {
                            }
                            else
                            {
                                File.WriteSpace(Keywords.Shared);
                            }
                        }

                        if (m.IsOverride)
                            File.WriteSpace(Keywords.Overrides);

                        if (Method.IsFunction)
                            File.WriteSpace(Keywords.Function);
                        else
                            File.WriteSpace(Keywords.Sub);

                        if (m.IsConstructor)
                        {
                            File.Write(Keywords.New);
                        }
                        else
                        {
                            File.Write(m.Name);
                        }
                    }

                    File.Write("(");

                    #region Parameters
                    var Parameters = m.Parameters.ToArray();

                    for (int i = 0; i < Parameters.Length; i++)
                    {
                        if (i > 0)
                        {
                            File.WriteSpace(",");
                        }


                        File.Write(Parameters[i].Name);

                        if (Method.Code.IsLambdaExpression)
                        {
                            // omit type ? :)
                        }
                        else
                        {
                            Parameters[i].Type.With(
                                ParameterType =>
                                {
                                    File.WriteSpaces(Keywords.As);

                                    this.WriteTypeName(File, ParameterType);
                                }
                           );
                        }
                    }
                    #endregion

                    File.Write(")");

                    if (Method.Code.IsLambdaExpression)
                    {
                        File.WriteSpace();
                        this.WriteMethodBody(File, m.Code, Context);
                    }
                    else
                    {
                        File.WriteLine();

                        this.WriteMethodBody(File, m.Code, Context);

                        File.WriteIndent();

                        File.WriteSpace(Keywords.End);
                        if (Method.IsFunction)
                            File.WriteSpace(Keywords.Function);
                        else
                            File.WriteSpace(Keywords.Sub);
                    }
                    File.WriteLine();

                }
            );
        }