Example #1
0
        public CgTypeCsSrcCode(string assemblyPath, string typeFullName)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath));
            }
            AssemblyPath = assemblyPath;
            if (!File.Exists(AssemblyPath))
            {
                throw new FileNotFoundException("Cannot find the compiled assembly.", assemblyPath);
            }

            //this is how we line up a source code file to a reflected runtime type
            var invokeDia2Dump = new InvokeDia2Dump.GetPdbData(assemblyPath);
            var pdbLines       = invokeDia2Dump.SingleTypeNamed(typeFullName);

            if (pdbLines == null)
            {
                throw new ItsDeadJim("Dia2Dump.exe did not return anything for the type " +
                                     $"named '{typeFullName}' from '{invokeDia2Dump.PdbAssemblyFilePath}'");
            }

            //but we don't want the type in our appDomain, so we shell it out as a code-gen type
            _cgType = Etc.GetIsolatedCgOfType(assemblyPath, typeFullName, true);

            _cgType.AssignPdbSymbols(pdbLines.moduleSymbols);

            var sourceCodeFiles = pdbLines.moduleSymbols.Select(ms => ms.file);

            foreach (var src in sourceCodeFiles)
            {
                if (!File.Exists(src))
                {
                    continue;
                }

                //ANTLR CSharp parser seems to have problems with Preprocessor cmd\directives\macros
                var srcLines = File.ReadAllLines(src);
                srcLines = Settings.LangStyle.RemovePreprocessorCmds(srcLines);
                File.WriteAllLines(src, srcLines);

                var antlrParseRslts = CsharpParseTree.InvokeParse(src);
                _cgType.AssignAntlrParseItems(GetAntlrParseItems(antlrParseRslts));
            }
        }
Example #2
0
        public CgTypeCsSrcCode(string assemblyPath, string typeFullName)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
                throw new ArgumentNullException(nameof(assemblyPath));
            AssemblyPath = assemblyPath;
            if (!File.Exists(AssemblyPath))
            {
                throw new ItsDeadJim($"No such file '{AssemblyPath}'.");
            }

            var invokeDia2Dump = new InvokeDia2Dump.GetPdbData(assemblyPath);
            var pdbLines = invokeDia2Dump.SingleTypeNamed(typeFullName);
            if(pdbLines == null)
                throw new ItsDeadJim($"Dia2Dump.exe did not return anything for the type named '{typeFullName}'");

            _cgType = Etc.GetIsolatedCgOfType(assemblyPath, typeFullName, true);

            _cgType.AssignPdbSymbols(pdbLines.moduleSymbols);
        }
Example #3
0
        public CgTypeCsSrcCode(Assembly asm, string typeFullName, params string[] sourceCodeFiles)
        {
            if (asm == null)
            {
                throw new ArgumentNullException(nameof(asm));
            }
            AssemblyPath = asm.Location;
            if (!File.Exists(AssemblyPath))
            {
                throw new FileNotFoundException("Cannot find the compiled assembly.", AssemblyPath);
            }

            //this is how we line up a source code file to a reflected runtime type
            var invokeDia2Dump = new InvokeDia2Dump.GetPdbData(AssemblyPath);
            var pdbLines       = invokeDia2Dump.SingleTypeNamed(typeFullName);

            if (pdbLines == null)
            {
                throw new ItsDeadJim("Dia2Dump.exe did not return anything for the type " +
                                     $"named '{typeFullName}' from '{invokeDia2Dump.PdbAssemblyFilePath}'");
            }

            _cgType = Etc.GetCgOfType(asm, typeFullName, true);

            _cgType.AssignPdbSymbols(pdbLines.moduleSymbols);

            var scf = sourceCodeFiles?.ToList() ?? new List <string>();

            scf.AddRange(pdbLines.moduleSymbols.Select(ms => ms.file));

            foreach (var src in sourceCodeFiles)
            {
                var antlrParseRslts = CsharpParseTree.InvokeParse(src);
                _cgType.AssignAntlrParseItems(GetAntlrParseItems(antlrParseRslts));
            }
        }
Example #4
0
 public void Init()
 {
     TempDirectories.Code = @"C:\Projects\31g\trunk\Code\NoFuture.Tests\Gen";
     CustomTools.Dia2Dump = @"C:\Projects\31g\trunk\bin\Dia2Dump.exe";
     _testSubject = new GetPdbData(TEST_PDB_FILE);
 }