Exemplo n.º 1
0
        [Test] public void EnumWithValue()
        {
            StructFile structFile = new StructParser().LoadStructs("enum a { b=5, c=8 }");
            EnumDef    enumDef    = structFile.GetEnumByName("a");

            Assert.AreEqual("b", enumDef.ValueToString(5));
            Assert.AreEqual("c", enumDef.ValueToString(8));
        }
Exemplo n.º 2
0
        [Test] public void Enum()
        {
            StructFile structFile = new StructParser().LoadStructs("enum a { b, c }");
            EnumDef    enumDef    = structFile.GetEnumByName("a");

            Assert.IsNotNull(enumDef);
            Assert.AreEqual("b", enumDef.ValueToString(0));
            Assert.AreEqual("c", enumDef.ValueToString(1));
        }
Exemplo n.º 3
0
        public override void LoadData(BinaryReader reader, StructInstance instance)
        {
            int     offset  = (int)reader.BaseStream.Position;
            uint    value   = ReadIntValue(reader, instance).ToUInt32(CultureInfo.CurrentCulture);
            EnumDef enumDef = GetEnumAttribute("enum");

            AddCell(instance, new EnumValue(value, enumDef), enumDef.ValueToString(value), offset);
        }
Exemplo n.º 4
0
        [Test] public void IncludeStructFile()
        {
            StructSourceContext context = new StructSourceContext();

            context.AddSourceText("a.strs", "include b.strs; struct A { enum8 [enum=E] q; }");
            context.AddSourceText("b.strs", "enum E { z, x, c }");
            StructParser parser = new StructParser();
            StructFile   file   = parser.LoadStructs("a.strs", context);

            Assert.IsNotNull(file);
            Assert.AreEqual(0, parser.Errors.Count);
            EnumDef e = file.GetEnumByName("E");

            Assert.AreEqual("c", e.ValueToString(2));
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            var result = new StringBuilder();

            for (int i = 0; i < _size * 8; i++)
            {
                if ((_value & (1ul << i)) != 0)
                {
                    if (result.Length > 0)
                    {
                        result.Append(", ");
                    }
                    result.Append(EnumDef.ValueToString((uint)i));
                }
            }
            return(result.ToString());
        }
Exemplo n.º 6
0
 public override string ToString()
 {
     return(_enumDef.ValueToString(_value));
 }