/// <summary> /// Creates a new instance of the object being deserialized (since no constructors are called) /// then deserializes data into it. /// </summary> /// <param name="obj">The DataSet or DataTable to serialize.</param> /// <param name="info">See .Net serialization.</param> /// <param name="context">See .Net serialization.</param> /// <param name="selector">The selector which selected this surrogate.</param> /// <returns></returns> public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { obj = createNewInstance(obj); byte[] data = (byte[])info.GetValue("_", typeof(byte[])); if (obj.GetType() == typeof(DataSet) || obj is IModifiedTypedDataSet) { return(AdoNetHelper.DeserializeDataSet(obj as DataSet, data)); } else if (obj.GetType() == typeof(DataTable)) { return(AdoNetHelper.DeserializeDataTable(obj as DataTable, data)); } else if (obj is DataSet) { return(AdoNetHelper.DeserializeTypedDataSet(obj as DataSet, data)); } else if (obj is DataTable) { return(AdoNetHelper.DeserializeTypedDataTable(obj as DataTable, data)); } else { throw new InvalidOperationException("Not a supported Ado.Net object"); } }