Пример #1
0
 public abstract void FormatConsts(ConstsDef def);
Пример #2
0
 private bool ParseConstant(ConstsDef def, XmlElement elem)
 {
     var name = elem.GetAttribute("name");
     if (String.IsNullOrEmpty(name))
     {
         return false;
     }
     var element = new ConstsDef.Constant();
     element.Name = name;
     element.Value = elem.InnerText.Trim();
     def.Constants.Add(element);
     return true;
 }
Пример #3
0
        private bool ParseConsts(Document doc, XmlElement elem)
        {
            var name = elem.GetAttribute("name");
            var type = elem.GetAttribute("type");
            if (String.IsNullOrEmpty(name))
            {
                return false;
            }
            if (String.IsNullOrEmpty(type))
            {
                type = "int32";  // default type
            }
            var def = new ConstsDef();
            def.Name = name;
            def.Type = type;

            var node = elem.FirstChild;
            for ( ; node != null; node = node.NextSibling)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                var child = (XmlElement)node;
                if (child.IsEmpty)
                {
                    continue;
                }
                switch (child.Name)
                {
                    case "const":
                        if (ParseConstant(def, child) == false)
                        {
                            return false;
                        }
                        break;
                    default:
                        break;
                }
            }
            doc.Definitions.Add(def);
            return true;
        }
Пример #4
0
        public override void FormatConsts(ConstsDef def)
        {
            if (nativeTypes.ContainsKey(def.Type))
            {
                def.NativeType = nativeTypes[def.Type];
            }
            else
            {
                return;
            }

            Indent(0); Out.WriteLine("public static class {0}", def.Name);
            Indent(0); Out.WriteLine("{");
            foreach (var constant in def.Constants)
            {
                Indent(1);
                Out.Write("public const {0} {1}", def.NativeType, constant.Name);
                if (!String.IsNullOrEmpty(constant.Value))
                {
                    Out.Write(" = {0};", constant.Value);
                }
                Out.WriteLine();
            }
            Indent(0); Out.WriteLine("}");
        }