示例#1
0
        /// <summary>
        /// Crée une fonction macro clank à partir du membre donné.
        /// </summary>
        static string CreateAccess(string padding, MethodInfo info, AccessAttribute attr)
        {
            StringBuilder b = new StringBuilder();

            b.AppendLine(padding + "// " + attr.Comment);
            b.Append(padding + "public " + CreateTypeName(info.ReturnType) + " " + info.Name);
            b.Append("(");
            foreach (var arg in info.GetParameters())
            {
                b.Append(CreateTypeName(arg.ParameterType) + " " + arg.Name + ",");
            }

            if (info.GetParameters().Length != 0)
            {
                b.Remove(b.Length - 1, 1); // supprime la virgule en trop
            }
            b.AppendLine(")");
            b.AppendLine(padding + "{ ");
            b.Append(padding + "\treturn " + info.Name + "_macro(clientId,");
            foreach (var arg in info.GetParameters())
            {
                b.Append(arg.Name + ",");
            }

            b.Remove(b.Length - 1, 1); // supprime la virgule en trop
            b.AppendLine(");");
            b.AppendLine(padding + "}");
            return(b.ToString());
        }
示例#2
0
        /// <summary>
        /// Crée une fonction macro clank à partir du membre donné.
        /// </summary>
        static string CreateMacro(string padding, MethodInfo info, AccessAttribute attr)
        {
            StringBuilder b = new StringBuilder();

            b.AppendLine(padding + "// " + attr.Comment);
            b.Append(padding + CreateTypeName(info.ReturnType) + " " + info.Name + "_macro");
            b.Append("(int clientId,");
            foreach (var arg in info.GetParameters())
            {
                b.Append(CreateTypeName(arg.ParameterType) + " " + arg.Name + ",");
            }
            b.Remove(b.Length - 1, 1); // supprime la virgule en trop
            b.Append(") { string cs = \"" + attr.ObjectSource + "." + info.Name + "(");
            foreach (var arg in info.GetParameters())
            {
                b.Append("$(" + arg.Name + "),");
            }

            if (info.GetParameters().Length != 0)
            {
                b.Remove(b.Length - 1, 1); // supprime la virgule en trop
            }
            b.Append(")\"; }");

            return(b.ToString());
        }
示例#3
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());
        }