Esempio n. 1
0
        /// <summary>
        /// Crée une enum clank à partir du type énuméré C# donné.
        /// </summary>
        static string CreateEnum(string padding, Type t, EnumAttribute attr)
        {
            StringBuilder b = new StringBuilder();

            b.AppendLine(padding + "public enum " + t.Name + "\r\n" + padding + "{");
            Array values = t.GetEnumValues();
            int   i      = 0;

            string[] enumNames = t.GetEnumNames();

            foreach (string name in enumNames)
            {
                b.Append(padding + "\t");
                b.Append(name + " = ");
                if (i == enumNames.Length - 1)
                {
                    b.AppendLine(((int)t.GetField(name).GetValue(t)).ToString());
                }
                else
                {
                    b.AppendLine((int)t.GetField(name).GetValue(t) + ",");
                }

                i++;
            }

            b.AppendLine(padding + "}");

            return(b.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Crée le fichier main contenant les includes et les interfaces.
        /// </summary>
        public static string CreateMain(Assembly assembly, Dictionary <string, string> views)
        {
            StringBuilder b      = new StringBuilder();
            List <string> macros = new List <string>();
            List <string> access = new List <string>();
            List <string> enums  = new List <string>();

            // Parcours tous les types pour en extraire les macros / access.
            foreach (Type type in assembly.GetTypes())
            {
                MethodInfo[] fields = type.GetMethods();
                object[]     attributes;
                foreach (MethodInfo info in fields)
                {
                    if (info.DeclaringType != type)
                    {
                        continue;
                    }

                    attributes = info.GetCustomAttributes(typeof(AccessAttribute), false);
                    foreach (object att in attributes)
                    {
                        AccessAttribute attr = att as AccessAttribute;
                        if (attr != null)
                        {
                            macros.Add(CreateMacro("\t\t", info, attr));
                            access.Add(CreateAccess("\t\t", info, attr));
                        }
                    }
                }

                if (type.IsEnum)
                {
                    // Récupère les types énumérés.
                    attributes = type.GetCustomAttributes(typeof(EnumAttribute), false);
                    foreach (object att in attributes)
                    {
                        EnumAttribute attr = att as EnumAttribute;
                        if (attr != null)
                        {
                            enums.Add(CreateEnum("\t\t", type, attr));
                        }
                    }
                }
            }



            b.AppendLine("#include stdtypes.clank");
            b.AppendLine("#include XNAMacros.clank");
            b.AppendLine("main\r\n{");


            // Ecrit les includes
            foreach (var kvp in views)
            {
                b.AppendLine("\t#include " + kvp.Key);
            }

            b.AppendLine("\tstate\r\n\t{");
            b.AppendLine("\t\t// Rajoute les statements using et le bon namespace pour la classe state.");
            b.AppendLine("\t\tvoid getClassMetadata_cs()");
            b.AppendLine("\t\t{");
            b.AppendLine("\t\t\tstring usingStatements = \"\";");
            b.AppendLine("\t\t\tstring namespace = \"Codinsa2015.Views\";");
            b.AppendLine("\t\t}");

            b.AppendLine("\t\t// Rajoute le nom du package pour les projets java.");
            b.AppendLine("\t\tvoid getClassMetadata_java()");
            b.AppendLine("\t\t{");
            b.AppendLine("\t\t\tstring package = \"net.codinsa2015\";");
            b.AppendLine("\t\t}");
            // Enumérations.
            foreach (string str in enums)
            {
                b.AppendLine(str);
            }


            b.AppendLine("\t}");
            // Macros
            b.AppendLine("\tmacro\r\n\t{");
            foreach (string macro in macros)
            {
                b.AppendLine(macro);
            }
            b.AppendLine();
            b.AppendLine("\t} // macro");

            // Access
            b.AppendLine("\taccess\r\n\t{");
            foreach (string a in access)
            {
                b.AppendLine(a);
            }
            b.AppendLine();
            b.AppendLine("\t} // access");

            b.AppendLine();
            b.AppendLine("} // main");
            return(b.ToString());
        }