public Deserialize ( |
||
reader | ||
return | object |
public object Deserialize(BinaryReader reader) {
if (reader == null)
throw new ArgumentNullException("reader");
var graphType = ReadType(reader);
if (graphType == null)
throw new InvalidOperationException("No type found in the graph stream");
#if PCL
if (!graphType.GetTypeInfo().IsDefined(typeof(SerializableAttribute)))
#else
if (!Attribute.IsDefined(graphType, typeof (SerializableAttribute)))
#endif
throw new ArgumentException(String.Format("The type '{0}' is not marked as serializable.", graphType));
#if PCL
if (graphType.IsAssignableTo(typeof(ISerializable)))
#else
if (typeof (ISerializable).IsAssignableFrom(graphType))
#endif
return CustomDeserialize(reader, graphType);
return DeserializeType(reader, graphType);
}
BinarySerializer::Deserialize ( Stream stream ) : object |
public static void SerializeObjectNameWithNoParent() { var objName = new ObjectName("name"); var serializer = new BinarySerializer(); byte[] bytes; using (var memoryStream = new MemoryStream()) { serializer.Serialize(memoryStream, objName); memoryStream.Flush(); bytes = memoryStream.ToArray(); } object graph = null; using (var memoryStream = new MemoryStream(bytes)) { graph = serializer.Deserialize(memoryStream, typeof(ObjectName)); } Assert.IsNotNull(graph); Assert.IsInstanceOf<ObjectName>(graph); var objName2 = (ObjectName) graph; Assert.AreEqual(objName.Name, objName2.Name); Assert.AreEqual(objName, objName2); }