FIX: work with non-public constructors

This commit is contained in:
Marc Gravell
2011-08-04 07:14:59 +01:00
parent aec048028f
commit c873a24ddb
2 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -1331,7 +1331,7 @@ IDataReader reader, int startBound = 0, int length = -1, bool returnNullIfFirstM
il.BeginExceptionBlock();
// stack is empty
il.Emit(OpCodes.Newobj, typeof(T).GetConstructor(Type.EmptyTypes)); // stack is now [target]
il.Emit(OpCodes.Newobj, typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)); // stack is now [target]
bool first = true;
var allDone = il.DefineLabel();
foreach (var item in setters)
+13 -1
View File
@@ -1038,6 +1038,18 @@ Order by p.Id";
{
public System.Data.Linq.Binary Value { get; set; }
}
class WithPrivateConstructor
{
public int Foo { get; set; }
private WithPrivateConstructor() { }
}
public void TestWithNonPublicConstructor()
{
var output = connection.Query<WithPrivateConstructor>("select 1 as Foo").First();
output.Foo.IsEqualTo(1);
}
}
}