public void Serialize(BinaryWriter writer, object obj) {
if (writer == null)
throw new ArgumentNullException("writer");
if (obj == null)
throw new ArgumentNullException("obj");
var objType = obj.GetType();
#if !PCL
if (!Attribute.IsDefined(objType, typeof(SerializableAttribute)))
#else
if (!objType.GetTypeInfo().IsDefined(typeof(SerializableAttribute)))
#endif
throw new ArgumentException(String.Format("The type '{0} is not serializable", objType.FullName));
var graph = new SerializationInfo(objType, new FormatterConverter());
var context = new StreamingContext();
#if PCL
if (objType.IsTypeOf(typeof(ISerializable))) {
#else
if (typeof (ISerializable).IsAssignableFrom(objType)) {
#endif
((ISerializable) obj).GetObjectData(graph, context);
} else {
GetObjectValues(objType, obj, graph);
}
SerializeGraph(writer, Encoding, objType, graph);
}