Example #1
0
 private static List <string> GetDirectories()
 {
     return(new List <string>()
     {
         ReadCodeFile.GetCodeBasePath("Lazinator") + "/Attributes",
         ReadCodeFile.GetCodeBasePath("LazinatorCollections"),
         ReadCodeFile.GetCodeBasePath("LazinatorCollections") + "/ByteSpan",
         ReadCodeFile.GetCodeBasePath("LazinatorCollections") + "/BitArray",
         ReadCodeFile.GetCodeBasePath("LazinatorCollections") + "/Dictionary",
         ReadCodeFile.GetCodeBasePath("LazinatorCollections") + "/Enumerators",
         ReadCodeFile.GetCodeBasePath("LazinatorCollections") + "/OffsetList",
         ReadCodeFile.GetCodeBasePath("Lazinator") + "/Wrappers",
         ReadCodeFile.GetCodeBasePath("Lazinator") + "/Buffers",
         ReadCodeFile.GetCodeBasePath("Lazinator") + "/Persistence",
         ReadCodeFile.GetCodeBasePath("LazinatorTests") + "/Examples",
     });
 }
Example #2
0
        private static LazinatorConfig FindConfigFileStartingFromSubfolder(string mainFolder, string subfolder, string projectPath)
        {
            ReadCodeFile.GetCodeInFile(projectPath, mainFolder, subfolder, "LazinatorConfig", ".json", out string configPath, out string configText);
            if (configText == null)
            {
                ReadCodeFile.GetCodeInFile(projectPath, mainFolder, "/", "LazinatorConfig", ".json", out configPath, out configText);
            }
            if (configText == null)
            {
                ReadCodeFile.GetCodeInFile(projectPath, "/", "", "LazinatorConfig", ".json", out configPath, out configText);
            }
            LazinatorConfig config = null;

            if (configText != null)
            {
                config = JsonConvert.DeserializeObject <LazinatorConfig>(configText);
            }
            return(config);
        }
Example #3
0
        private static async Task CompleteGenerateCode(Type existingType, string project, string mainFolder, string subfolder, AdhocWorkspace ws)
        {
            if (mainFolder == "" && subfolder == "")
            {
                mainFolder = "/";
            }
            if (existingType.IsInterface)
            {
                throw new Exception("Can complete generate code only on class implementing interface, not interface itself.");
            }
            string projectPath = ReadCodeFile.GetCodeBasePath(project);
            string name        = ReadCodeFile.GetNameOfType(existingType);

            ReadCodeFile.GetCodeInFile(projectPath, mainFolder, subfolder, name, ".g.cs", out string codeBehindPath, out string codeBehind);
            LazinatorConfig config = FindConfigFileStartingFromSubfolder(mainFolder, subfolder, projectPath);

            // uncomment to include tracing code
            //if (config == null)
            //    config = new LazinatorConfig();
            //config.IncludeTracingCode = true;

            var compilation = await AdhocWorkspaceManager.GetCompilation(ws);

            LazinatorCompilation lazinatorCompilation = new LazinatorCompilation(compilation, existingType, config);

            var  d      = new ObjectDescription(lazinatorCompilation.ImplementingTypeSymbol, lazinatorCompilation, codeBehindPath, true);
            var  result = d.GetCodeBehind();
            bool match  = codeBehind == result;

            // return; // uncomment this to prevent any changes to classes during testing if automaticallyFix is true

            bool automaticallyFix = true; // Set to true to automatically update all test classes on the local development machine to a new format. This will trivially result in the test passing. Before doing this, submit all changes. After doing this, if code compiles, run all tests. Then set this back to false.

            if (automaticallyFix && !match)
            {
                File.WriteAllText(codeBehindPath, result);
            }
            else
            {
                match.Should().BeTrue();
            }
        }