private static MethodEvent CreateMethodEventFromMethodCallExpression(Guid eventSourceId, MethodCallExpression expression) { var methodEvent = new MethodEvent(eventSourceId, expression.Method); AddArgumentsFromMethodCallExpression(expression, methodEvent); return(methodEvent); }
private static void AddArgumentsFromMethodCallExpression(MethodCallExpression expression, MethodEvent methodEvent) { var parameterInfos = expression.Method.GetParameters(); for (var argumentIndex = 0; argumentIndex < expression.Arguments.Count(); argumentIndex++) { var parameterName = parameterInfos[argumentIndex].Name; var argument = expression.Arguments[argumentIndex] as MemberExpression; if (null != argument) { var fieldInfo = argument.Member as FieldInfo; if (null != fieldInfo) { var constantExpression = argument.Expression as ConstantExpression; if (null != constantExpression) { methodEvent.Arguments[parameterName] = fieldInfo.GetValue(constantExpression.Value); } } } } }
private static MethodEvent CreateMethodEventFromMethodCallExpression(Guid eventSourceId, MethodCallExpression expression) { var methodEvent = new MethodEvent(eventSourceId, expression.Method); AddArgumentsFromMethodCallExpression(expression, methodEvent); return methodEvent; }
private static void AddArgumentsFromMethodCallExpression(MethodCallExpression expression, MethodEvent methodEvent) { var parameterInfos = expression.Method.GetParameters(); for (var argumentIndex = 0; argumentIndex < expression.Arguments.Count(); argumentIndex++) { var parameterName = parameterInfos[argumentIndex].Name; var argument = expression.Arguments[argumentIndex] as MemberExpression; if (null != argument) { var fieldInfo = argument.Member as FieldInfo; if (null != fieldInfo) { var constantExpression = argument.Expression as ConstantExpression; if (null != constantExpression) { methodEvent.Arguments[parameterName] = fieldInfo.GetValue(constantExpression.Value); } } } } }