Beispiel #1
0
 public static void WriteFileHeader(string filename, TabStringBuilder builder)
 {
     builder.AppendLine("/*This document was generated with a tool.{0}dbus2cs version {1}*/", Environment.NewLine, System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
     builder.AppendLine(License);
 }
Beispiel #2
0
 public static void WriteInterface(XmlNode node, TabStringBuilder builder)
 {
     foreach(XmlNode doc in node.ChildNodes)
         if (doc.Name == "doc:doc")
         {
             builder.AppendLine(1, "/// <summary>");
             foreach (string line in doc.InnerText.Trim().Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.None))
                 builder.AppendLine(1, "/// {0}", line.Trim());
             builder.AppendLine(1, "/// </summary>");
         }
     string raw = node.Attributes["name"].Value;
     builder.AppendLine(1, "[Interface(\"{0}\")]", raw);
     string[] split = raw.Split('.');
     builder.Append(1, "public interface {0}{1}\t{{{1}", split[split.Length - 1], Environment.NewLine);
     foreach (XmlNode typeNode in node.ChildNodes)
     {
         switch (typeNode.Name)
         {
             case ("method"):
                 //if (typeNode.Attributes["name"].Value.ToLower().StartsWith("get") || typeNode.Attributes["name"].Value.ToLower().StartsWith("set"))
                 //{
                 //    WriteProperty(typeNode, builder);
                 //}
                 //else
                 WriteComment(typeNode, builder);
                     WriteMethod(typeNode, builder);
                 break;
             case ("signal"):
                 WriteComment(typeNode, builder);
                 WriteEvent(typeNode, builder);
                 break;
             case ("error"):
                 break;//make custom error types?
         }
     }
     builder.AppendLine(1, "}}{0}", Environment.NewLine);
 }
Beispiel #3
0
 public static void WriteUsings(XmlDocument doc, TabStringBuilder builder)
 {
     builder.AppendLine("using System;").AppendLine("using System.Collections.Generic;").AppendLine("using NDesk.DBus;").AppendLine();
 }
Beispiel #4
0
 public static void WriteNamespace(XmlNode node, TabStringBuilder builder)
 {
     //string[] split = node.FirstChild.Attributes["name"].Value.Split('.');
     //builder.Append("namespace ");
     //for (int i = 1; i < split.Length; i++)
     //{
     //    builder.Append(split[i]);
     //    if (i < split.Length - 1)
     //        builder.Append(".");
     //}
     builder.Append("namespace {0}", Namespace == string.Empty ? "DefaultNamespace" : Namespace);
     builder.AppendLine("{0}{{", Environment.NewLine);
     foreach (XmlNode inter in node.SelectNodes("interface"))
     {
         WriteInterface(inter, builder);
     }
     builder.Append(StructsEtc);
     builder.Append("}");
 }
Beispiel #5
0
 public static void WriteEvent(XmlNode node, TabStringBuilder builder)
 {
     builder.AppendLine(2, "event {0} {1};", CreateDelegate(node, builder), node.Attributes["name"].Value);
 }
Beispiel #6
0
 public static void WriteMethod(XmlNode node, TabStringBuilder builder)
 {
     builder.AppendLine(2, "{0} {1}({2});", GetReturnType(node), node.Attributes["name"].Value, GetParameters(node));
 }
Beispiel #7
0
 public static void WriteComment(XmlNode node, TabStringBuilder builder)
 {
     List<string> description = new List<string>(), remark = new List<string>(), returns = new List<string>();
     List<KeyValuePair<string, string[]>> args = new List<KeyValuePair<string, string[]>>();//keep order
     foreach (XmlNode docOrArg in node.ChildNodes)
         switch (docOrArg.Name.ToLower())
         {
             case ("doc:doc"):
                 foreach (XmlNode descOrRemark in docOrArg.ChildNodes)
                 {
                     if (descOrRemark.Name.ToLower() == "doc:description")
                         description.AddRange(descOrRemark.InnerText.Trim().Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.None));
                     if (descOrRemark.Name.ToLower() == "doc:inote")
                         remark.AddRange(descOrRemark.InnerText.Trim().Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.None));
                 }
                 break;
             case ("arg"):
                 if (docOrArg.Attributes["direction"] != null && docOrArg.Attributes["name"] != null)
                     if (docOrArg.Attributes["direction"].Value == "in")
                     {
                         foreach (XmlNode docNode in docOrArg.ChildNodes)
                             foreach (XmlNode summary in docNode.ChildNodes)
                             {
                                 if (docNode.Name.ToLower() == "doc:doc" && summary.Name.ToLower() == "doc:summary")
                                 {
                                     args.Add(new KeyValuePair<string, string[]>(docOrArg.Attributes["name"].Value, summary.InnerText.Trim().Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.None)));
                                 }
                             }
                     }
                     else if (docOrArg.Attributes["direction"].Value == "out")
                     {
                         foreach (XmlNode docNode in docOrArg.ChildNodes)
                             foreach (XmlNode summary in docNode.ChildNodes)
                             {
                                 if (docNode.Name.ToLower() == "doc:doc" && summary.Name.ToLower() == "doc:summary")
                                     returns.AddRange(summary.InnerText.Trim().Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.None));
                             }
                     }
                 break;
         }
     if (description.Count > 0 && description[0].Trim().Length > 0)
     {
         builder.AppendLine(2, "/// <summary>");
         foreach (string line in description)
             builder.AppendLine(2, "/// {0}", line.Trim());
         builder.AppendLine(2, "/// </summary>");
     }
     if (remark.Count > 0 && remark[0].Trim().Length > 0)
     {
         builder.AppendLine(2, "/// <remarks>");
         foreach (string line in remark)
             builder.AppendLine(2, "/// {0}", line.Trim());
         builder.AppendLine(2, "/// </remarks>");
     }
     if (args.Count > 0)
     {
         if (args.Count > 0)
             foreach (KeyValuePair<string, string[]> pair in args)
             {
                 builder.AppendLine(2, "/// <param name=\"{0}\">", pair.Key);
                 foreach (string line in pair.Value)
                     builder.AppendLine(2, "/// {0}", line);
                 builder.AppendLine(2, "/// </param>");
             }
     }
     if (returns.Count > 0 && returns[0].Trim().Length > 0)
     {
         builder.AppendLine(2, "/// <returns>");
         foreach (string ret in returns)
             builder.AppendLine(2, "/// {0}", ret.Trim());
         builder.AppendLine(2, "/// </returns>");
     }
 }