public static object BinaryDeserialize(Type type, BinarySerializerData data) { object serializer = GetSerializer(type, binarySerializers); if (serializer == null) { throw new NotImplementedException("BinarySerializer for Type '" + type.Name + "' is not implemented"); } if (data.Length == 0) { return(null); } MethodInfo method = serializer.GetType().GetMethod("Deserialize"); return(method.Invoke(serializer, new object[] { data })); }
private void CreateValue(XElement element, Type type, object value, bool preferBinarySerialization) { if (preferBinarySerialization) { BinarySerializerData serializedData = Serializer.BinarySerialize(type, value); XHelper.CreateAttribute(element, "Length", serializedData.Length.ToString()); element.Add(new XCData(Convert.ToBase64String(serializedData.Data))); } else { //if not using binary serialization, we just use the regular serializer if (value != null) { XHelper.CreateAttribute(element, "Value", Serializer.Serialize(type, value)); } else { XHelper.CreateAttribute(element, "Value", "null"); } } }