Beispiel #1
0
 public byte[] Generate(CoddeeSolutionInfo solution, ProjectConfiguration project, TableImportArgumentsViewModel args)
 {
     using (var ms = new MemoryStream())
     {
         Generate(solution, project, args, ms);
         return(ms.ToArray());
     }
 }
Beispiel #2
0
        public void Generate(CoddeeSolutionInfo solution, ProjectConfiguration project, TableImportArgumentsViewModel args, Stream stream)
        {
            _project  = project;
            _solution = solution;
            var compileUnit     = new CodeCompileUnit();
            var nameSpace       = new CodeNamespace(project.DefaultNamespace);
            var usingsNamespace = new CodeNamespace();

            usingsNamespace.Imports.Add(new CodeNamespaceImport("System"));
            usingsNamespace.Imports.Add(new CodeNamespaceImport("Coddee"));
            AddNamepaceImports(usingsNamespace);
            var type = CreateType(args);

            AddBaseTypes(type, args);
            AddMembers(type, args);

            nameSpace.Types.Add(type);
            compileUnit.Namespaces.Add(usingsNamespace);
            compileUnit.Namespaces.Add(nameSpace);

            CodeDomProvider      provider = CodeDomProvider.CreateProvider("CSharp");
            CodeGeneratorOptions options  = new CodeGeneratorOptions
            {
                BlankLinesBetweenMembers = false,
                BracingStyle             = "C"
            };

            using (var ms = new MemoryStream())
            {
                using (var tempsw = new StreamWriter(ms))
                {
                    provider.GenerateCodeFromCompileUnit(compileUnit, tempsw, options);
                }
                var text = Encoding.UTF8.GetString(ms.ToArray());
                text = text.Replace("This code was generated by a tool.", "This code was generated by Coddee tool.");
                var bytes = Encoding.UTF8.GetBytes(text);
                stream.Write(bytes, 0, bytes.Length);
                stream.Flush();
            }
        }
Beispiel #3
0
 public static void CreateSolutionInfo(VsHelper vsHelper)
 {
     _solution = new CoddeeSolutionInfo(vsHelper);
 }