Пример #1
0
        private static void ProcessParameter(MethodInfo info, StringBuilder parameterString)
        {
            if (parameterString == null || parameterString.Length == 0)
            {
                return;
            }
            string value = parameterString.ToString();

            if (value.StartsWith("@return"))
            {
                info.Returns = value.Substring(7).Trim();
            }
            else if (value.StartsWith("@param"))
            {
                var split           = value.IndexOf(" ");
                var paramDefinition = value.Substring(0, split);
                var p = value.Substring(split).Trim();
                split = p.IndexOf(" ");
                string orgParamName = split > 0 ? p.Substring(0, split).Trim() : p;
                string paramName    = orgParamName;
                string description  = split > 0 ? p.Substring(split).Trim() : "";
                paramName = MethodSignatureAnalyzer.SafeParameterName(paramName);
                while (info.Parameters.ContainsKey(paramName))
                {
                    paramName = paramName + "_"; //Sometimes args are duplicated. Rename for now
                }
                bool         isIn  = paramDefinition.Contains("[in]") || paramDefinition.Contains("[in,out]") || !paramDefinition.Contains("[");
                bool         isOut = paramDefinition.Contains("[out]") || paramDefinition.Contains("[in,out]");
                PropertyInfo pi    = new PropertyInfo()
                {
                    Name         = paramName,
                    OriginalName = orgParamName,
                    Description  = description,
                    IsInput      = isIn, IsOutput = isOut
                };
                info.Parameters.Add(paramName, pi);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string repo          = @"..\..\..\..\..\alljoyn\";
            string exportList    = repo + @"alljoyn_c\src\Windows\alljoyn_c.def";
            string includeFolder = repo + @"alljoyn_c\inc\alljoyn_c\";
            string outputFolder  = @"..\..\..\..\AllJoynDotNet\Generated\";
            //List<string> exportMembers = new List<string>();
            //using (var sr = File.OpenText(exportList))
            //{
            //    if (sr.ReadLine() != "EXPORTS" || sr.ReadLine() != "")
            //        throw new InvalidDataException();
            //    while (!sr.EndOfStream)
            //    {
            //        var line = sr.ReadLine();
            //        if (!string.IsNullOrWhiteSpace(line))
            //            exportMembers.Add(line);
            //    }
            //}
            List <string> generatedFiles = new List <string>();

            foreach (var file in new DirectoryInfo(includeFolder).GetFiles("*.h"))
            {
                //First pass we find all known type definitions before generating code
                var result = DoxygenAnalyzer.Analyze(file.FullName);
                foreach (var item in result.TypeDefinitions)
                {
                    if (item.Doc is DoxygenAnalyzer.MethodInfo)
                    {
                        var csharp = MethodSignatureAnalyzer.CreateTypeDefinition(item.ExportDefinition);
                    }
                }
                foreach (var item in result.Methods)
                {
                    var methodInfo = (item.Doc as DoxygenAnalyzer.MethodInfo);
                    var csharp     = MethodSignatureAnalyzer.CreateImport(item.ExportDefinition, methodInfo);
                }
            }
            foreach (var file in new DirectoryInfo(includeFolder).GetFiles("*.h"))
            {
                string generatedFile = file.Name.Replace(".h", ".cs");
                generatedFiles.Add(generatedFile);
                if (File.Exists(outputFolder + generatedFile))
                {
                    File.Delete(outputFolder + generatedFile);
                }
                using (var sw = File.CreateText(outputFolder + generatedFile))
                {
                    //using (StreamWriter sw = new StreamWriter(outfile))
                    {
                        var result = DoxygenAnalyzer.Analyze(file.FullName);
                        sw.WriteLine("// Generated from " + file.Name);
                        sw.Write(HeaderTemplate);
                        foreach (var item in result.TypeDefinitions)
                        {
                            if (item.Doc is DoxygenAnalyzer.MethodInfo)
                            {
                                var csharp = MethodSignatureAnalyzer.CreateTypeDefinition(item.ExportDefinition);
                                if (csharp != null)
                                {
                                    var methodInfo = (item.Doc as DoxygenAnalyzer.MethodInfo);
                                    var doc        = methodInfo.XmlDoc;
                                    if (doc != null)
                                    {
                                        WriteLines(doc, "\t\t/// ", sw);
                                    }
                                    WriteLines(csharp, "\t\t", sw);
                                    WriteLines(item.ExportDefinition, "\t\t// ", sw);
                                    sw.WriteLine();
                                }
                            }
                        }
                        sw.Write(ClassHeaderTemplate.Replace("{PartialClassDescription}", "//" + result.FileDescription).Replace("{ClassName}", file.Name.Replace(".h", "")));

                        foreach (var item in result.Methods)
                        {
                            var methodInfo = (item.Doc as DoxygenAnalyzer.MethodInfo);
                            if (methodInfo != null)
                            {
                                var doc = methodInfo.XmlDoc;
                                if (doc != null)
                                {
                                    WriteLines(doc, "\t\t/// ", sw);
                                }
                            }
                            //foreach(var line in item.Doc.Spl)
                            var csharp = MethodSignatureAnalyzer.CreateImport(item.ExportDefinition, methodInfo);
                            WriteLines(csharp, "\t\t", sw);
                            WriteLines(item.ExportDefinition, "\t\t// ", sw);
                            sw.WriteLine("");
                        }

                        sw.Write(FooterTemplate);
                    }
                }
            }
            //using(var sw = File.CreateText(outputFolder + "TypeDefinitions.cs"))
            //{
            //    sw.WriteLine(TypeDefinitionHeader);
            //    foreach(var item in MethodSignatureAnalyzer.AllJoynTypes.OrderBy(t=>t.Key))
            //    {
            //        sw.WriteLine($"\t\tpublic partial class {item.Key} {{ }}");
            //    }
            //    sw.Write("\t}\n}");
            //}
            //generatedFiles.Add("TypeDefinitions.cs");

            File.WriteAllText(outputFolder + "AllJoynWrapper.cs", AllJoynWrapperTemplate);
            generatedFiles.Add("AllJoynWrapper.cs");
            var projectGuid = "6feeac78-a2ec-4eb4-bd87-2863dbfec3de";

            SharedProjectGenerator.Generate(outputFolder, "AllJoynDotNet.GeneratedInterop", projectGuid, generatedFiles);
        }