Customizing Dump in a DataContext package
Hi, I'm having an issue with the ToDump
function inside a DataContext package. I'm creating a static method as per documentation but it doesn't seem to be called and the output does not get formatted the way I want it to.
Example:
public sealed class MongoDriver : DynamicDataContextDriver { public static object ToDump(object input) { var document = input as BsonDocument; return document != null ? BsonTypeMapper.MapToDotNetValue(document) : input; } // unrelated code here }
Is there something I'm missing or is this a limitation of the DataContext?
Comments
-
The static
ToDump
method applies to scripts and My Extensions - not drivers.With drivers, you instead override the
PreprocessObjectToWrite
method. This is described in the documentation:
https://www.linqpad.net/Extensibility.aspx -
@JoeAlbahari said:
The staticToDump
method applies to scripts and My Extensions - not drivers.With drivers, you instead override the
PreprocessObjectToWrite
method. This is described in the documentation:
https://www.linqpad.net/Extensibility.aspxOh, I see. Thank you, Joseph!
For those that might come after, I've achieved what I wanted with just a small modification of my code:
public sealed class MongoDriver : DynamicDataContextDriver { public override void PreprocessObjectToWrite(ref object objectToWrite, ObjectGraphInfo info) { var document = objectToWrite as BsonDocument; if (document != null) { objectToWrite = BsonTypeMapper.MapToDotNetValue(document); return; } } // unrelated code here }