Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            AccessorCreatorStore store = new AccessorCreatorStore();

            store.Add("char*", new StringAccessorCreator());
            BasicClassCreator classCreator = new BasicClassCreator();

            DisplayUsage();

            List <FieldInfo> fields = new List <FieldInfo>();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');

                if (input.Length == 1)
                {
                    string termination = input[0];
                    if (termination.Length == 0 || termination[0] != '.')
                    {
                        continue;
                    }

                    if (termination.Length == 1)
                    {
                        foreach (var field in fields)
                        {
                            IAccessorCreator creator = store[field.type];
                            Console.WriteLine(creator.MakeGetter(field));
                            Console.WriteLine();
                            Console.WriteLine(creator.MakeSetter(field));
                            Console.WriteLine();
                        }
                    }
                    else
                    {
                        string         className      = termination.Substring(1);
                        GeneratedClass generatedClass = classCreator.GenerateClass(className, fields);

                        File.WriteAllText(className + ".h", generatedClass.headerFile);
                        File.WriteAllText(className + ".cpp", generatedClass.cppFile);

                        Console.WriteLine("Class saved in {0}", System.Environment.CurrentDirectory);
                    }

                    fields.Clear();
                }

                if (input.Length != 2)
                {
                    continue;
                }
                FieldInfo current = new FieldInfo();
                current.type = input[0];
                current.name = input[1];
                fields.Add(current);
            }
        }
        private GeneratedField GenerateField(FieldInfo info)
        {
            GeneratedField result = new GeneratedField();

            result.info = info;

            IAccessorCreator creator = store[info.type];

            result.getter = creator.MakeGetter(info);
            result.setter = creator.MakeSetter(info);

            result.getterDeclaration = result.getter.Split(new string[] { Environment.NewLine },
                                                           StringSplitOptions.RemoveEmptyEntries)[0];
            result.setterDeclaration = result.setter.Split(new string[] { Environment.NewLine },
                                                           StringSplitOptions.RemoveEmptyEntries)[0];

            return(result);
        }