Exemple #1
0
        public static CodeGeneratorRequest Create(global::System.Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException();
            }

            Message msg = null;

            try
            {
                CodeGeneratorRequest req = msg.Allocate <CodeGeneratorRequest>();
                msg.Root = msg;

                Dictionary <System.Type, Node> map     = new Dictionary <System.Type, Node>();
                Queue <System.Type>            pending = new Queue <System.Type>();
                pending.Enqueue(type);

                var nodes = new List <Node>(); // in discovery order

                // first just get everything without configuring all the nodes; this avoids a number of cyclic issues
                while (pending.Count != 0)
                {
                    System.Type next = pending.Dequeue();
                    if (next != null && !map.ContainsKey(next))
                    {
                        ulong       id       = 0;
                        string      name     = next.Name;
                        IdAttribute idAttrib = (IdAttribute)Attribute.GetCustomAttribute(next, typeof(IdAttribute));
                        if (idAttrib != null)
                        {
                            id = idAttrib.Id;
                            if (!string.IsNullOrWhiteSpace(idAttrib.Name))
                            {
                                name = idAttrib.Name;
                            }
                        }
                        var node = new Node {
                            id = id, displayName = Text.Create(msg, name)
                        };
                        map.Add(next, node);
                        nodes.Add(node);
                        Cascade(next, pending);
                    }
                }

                foreach (var pair in map)
                {
                    ConfigureNode(pair.Key, pair.Value, map);
                }

                req.nodes          = msg.AllocateList <Node>(nodes);
                req.requestedFiles = msg.AllocateList <RequestedFile>(0);
                return(req);
            }
            finally
            {
                if (msg != null)
                {
                    msg.Dispose();
                }
            }
        }
Exemple #2
0
 private static void ShowSchemaInfo(CodeGeneratorRequest req)
 {
     if (req.requestedFiles.IsValid())
     {
         if (req.requestedFiles.Count() != 0)
         {
             Console.WriteLine("Requested files:");
             foreach (var file in req.requestedFiles)
             {
                 Console.WriteLine("{0}: {1}", file.id, file.filename);
                 if (file.imports.IsValid())
                 {
                     foreach (var imp in file.imports)
                     {
                         Console.WriteLine("\t{0}: {1}", imp.id, imp.name);
                     }
                 }
             }
             Console.WriteLine();
         }
     }
     if (req.nodes.IsValid())
     {
         if (req.nodes.Count() != 0)
         {
             Console.WriteLine("Nodes:");
             foreach (var node in req.nodes)
             {
                 string name = node.displayName.ToString();
                 Console.WriteLine("  {2}: {0} ({1})", name, name.Substring((int)node.displayNamePrefixLength), node.Union);
             }
             Console.WriteLine();
         }
     }
 }