static SqlExceptionPrototype()
{
// Find SqlError constructor (note we don't get about the overload that accepts uint win32ErrorCode
MethodInfo methodInfo =
typeof(SqlException).GetMethod(
"CreateException",
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod,
null,
new[]
{
typeof(SqlErrorCollection),
typeof(string),
typeof(Guid),
typeof(Exception)
},
null);
Debug.Assert(methodInfo != null);
// Create parameters
List<ParameterExpression> parameters = new List<ParameterExpression>(4)
{
Expression.Parameter(
typeof(SqlErrorCollection),
"errorCollection"),
Expression.Parameter(typeof(string), "serverVersion"),
Expression.Parameter(typeof(Guid), "conId"),
Expression.Parameter(typeof(Exception), "innerException")
};
// Create lambda expression.
_constructor = Expression.Lambda<Func<SqlErrorCollection, string, Guid, Exception, SqlException>>(
Expression.Call(methodInfo, parameters),
parameters).Compile();
}