Closed GoogleCodeExporter closed 9 years ago
Standard before-deserialize callbacks are supported, as are constructors and
custom factories. Would any of those suffice?
Original comment by marc.gravell
on 9 Jun 2014 at 9:35
Can you point me to a sample of using the before-deserialize callback? And/or a
custom factory? One of those may work. Thanks!
Original comment by kind...@gmail.com
on 9 Jun 2014 at 10:26
Callbacks are basically the same as WCF, although alternative signatures are
also supported. But:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeseriali
zingattribute(v=vs.110).aspx
Original comment by marc.gravell
on 9 Jun 2014 at 10:34
Hi Mark, thanks for the quick response. I'm not entirely sure how to set up the
callbacks with Dapper. Does there need to be some setup for Dapper before the
serialization attributes are recognized?
In the following test, the 4 strings are never populated in the methods
decorated with the serialize attributes:
public class TypeWithSeralizationCallbacks
{
public int X { get; set; }
public int Y { get; set; }
public string OnSerialize { get; set; }
public string OnSerialized { get; set; }
public string OnDeSerialize { get; set; }
public string OnDeSerialized { get; set; }
[OnSerializing]
internal void OnSerializingMethod( StreamingContext context )
{
OnSerialize = "OnSerialize";
}
[OnSerialized]
internal void OnSerializedMethod( StreamingContext context )
{
OnSerialized = "OnSerialized";
}
[OnDeserializing]
internal void OnDeserializingMethod( StreamingContext context )
{
OnDeSerialize = "OnDeSerialize";
}
[OnDeserialized]
internal void OnDeserializedMethod( StreamingContext context )
{
OnDeSerialized = "OnDeSerialized";
}
public void Print()
{
Console.WriteLine( "X: {0}", X );
Console.WriteLine( "Y: {0}", Y );
Console.WriteLine( "OnSerialize: {0}", OnSerialize ?? "null" );
Console.WriteLine( "OnSerialized: {0}", OnSerialized ?? "null" );
Console.WriteLine( "OnDeSerialize: {0}", OnDeSerialize ?? "null" );
Console.WriteLine( "OnDeSerialized: {0}", OnDeSerialized ?? "null" );
}
}
static void Main()
{
var conn = GetOpenConnection();
var obj = conn.Query<TypeWithSeralizationCallbacks>( "select 11 X, 22 Y" ).Single();
obj.Print();
Console.WriteLine( "\n\n--done--" );
Console.ReadLine();
}
Original comment by kind...@gmail.com
on 10 Jun 2014 at 12:01
Ah, dammit - my bad. Sorry, I misread the email title, and was confused that we
were talking about a different library. Entirely my fault - sorry. Let me
investigate. No, dapper doesn't offer anything here.
Original comment by marc.gravell
on 10 Jun 2014 at 7:20
Hi Mark, bummer. What are your thoughts on extending dapper to support this
type of scenario? For us, this is a must-have to get dapper integrated into our
application. Hey, no pressure :)
Original comment by kind...@gmail.com
on 10 Jun 2014 at 1:10
That's about this likely:
https://github.com/StackExchange/dapper-dot-net/commit/88766056c8788190fcb5ad5b0
fc525005d70e281
Original comment by marc.gravell
on 10 Jun 2014 at 1:43
Marc, (not Mark, sorry about that earlier)... That's awesome! We'll dive into
this today. Thanks!
Original comment by kind...@gmail.com
on 10 Jun 2014 at 3:04
Original comment by marc.gravell
on 6 Aug 2014 at 3:40
Original issue reported on code.google.com by
kind...@gmail.com
on 9 Jun 2014 at 9:32