本文整理汇总了C#中BinarySerializer类的典型用法代码示例。如果您正苦于以下问题:C# BinarySerializer类的具体用法?C# BinarySerializer怎么用?C# BinarySerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinarySerializer类属于命名空间,在下文中一共展示了BinarySerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBufferTest
public void GetBufferTest()
{
var binarySerializer = new BinarySerializer();
var buffer = binarySerializer.GetBuffer(new TestHelpers.Customer(21));
var customer = binarySerializer.Deserializer(buffer, typeof(Customer));
Assert.IsInstanceOfType(customer, typeof(Customer));
}
示例2: foreach
void IDataSerializable.Serialize(BinarySerializer serializer)
{
if (serializer.Mode == SerializerMode.Write)
{
serializer.Writer.Write(Textures.Count);
foreach (var texture in Textures)
{
var name = texture.Key;
var list = texture.Value;
serializer.Serialize(ref name);
serializer.Serialize(ref list);
}
}
else
{
var count = serializer.Reader.ReadInt32();
Textures = new Dictionary<string, List<MaterialTexture>>(count);
for(int i = 0; i < count; i++)
{
string name = null;
List<MaterialTexture> list = null;
serializer.Serialize(ref name);
serializer.Serialize(ref list);
Textures.Add(name, list);
}
}
serializer.Serialize(ref Properties);
}
示例3: GetBuffer_UseGeneric
public void GetBuffer_UseGeneric()
{
var binarySerializer = new BinarySerializer();
var buffer = binarySerializer.GetBuffer(new TestHelpers.Customer(32));
var customer = binarySerializer.Deserializer<Customer>(buffer);
Assert.IsInstanceOfType(customer, typeof(Customer));
}
示例4:
/// <inheritdoc/>
void IDataSerializable.Serialize(BinarySerializer serializer)
{
serializer.Serialize(ref Name);
serializer.Serialize(ref ShareConstantBuffers);
serializer.Serialize(ref Techniques);
serializer.Serialize(ref Arguments, SerializeFlags.Nullable);
}
示例5: LoadState
private void LoadState()
{
try
{
var ser = new BinarySerializer();
var stat = ser.Deserialize(StateFileName) as Dictionary<String, Object>;
if (stat != null)
{
var w = (Int32)stat["Width"];
var h = (Int32)stat["Height"];
if (w > MinimumSize.Width)
Width = w;
if (h > MinimumSize.Height)
Height = h;
var x = (Int32)stat["X"];
var y = (Int32)stat["Y"];
if (x > 0 && y > 0)
Location = new Point(x, y);
foreach (var p in GetType().GetProperties())
{
if (Attribute.IsDefined(p, typeof(StateItemAttribute)))
p.SetValue(this, stat[p.Name], null);
}
}
}
catch { }
}
示例6:
/// <summary>Reads or writes datas from/to the given binary serializer.</summary>
/// <param name="serializer">The binary serializer.</param>
void IDataSerializable.Serialize(BinarySerializer serializer)
{
serializer.Serialize(ref MaterialIndex);
serializer.Serialize(ref IndexBufferRange);
serializer.Serialize(ref VertexBufferRange);
serializer.Serialize(ref Properties);
}
示例7: DocumentCategorizerComponent
public DocumentCategorizerComponent(string modelFileName)
: base(typeof(DocumentCategorizerComponent))
{
mBlockSelector = "TextBlock";
BinarySerializer reader = new BinarySerializer(modelFileName, FileMode.Open);
LoadModel(reader);
}
示例8: Load
public void Load(BinarySerializer reader)
{
TotalHits = reader.ReadLong();
ActualSize = reader.ReadInt();
ResultSetXml = reader.ReadString();
TimeStamp = DateTime.FromOADate(reader.ReadDouble());
}
示例9: SerializeTest
public void SerializeTest()
{
BinarySerializer serializer = new BinarySerializer();
MemoryStream stream = serializer.Serialize(new List<string>() { "f", "s" });
Assert.IsNotNull(stream);
}
示例10: Main
private static void Main(string[] args)
{
var file = args[0];
using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read))
{
var serializer = new BinarySerializer();
serializer.MemberDeserialized += (sender, eventArgs) => Console.WriteLine(eventArgs.MemberName + " : " + eventArgs.Value);
var iso = serializer.Deserialize<Iso9660.Iso9660>(stream);
stream.Position = 0;
var xmlSerializer = new XmlSerializer(typeof (Iso9660.Iso9660));
var outfilePath = Path.GetDirectoryName(file);
var outfileName = Path.GetFileNameWithoutExtension(file) + ".xml";
var outfile = Path.Combine(outfilePath, outfileName);
using (var xmlStream = new FileStream(outfile, FileMode.Create, FileAccess.Write))
{
xmlSerializer.Serialize(xmlStream, iso);
}
Console.ReadKey();
}
}
示例11: Save
// *** ISerializable interface implementation ***
public void Save(BinarySerializer writer)
{
writer.WriteLong(TotalHits);
writer.WriteInt(ActualSize);
writer.WriteString(ResultSetXml);
writer.WriteDouble(TimeStamp.ToOADate());
}
示例12: Load
public void Load(BinarySerializer reader)
{
Utils.ThrowException(reader == null ? new ArgumentNullException("reader") : null);
// the following statements throw serialization-related exceptions
mLanguage = (Language)reader.ReadInt();
CreateStemmer();
}
示例13: SerializeAndReadBack
public void SerializeAndReadBack()
{
var registry = new DependencyFingerprintProtocolRegistry();
registry.Register<CombinedFingerprintProtocol>();
registry.Register<SourceSetFingerprintProtocol>();
var ser = new BinarySerializer(registry);
var dep = CreateDependencyObject();
var fp1 = dep.Fingerprint;
byte[] data;
using (var ms = new MemoryStream())
{
fp1.Save(ser, ms);
data = ms.ToArray();
}
CombinedFingerprint fp2;
using (var ms = new MemoryStream(data))
{
fp2 = new CombinedFingerprint(ser, ms);
}
fp1.Should().Be(fp2);
}
示例14:
/// <inheritdoc/>
void IDataSerializable.Serialize(BinarySerializer serializer)
{
serializer.Serialize(ref Name, SerializeFlags.Nullable);
serializer.Serialize(ref IsSubPass);
serializer.Serialize(ref Attributes);
serializer.Serialize(ref Pipeline);
}
示例15: ApplyInternal
public override ISerializer ApplyInternal()
{
var serializer = new BinarySerializer(_binaryFormatter);
VerifyErrors(serializer);
return serializer;
}