コード例 #1
0
        public void WriteWithinSerializedFfxXml(XmlWriter writer)
        {
            writer.WriteStartElement(ValueType);
            writer.WriteAttributeString("name", Name);

            if (IsAssert)
            {
                writer.WriteAttributeString("assert", AssertValue.ToString());
            }

            if (IsOptional)
            {
                writer.WriteAttributeString("optional", "true");
            }

            if (IsXmlAttribute)
            {
                writer.WriteAttributeString("attribute", "true");
            }

            if (IsNodeFlattened)
            {
                writer.WriteAttributeString("flattened", "true");
            }

            if (Tag != null)
            {
                writer.WriteAttributeString("tag", Tag);
            }



            writer.WriteEndElement();
        }
コード例 #2
0
        public object ReadStandardValueFromRaw(BinaryReaderEx br)
        {
            object valueThatWasRead = null;

            switch (ValueType)
            {
            case "b": valueThatWasRead = br.ReadBoolean(); break;

            case "u8":
            case "x8": valueThatWasRead = br.ReadByte(); break;

            case "s8": valueThatWasRead = br.ReadSByte(); break;

            case "u16":
            case "x16": valueThatWasRead = br.ReadUInt16(); break;

            case "s16": valueThatWasRead = br.ReadInt16(); break;

            case "u32":
            case "x32": valueThatWasRead = br.ReadUInt32(); break;

            case "s32": valueThatWasRead = br.ReadInt32(); break;

            case "u64":
            case "x64": valueThatWasRead = br.ReadUInt64(); break;

            case "s64": valueThatWasRead = br.ReadInt64(); break;

            case "f32": valueThatWasRead = br.ReadSingle(); break;

            case "f64": valueThatWasRead = br.ReadDouble(); break;

            default: throw new Exception($"Value type '{ValueType}' is not a standard type " +
                                         $"and must be handled manually instead of calling {nameof(XmlStructDefField)}." +
                                         $"{nameof(ReadStandardValueFromRaw)}.");
            }

            if (IsAssert && !AssertValue.Equals(valueThatWasRead))
            {
                throw new XmlStructException($"Assert failed for field '{Name}'. " +
                                             $"Read '{valueThatWasRead}', expected to read '{AssertValue}'.");
            }

            return(valueThatWasRead);
        }
コード例 #3
0
 public static void Approximately(this AssertValue assert, float val, float delta)
 {
     assert.BetweenInclusive(val - delta, val + delta);
 }
コード例 #4
0
 public static void Approximately(this AssertValue assert, float val)
 {
     assert.Approximately(val, DELTA);
 }