JamesZhuBt / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Add support for protected default constructors #58

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using the type Dog from the first example on the Project Home page, add a 
protected parameter-less constructor. (i.e. protected Dog() {})
2. Run the example.

What is the expected output? What do you see instead?

I expected the examples to run as per normal. Instead an exception was raised:

System.ArgumentNullException : Value cannot be null. Parameter name con.
at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, 
ConstructorInfo con)
Dapper.cs(1335,0): at Dapper.SqlMapper.GetClassDeserializer[T](IDataReader 
reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)

What version of the product are you using? On what operating system?

Revision 06c761fa180c. Windows 7.

Please provide any additional information below.

In revision 06c761fa180c, if line 1335 is changed to the below, then protected 
parameterless constructors can be used.

il.Emit(OpCodes.Newobj, typeof(T).GetConstructor(BindingFlags.Instance | 
BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null)); // 
stack is now [target]

Original issue reported on code.google.com by as.da...@gmail.com on 4 Aug 2011 at 12:54

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 4 Aug 2011 at 5:15

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 4 Aug 2011 at 6:16