Beispiel #1
0
 public override void Write(XnbReaderManager xnbReaderManager, XnbStreamWriter xnbStreamWriter, object value)
 {
     if (value is int number)
     {
         xnbStreamWriter.Write(number);
     }
 }
        public override void Write(XnbReaderManager xnbReaderManager, XnbStreamWriter xnbStreamWriter, object value)
        {
            if (value is Dictionary <TKeyType, TValueType> dictionary)
            {
                xnbStreamWriter.Write(dictionary.Count);
                foreach (KeyValuePair <TKeyType, TValueType> keyValuePair in dictionary)
                {
                    (int keyReaderIndex, XnbTypeReader keyReader) = xnbReaderManager.GetOrAddXnbTypeReaderFromTargetType <TKeyType>();
                    if (!typeof(TKeyType).IsValueType)
                    {
                        xnbStreamWriter.Write7BitEncodedInt(keyReaderIndex);
                    }
                    keyReader.Write(xnbReaderManager, xnbStreamWriter, keyValuePair.Key);

                    (int valueReaderIndex, XnbTypeReader valueReader) = xnbReaderManager.GetOrAddXnbTypeReaderFromTargetType <TValueType>();
                    if (!typeof(TValueType).IsValueType)
                    {
                        xnbStreamWriter.Write7BitEncodedInt(valueReaderIndex);
                    }
                    valueReader.Write(xnbReaderManager, xnbStreamWriter, keyValuePair.Value);
                }
            }
            else
            {
                throw new ArgumentException($"Expected {typeof(Dictionary<TKeyType, TValueType>).Name}, got {value.GetType().Name}");
            }
        }
Beispiel #3
0
 public override void Write(XnbReaderManager xnbReaderManager, XnbStreamWriter xnbStreamWriter, object value)
 {
     if (value is string text)
     {
         xnbStreamWriter.Write(text);
     }
 }