本文整理汇总了C#中SerializationWriter类的典型用法代码示例。如果您正苦于以下问题:C# SerializationWriter类的具体用法?C# SerializationWriter怎么用?C# SerializationWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializationWriter类属于命名空间,在下文中一共展示了SerializationWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public byte[] Serialize()
{
var _SerializationWriter = new SerializationWriter();
_SerializationWriter.WriteString(ThrowedException);
return _SerializationWriter.ToArray();
}
示例2: Serialize
public byte[] Serialize()
{
var _SerializationWriter = new SerializationWriter();
_SerializationWriter.WriteString(Message);
return _SerializationWriter.ToArray();
}
示例3: Serialize
public byte[] Serialize()
{
var _SerializationWriter = new SerializationWriter();
_SerializationWriter.WriteUInt32(NumberOfQueueEntries);
return _SerializationWriter.ToArray();
}
示例4: Serialize
public static void Serialize(SerializationWriter writer, Color color)
{
BitVector32 flags = new BitVector32();
if (color.IsKnownColor)
flags[ColorIsKnown] = true;
else if (color.IsNamedColor)
flags[ColorHasName] = true;
else if (!color.IsEmpty)
{
flags[ColorHasValue] = true;
flags[ColorHasRed] = color.R != 0;
flags[ColorHasGreen] = color.G != 0;
flags[ColorHasBlue] = color.B != 0;
flags[ColorHasAlpha] = color.A != 0;
}
writer.WriteOptimized(flags);
if (color.IsKnownColor)
writer.WriteOptimized((int) color.ToKnownColor());
else if (color.IsNamedColor)
writer.WriteOptimized(color.Name);
else if (!color.IsEmpty)
{
byte component;
if ( (component = color.R) != 0) writer.Write(component);
if ( (component = color.G) != 0) writer.Write(component);
if ( (component = color.B) != 0) writer.Write(component);
if ( (component = color.A) != 0) writer.Write(component);
}
}
示例5: Serialize
public Byte[] Serialize()
{
var _SerializationWriter = new SerializationWriter();
_SerializationWriter.WriteString(ObjectLocation);
_SerializationWriter.WriteByte(NewDefaultRule);
return _SerializationWriter.ToArray();
}
示例6: GetObjectData
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
using (SerializationWriter writer = new SerializationWriter())
{
writer.Write(_name);
writer.WriteObject(_dataType);
writer.WriteObject(_value);
info.AddValue("d", writer.ToArray());
}
}
示例7: Serialize
public byte[] Serialize()
{
SerializationWriter writer = new SerializationWriter();
writer.WriteObject(AccountName);
writer.WriteObject(DeviceID);
writer.WriteObject(Timestamp);
writer.WriteObject(Latitude);
writer.WriteObject(Longitude);
writer.WriteObject(AccuracyInMeters);
return writer.ToArray();
}
示例8: TestNull
public void TestNull()
{
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms))
using (SerializationReader sr = new SerializationReader(ms))
{
sw.Write<object>(null);
sw.Write<int[]>(null);
sw.Write<List<int>>(null);
sw.Write<Dictionary<int, string>>(null);
sw.Write<TestSerializable>(null);
}
}
示例9: TestUTF16Chars
public void TestUTF16Chars()
{
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
{
for (int i = 0; i < 55296; i++)
sw.Write((char)i);
sw.Flush();
ms.Position = 0;
for (int i = 0; i < 55296; i++)
Assert.AreEqual((char)i, sr.Read<char>());
}
}
示例10: TestUTF16String
public void TestUTF16String()
{
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 55296; i++)
sb.Append((char)i);
string res = sb.ToString();
sw.Write(res);
sw.Flush();
ms.Position = 0;
Assert.AreEqual(res, sr.Read<string>());
}
}
示例11: TestBytes
public void TestBytes()
{
Random rand = new Random();
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms))
using (SerializationReader sr = new SerializationReader(ms))
{
byte[] values = new byte[Config.MULTI_TEST_COUNT];
rand.NextBytes(values);
for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
sw.Write(values[i]);
sw.Flush();
ms.Position = 0;
for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
Assert.AreEqual(values[i], sr.Read<byte>());
}
}
示例12: TestBasicList
public void TestBasicList()
{
Random rand = new Random();
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms))
using (SerializationReader sr = new SerializationReader(ms))
{
List<int> list = new List<int>(Config.MULTI_TEST_COUNT);
for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
list.Add(rand.Next(int.MinValue, int.MaxValue));
sw.Write(list);
sw.Flush();
ms.Position = 0;
List<int> ret = sr.Read<List<int>>();
for (int i = 0; i < list.Count; i++)
Assert.AreEqual(list[i], ret[i]);
}
}
示例13: TestBasicDictionary
public void TestBasicDictionary()
{
Random rand = new Random();
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms))
using (SerializationReader sr = new SerializationReader(ms))
{
Dictionary<int, float> dict = new Dictionary<int, float>(Config.MULTI_TEST_COUNT);
for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
dict[rand.Next(int.MinValue, int.MaxValue)] = (float)rand.NextDouble();
sw.Write(dict);
sw.Flush();
ms.Position = 0;
Dictionary<int, float> ret = sr.Read<Dictionary<int, float>>();
foreach (KeyValuePair<int, float> kvp in dict)
Assert.AreEqual(kvp.Value, ret[kvp.Key]);
}
}
示例14: TestBasicArray
public void TestBasicArray()
{
Random rand = new Random();
using (MemoryStream ms = new MemoryStream())
using (SerializationWriter sw = new SerializationWriter(ms))
using (SerializationReader sr = new SerializationReader(ms))
{
int[] array = new int[Config.MULTI_TEST_COUNT];
for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
array[i] = rand.Next(int.MinValue, int.MaxValue);
sw.Write(array);
sw.Flush();
ms.Position = 0;
int[] ret = sr.Read<int[]>();
for (int i = 0; i < ret.Length; i++)
Assert.AreEqual(array[i], ret[i]);
}
}
示例15: Serialize
public byte[] Serialize()
{
SerializationWriter writer = new SerializationWriter();
writer.WriteObject(ServerName);
writer.WriteObject(Name);
if (Type == ObjectTypes.Actor)
writer.WriteObject((byte)0);
else
if (Type == ObjectTypes.Sensor)
writer.WriteObject((byte)1);
else
if (Type == ObjectTypes.Unknown)
writer.WriteObject((byte)2);
writer.WriteObject(TypeName);
writer.WriteObject(Timecode.Ticks);
writer.WriteObject(XS1ObjectID);
writer.WriteObject(Value);
return writer.ToArray();
}