|
3 | 3 | using System.IO;
|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Linq.Expressions;
|
| 6 | +using NHibernate.Util; |
6 | 7 |
|
7 | 8 | namespace NHibernate
|
8 | 9 | {
|
@@ -243,8 +244,8 @@ private static Func<TParameter, object> GetGetLoggerMethodCall<TParameter>()
|
243 | 244 | var method = LogManagerType.GetMethod("GetLogger", new[] { typeof(TParameter) });
|
244 | 245 | ParameterExpression resultValue;
|
245 | 246 | ParameterExpression keyParam = Expression.Parameter(typeof(TParameter), "key");
|
246 |
| - MethodCallExpression methodCall = Expression.Call(null, method, new Expression[] { resultValue = keyParam }); |
247 |
| - return Expression.Lambda<Func<TParameter, object>>(methodCall, new[] { resultValue }).Compile(); |
| 247 | + MethodCallExpression methodCall = Expression.Call(null, method, resultValue = keyParam); |
| 248 | + return Expression.Lambda<Func<TParameter, object>>(methodCall, resultValue).Compile(); |
248 | 249 | }
|
249 | 250 | }
|
250 | 251 |
|
@@ -280,66 +281,29 @@ public class Log4NetLogger: IInternalLogger
|
280 | 281 |
|
281 | 282 | static Log4NetLogger()
|
282 | 283 | {
|
283 |
| - IsErrorEnabledDelegate = GetPropertyGetter("IsErrorEnabled"); |
284 |
| - IsFatalEnabledDelegate = GetPropertyGetter("IsFatalEnabled"); |
285 |
| - IsDebugEnabledDelegate = GetPropertyGetter("IsDebugEnabled"); |
286 |
| - IsInfoEnabledDelegate = GetPropertyGetter("IsInfoEnabled"); |
287 |
| - IsWarnEnabledDelegate = GetPropertyGetter("IsWarnEnabled"); |
288 |
| - ErrorDelegate = GetMethodCallForMessage("Error"); |
289 |
| - ErrorExceptionDelegate = GetMethodCallForMessageException("Error"); |
290 |
| - ErrorFormatDelegate = GetMethodCallForMessageFormat("ErrorFormat"); |
291 |
| - |
292 |
| - FatalDelegate = GetMethodCallForMessage("Fatal"); |
293 |
| - FatalExceptionDelegate = GetMethodCallForMessageException("Fatal"); |
294 |
| - |
295 |
| - DebugDelegate = GetMethodCallForMessage("Debug"); |
296 |
| - DebugExceptionDelegate = GetMethodCallForMessageException("Debug"); |
297 |
| - DebugFormatDelegate = GetMethodCallForMessageFormat("DebugFormat"); |
298 |
| - |
299 |
| - InfoDelegate = GetMethodCallForMessage("Info"); |
300 |
| - InfoExceptionDelegate = GetMethodCallForMessageException("Info"); |
301 |
| - InfoFormatDelegate = GetMethodCallForMessageFormat("InfoFormat"); |
302 |
| - |
303 |
| - WarnDelegate = GetMethodCallForMessage("Warn"); |
304 |
| - WarnExceptionDelegate = GetMethodCallForMessageException("Warn"); |
305 |
| - WarnFormatDelegate = GetMethodCallForMessageFormat("WarnFormat"); |
306 |
| - } |
307 |
| - |
308 |
| - private static Func<object, bool> GetPropertyGetter(string propertyName) |
309 |
| - { |
310 |
| - ParameterExpression funcParam = Expression.Parameter(typeof(object), "l"); |
311 |
| - Expression convertedParam = Expression.Convert(funcParam, ILogType); |
312 |
| - Expression property = Expression.Property(convertedParam, propertyName); |
313 |
| - return (Func<object, bool>)Expression.Lambda(property, funcParam).Compile(); |
314 |
| - } |
315 |
| - |
316 |
| - private static Action<object, object> GetMethodCallForMessage(string methodName) |
317 |
| - { |
318 |
| - ParameterExpression loggerParam = Expression.Parameter(typeof(object), "l"); |
319 |
| - ParameterExpression messageParam = Expression.Parameter(typeof(object), "o"); |
320 |
| - Expression convertedParam = Expression.Convert(loggerParam, ILogType); |
321 |
| - MethodCallExpression methodCall = Expression.Call(convertedParam, ILogType.GetMethod(methodName, new[] { typeof(object) }), messageParam); |
322 |
| - return (Action<object, object>)Expression.Lambda(methodCall, new[] { loggerParam, messageParam }).Compile(); |
323 |
| - } |
324 |
| - |
325 |
| - private static Action<object, object, Exception> GetMethodCallForMessageException(string methodName) |
326 |
| - { |
327 |
| - ParameterExpression loggerParam = Expression.Parameter(typeof(object), "l"); |
328 |
| - ParameterExpression messageParam = Expression.Parameter(typeof(object), "o"); |
329 |
| - ParameterExpression exceptionParam = Expression.Parameter(typeof(Exception), "e"); |
330 |
| - Expression convertedParam = Expression.Convert(loggerParam, ILogType); |
331 |
| - MethodCallExpression methodCall = Expression.Call(convertedParam, ILogType.GetMethod(methodName, new[] { typeof(object), typeof(Exception) }), messageParam, exceptionParam); |
332 |
| - return (Action<object, object, Exception>)Expression.Lambda(methodCall, new[] { loggerParam, messageParam, exceptionParam }).Compile(); |
333 |
| - } |
334 |
| - |
335 |
| - private static Action<object, string, object[]> GetMethodCallForMessageFormat(string methodName) |
336 |
| - { |
337 |
| - ParameterExpression loggerParam = Expression.Parameter(typeof(object), "l"); |
338 |
| - ParameterExpression formatParam = Expression.Parameter(typeof(string), "f"); |
339 |
| - ParameterExpression parametersParam = Expression.Parameter(typeof(object[]), "p"); |
340 |
| - Expression convertedParam = Expression.Convert(loggerParam, ILogType); |
341 |
| - MethodCallExpression methodCall = Expression.Call(convertedParam, ILogType.GetMethod(methodName, new[] { typeof(string), typeof(object[]) }), formatParam, parametersParam); |
342 |
| - return (Action<object, string, object[]>)Expression.Lambda(methodCall, new[] { loggerParam, formatParam, parametersParam }).Compile(); |
| 284 | + IsErrorEnabledDelegate = DelegateHelper.BuildPropertyGetter<bool>(ILogType, "IsErrorEnabled"); |
| 285 | + IsFatalEnabledDelegate = DelegateHelper.BuildPropertyGetter<bool>(ILogType, "IsFatalEnabled"); |
| 286 | + IsDebugEnabledDelegate = DelegateHelper.BuildPropertyGetter<bool>(ILogType, "IsDebugEnabled"); |
| 287 | + IsInfoEnabledDelegate = DelegateHelper.BuildPropertyGetter<bool>(ILogType, "IsInfoEnabled"); |
| 288 | + IsWarnEnabledDelegate = DelegateHelper.BuildPropertyGetter<bool>(ILogType, "IsWarnEnabled"); |
| 289 | + ErrorDelegate = DelegateHelper.BuildAction<object>(ILogType, "Error"); |
| 290 | + ErrorExceptionDelegate = DelegateHelper.BuildAction<object, Exception>(ILogType, "Error"); |
| 291 | + ErrorFormatDelegate = DelegateHelper.BuildAction<string, object[]>(ILogType, "ErrorFormat"); |
| 292 | + |
| 293 | + FatalDelegate = DelegateHelper.BuildAction<object>(ILogType, "Fatal"); |
| 294 | + FatalExceptionDelegate = DelegateHelper.BuildAction<object, Exception>(ILogType, "Fatal"); |
| 295 | + |
| 296 | + DebugDelegate = DelegateHelper.BuildAction<object>(ILogType, "Debug"); |
| 297 | + DebugExceptionDelegate = DelegateHelper.BuildAction<object, Exception>(ILogType, "Debug"); |
| 298 | + DebugFormatDelegate = DelegateHelper.BuildAction<string, object[]>(ILogType, "DebugFormat"); |
| 299 | + |
| 300 | + InfoDelegate = DelegateHelper.BuildAction<object>(ILogType, "Info"); |
| 301 | + InfoExceptionDelegate = DelegateHelper.BuildAction<object, Exception>(ILogType, "Info"); |
| 302 | + InfoFormatDelegate = DelegateHelper.BuildAction<string, object[]>(ILogType, "InfoFormat"); |
| 303 | + |
| 304 | + WarnDelegate = DelegateHelper.BuildAction<object>(ILogType, "Warn"); |
| 305 | + WarnExceptionDelegate = DelegateHelper.BuildAction<object, Exception>(ILogType, "Warn"); |
| 306 | + WarnFormatDelegate = DelegateHelper.BuildAction<string, object[]>(ILogType, "WarnFormat"); |
343 | 307 | }
|
344 | 308 |
|
345 | 309 | public Log4NetLogger(object logger)
|
|
0 commit comments