Example #1
0
        private void EmitTaskValue(XElement tasks, StringBuilder sb)
        {
            sb.AppendFormat("    public enum EventTask : uint");
            sb.AppendLine("    {");
            var mapCollection = new Dictionary <string, string>();

            foreach (var taskValue in tasks.Elements())
            {
                var taskEnumIdentifier = NameUtils.CreateIdentifier(taskValue.Attribute(AttributeNames.Name).Value);
                var taskEnumValue      = taskValue.Attribute(AttributeNames.Value).Value;

                sb.AppendFormat("        {0} = {1},", taskEnumIdentifier, taskEnumValue);
                sb.AppendLine();
            }

            sb.AppendLine("    }");
            sb.AppendLine();
        }
Example #2
0
        private void EmitMapValue(XElement maps, StringBuilder sb)
        {
            foreach (XElement map in maps.Elements())
            {
                string className = map.Attribute(AttributeNames.Name).Value;

                bool isInt = map.Elements()
                             .Select(e => e.Attribute(AttributeNames.Value).Value)
                             .All(s =>
                {
                    int val;
                    return(Int32.TryParse(s, out val));
                });

                string mapType = isInt ? "int" : "uint";

                sb.AppendFormat("    public enum {0} : {1}", NameUtils.CreateIdentifier(className), mapType);
                sb.AppendLine("    {");
                var mapCollection = new Dictionary <string, string>();
                foreach (var mapValue in map.Elements())
                {
                    var mapEnumIdentifier = NameUtils.CreateIdentifier(LookupResourceString(mapValue.Attribute(AttributeNames.Message).Value));
                    var mapEnumValue      = mapValue.Attribute(AttributeNames.Value).Value;
                    if (mapCollection.ContainsKey(mapEnumIdentifier))
                    {
                        mapCollection[mapEnumIdentifier] += " | " + mapEnumValue;
                    }
                    else
                    {
                        mapCollection[mapEnumIdentifier] = mapEnumValue;
                    }
                }

                foreach (var mapValue in mapCollection)
                {
                    sb.AppendFormat("        {0} = {1},", mapValue.Key, mapValue.Value);
                    sb.AppendLine();
                }

                sb.AppendLine("    }");
                sb.AppendLine();
            }
        }