Hello everyone,
I'm working on a little project and I hope to get some input from y'all
The end result is supposed to be a (hopefully very flexible) C# Parser.
Basically I want to pass a .cs file via args to - so far a console application - Lateron I want to add a submenu Item so you just rightclick on the class and have a sub for generating the Files you want/need.
The output/files to create is a basic Mapper and Mapper with additional Info (dictionaries) .js file and some other stuff.
For now i have a console app which does exactly that. but it is really static and not very nice to handle.

I'll rework the whole thing and probably have it OOP to safe the different arguments, properties, methods, functions, settings, whatever.
What I have certain problems with is that depending on what is written in each Line, a certain object property has to be set. But I don't know what exactly to look for.

Examples:
When the Line file starts with "using System" add a new library Object with the name property set to whatever follows after the System.
If the next line starts with namespace, add a new namespace object with the name property set to whatever follows after namespace
If the next line starts with { add a new Class object with the name property set to whatever follows after Class
and so on
as another example here is a file that could be like the input

Code:
namespace xxxxxxx.Pocos
{
    using System;
    using System.Collections.Generic;

    public partial class Customer
    {
        public Customer()
        {
            this.CompanyCustomer = new HashSet<CompanyCustomer>();
            this.CustomerAccountingEntry = new HashSet<CustomerAccountingEntry>();
            this.CustomerAddress = new HashSet<CustomerAddress>();
            this.CustomerEmail = new HashSet<CustomerEmail>();
            this.CustomerParameter = new HashSet<CustomerParameter>();
            this.CustomerProgram = new HashSet<CustomerProgram>();
            this.AccountingAccount = new HashSet<AccountingAccount>();
            this.CustomerChild = new HashSet<CustomerChild>();
            this.Document = new HashSet<Document>();
            this.Survey = new HashSet<Survey>();
            this.UserAccount = new HashSet<UserAccount>();
        }

        public System.Guid Id { get; set; }
        public int Number { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string Gender { get; set; }
        public string Title { get; set; }
        public Nullable<System.DateTime> BirthDate { get; set; }
        public string MaritalStatus { get; set; }
        public bool isDeleted { get; set; }
        public string Phone { get; set; }
        public string Mobile { get; set; }
        public string Fax { get; set; }
        public System.DateTime CreateDate { get; set; }
        public System.DateTime LastChange { get; set; }
        public string oldid { get; set; }
        public string CustomerCode { get; set; }

        public virtual ICollection<CompanyCustomer> CompanyCustomer { get; set; }
        public virtual ICollection<CustomerAccountingEntry> CustomerAccountingEntry { get; set; }
        public virtual ICollection<CustomerAddress> CustomerAddress { get; set; }
        public virtual ICollection<CustomerEmail> CustomerEmail { get; set; }
        public virtual ICollection<CustomerParameter> CustomerParameter { get; set; }
        public virtual ICollection<CustomerProgram> CustomerProgram { get; set; }
        public virtual ICollection<AccountingAccount> AccountingAccount { get; set; }
        public virtual ICollection<CustomerChild> CustomerChild { get; set; }
        public virtual ICollection<Document> Document { get; set; }
        public virtual ICollection<Survey> Survey { get; set; }
        public virtual ICollection<UserAccount> UserAccount { get; set; }
    }
}
So far I literally go through every line and check for more or less exact wording.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;

namespace xxxx
{
    class Program
    {
        static void Main(string[] args)
        {

            Entity e = new Entity();

            Console.WriteLine("Input Entity:");
            e.Name = Console.ReadLine();
            try
            {
                ReadFile(Properties.Settings.Default.FilePath + e.Name + ".cs", e);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File not found! Name correct? path correct?");

                Main(args);
            }

            writeEntityFile(Properties.Settings.Default.EntityPath, e, ReadFile(Properties.Settings.Default.FilePath + e.Name + ".cs", e));

            Console.WriteLine("Input Entity '" + e.Name + "' read!");
            Console.WriteLine("Files written to " + Properties.Settings.Default.EntityPath);

            //Want to add mapper -  Basic Mapper?
            Console.WriteLine("Add Mappers and BasicMappers?\ny/n");
            if (Console.ReadLine() == "y" || Console.ReadLine() == "yes")
            {
                writeMapperFiles(e.Name);
            }

            //Want to add Frontend Model?
            Console.WriteLine("Add Frontend Model?\ny/n");
            if (Console.ReadLine() == "y" || Console.ReadLine() == "yes")
            {
                addFrontendModel(e.Name);
            }

            //Want to add Frontend Collection?
            Console.WriteLine("Add Frontend Collection?\ny/n");
            if (Console.ReadLine() == "y" || Console.ReadLine() == "yes")
            {
                addFrontendCollection(e.Name);
            }

            Console.WriteLine("Want to add more Files?");
            if (Console.ReadLine() == "y" || Console.ReadLine() == "yes")
            {
                Main(args);
            }

            else
            {
                Environment.Exit(0);
            }
        }

        private static int ReadFile(string p, Entity e)
        {
            string line = "";
            int counter = 0;
            int attributeCounter = 0;

            StreamReader input = new StreamReader(p);

            while ((line = input.ReadLine()) != null)
            {
                switch (line.Trim())
                {
                    case "public bool isDeleted { get; set; }":
                        {
                            e.IsDeleted = true;
                            attributeCounter++;
                        } break;
                    case "public System.DateTime CreateDate { get; set; }":
                        {
                            e.HasCreateDate = true;
                            attributeCounter++;
                        } break;
                    case "POCO":
                        {
                            e.HasPOCO = true;
                            attributeCounter++;
                        } break;
                    default:
                        {

                        } break;
                }
                counter++;
            }
            input.Close();
            return attributeCounter;
        }

        private static void addFrontendCollection(string entityInput)
        {
            Console.WriteLine("Collection name?");

            StreamWriter frontendColFile = new StreamWriter(Properties.Settings.Default.ModelsPath + entityInput + Console.ReadLine() + ".js");
            frontendColFile.WriteLine(@"entityType : " + entityInput + " Test Input Frontend Collection TBD");
            frontendColFile.Close();
        }

        private static void addFrontendModel(string entityInput)
        {
            string fileContent = @"entityType : " + entityInput + @",
                                defaults : {";
            string line = "";
            int counter = 0;

            StreamReader input = new StreamReader(Properties.Settings.Default.MapperPath + entityInput + "Mapper.cs");
            Console.WriteLine("Module name? ");
            StreamWriter modelFile = new StreamWriter(Properties.Settings.Default.ModelsPath + @"\" + Console.ReadLine() + entityInput + ".js");

            while ((line = input.ReadLine()) != null)
            {
                if (line.Contains(" { get; set; }"))
                {
                    string[] split = line.Split(new Char[] { ' ' });

                    foreach (string s in split)
                    {
                        if (s.Trim() != "" && s.Trim() != "public" && s.Trim() != "private" && s.Trim() != "{" && s.Trim() != "}" && s.Trim() != "get" && s.Trim() != "set")
                        {
                            modelFile.WriteLine(line);
                        }
                    }                   
                }
                counter++;
            }
            modelFile.WriteLine("}");
            modelFile.Close();
        }

        private static void writeMapperFiles(string entityInput)
        {
            StreamWriter mapperFile = new StreamWriter(Properties.Settings.Default.MapperPath + entityInput + "Mapper.cs");
            StreamWriter basicMapperFile = new StreamWriter(Properties.Settings.Default.MapperPath + entityInput + "BasicMapper.cs");

            string line = "";
            int counter = 0;
            int lines = 0;

            StreamReader input = new StreamReader(Properties.Settings.Default.FilePath + entityInput + ".cs");
            while ((line = input.ReadLine()) != null)
            {
                    lines++;
            }

            input.DiscardBufferedData();
            input.BaseStream.Seek(0, SeekOrigin.Begin);
            input.BaseStream.Position = 0;

            while ((line = input.ReadLine()) != null && counter < lines - 2)
            {
                if (!line.Contains("ICollection") && line != "}" && line != "    }")
                {
                    mapperFile.WriteLine(line);
                    basicMapperFile.WriteLine(line);
                }

                counter++;
            }
                
            //Additional Data input for the Mapper - Basic Mapper
            Console.WriteLine("Add additional data?\ny/n");
            if (Console.ReadLine() == "y" || Console.ReadLine() == "yes")
            {           

                Console.WriteLine("Add a name of additional Data.\nConfirm with return.\nFinish with 'end'.");
                string addDataInput = Console.ReadLine();

                while (addDataInput !="end")
                {
                    mapperFile.WriteLine(@"public Dictionary<string, object> " + addDataInput + @" { get; set; }
public Dictionary " + addDataInput + " = new Dictionary<string,  object>();");
                    basicMapperFile.WriteLine(@"public Dictionary<string, object> " + addDataInput + @" { get; set; }
public Dictionary " + addDataInput + " = new Dictionary<string,  object>();");
                    addConfigFile(addDataInput, entityInput, true);

                    addDataInput = Console.ReadLine();
                }
                mapperFile.WriteLine("    }\n}");
                basicMapperFile.WriteLine("    }\n}");
            }
            else
            {
                addConfigFile("", entityInput, false);
            }

            input.Close();

            mapperFile.Close();
            basicMapperFile.Close();
        }


        private static void addConfigFile(string data, string entityInput, bool additionalData)
        {
            string fileContent = "";

            if (additionalData == true)
            {
                fileContent = @"public class AppStartConfigure" + entityInput + @"AutoMapperMappings : IInitializeOnAppStart
                      {
                          public void bindEvents()
                          {
                              EventBus.On(“AppStart”, configureAutoMapperMappings);
                          }

                          public void configureAutoMapperMappings(object data, EventArgs e)
                          {
                              Mapper.CreateMap<" + entityInput + @", " + entityInput + @"Mapper>()
                                  .ForMember(x => x." + data + @", o => o.ResolveUsing<" + data+ @"ValueResolver>())
                                  .ReverseMap();

                              Mapper.CreateMap<" + entityInput + @", " + entityInput + @"BasicMapper>()
                                  .ForMember(x => x." + data + @", o => o.ResolveUsing<" + data + @"ValueResolver>())
                                  .ReverseMap();
                          } 
                        }";
            }

            else
            {
                fileContent = @"public class AppStartConfigure" + entityInput + @"AutoMapperMappings : IInitializeOnAppStart
                      {
                          public void bindEvents()
                          {
                              EventBus.On(“AppStart”, configureAutoMapperMappings);
                          }

                          public void configureAutoMapperMappings(object data, EventArgs e)
                          {
                              Mapper.CreateMap<" + entityInput + @", " + entityInput + @"Mapper>()
                                  .ReverseMap();

                              Mapper.CreateMap<" + entityInput + @", " + entityInput + @"BasicMapper>()
                                  .ReverseMap();
                          }
                        }";
            }


            StreamWriter configFile = new StreamWriter(Properties.Settings.Default.configPath + entityInput + "MapperConfiguration.cs");
            configFile.WriteLine(fileContent);
            configFile.Close();
        }


        private static void writeEntityFile(string p, Entity e, int counter)
        {
            System.IO.StreamWriter output = new System.IO.StreamWriter(p + e.Name + ".cs");

            output.Write("public partial class " + e.Name + ": ");

            if (e.IsDeleted == true)
            {
                output.Write("ISoftDeletable");
                if (counter > 1)
                {
                    output.Write(", ");
                }
            }

            if (e.HasCreateDate == true)
            {
                output.Write("IHasCreateDate");
                if (counter > 2)
                {
                    output.Write(", ");
                }
            }

            if (e.HasPOCO == true)
            {
                output.Write("IHasPoco");
                if (counter > 3)
                {
                    output.Write(", ");
                }
            }

            output.Write(" {}");
            output.Close();
        }
    }
}
What I could need some help with is the basic structure I could need for a parser. So i can write all the information given in the input.cs file into some object.property and then put together the file I need from those properties

--> .js file
add header for basic generated .js file
first line = take this property of that object and put it there
next line = take this property of that object and put it there

--> "whatever input.cs file" Mapper.cs file
add Header vor regular .cs Mapper file
first line = if the input file contained the line "xxxxxx IsDeleted" in the Mapper add Interface ISoftDeletable
next line = take another property of a different object and put it there



aaaaaaand so on

I hope you guys get what I'm trying to do and what I'm needing help with, if not, feel free to ask and I'll try to explain in more (or probably less) detail.

Cheers
Lisa