Answer the question
In order to leave comments, you need to log in
Serialization in PCL
Hey!
There is a PCL (Portable Class Library) library used in the Windows Store and Windows Phone 8 projects.
This library has structures that have several fields of basic types:
private FieldTypes _type;
private string _name;
private string _value;
internal byte[] ToBinary()
{
byte[] binaryType = BitConverter.GetBytes((int)_type);
byte[] binaryNameLength = BitConverter.GetBytes(_name.Length);
byte[] binaryName = new byte[_name.Length * sizeof(char)];
Buffer.BlockCopy(_name.ToCharArray(), 0, binaryName, 0, binaryName.Length);
byte[] binaryValueLength = BitConverter.GetBytes(_value.Length);
byte[] binaryValue = new byte[_value.Length * sizeof(char)];
Buffer.BlockCopy(_value.ToCharArray(), 0, binaryValue, 0, binaryValue.Length);
int resultLength = binaryType.Length + binaryNameLength.Length + binaryName.Length + binaryValueLength.Length + binaryValue.Length;
byte[] result = new byte[resultLength];
Buffer.BlockCopy(binaryType, 0, result, 0, binaryType.Length);
Buffer.BlockCopy(binaryName, 0, result, binaryType.Length, binaryName.Length);
Buffer.BlockCopy(binaryNameLength, 0, result, binaryType.Length + binaryName.Length, binaryNameLength.Length);
Buffer.BlockCopy(binaryValueLength, 0, result, binaryType.Length + binaryName.Length + binaryNameLength.Length, binaryValueLength.Length);
Buffer.BlockCopy(binaryValue, 0, result, binaryType.Length + binaryName.Length + binaryNameLength.Length + binaryValueLength.Length, binaryValue.Length);
return result;
}
Answer the question
In order to leave comments, you need to log in
BinaryFormatter ?
UPD: I'm sorry, I didn't notice the phrase about the Windows Store.
Check out UniversalSerializer , it should be able to do that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question