Example #1
0
        /// <summary>
        ///     The method invocation
        /// </summary>
        /// <param name="methodName">string</param>
        /// <param name="parameters">params</param>
        /// <returns>return value</returns>
        public object Invoke(string methodName, params object[] parameters)
        {
            // First check the methods, so we can override all other access by specifying a method
            if (!_methodMap.TryGetValue(methodName, out var actions))
            {
                throw new NotImplementedException();
            }
            var methodCallInfo = new MethodCallInfo
            {
                Interceptor = this,
                MethodName  = methodName,
                Arguments   = parameters
            };

            foreach (var action in actions)
            {
                action(methodCallInfo);
                if (methodCallInfo.HasError)
                {
                    break;
                }
            }
            if (methodCallInfo.HasError)
            {
                throw methodCallInfo.Error;
            }
            // TODO: make out parameters possible
            return(methodCallInfo.ReturnValue);
        }
Example #2
0
 /// <summary>
 ///     Get the property name from the argument "index" of the MethodCallInfo
 ///     If the argument is a string, it will be returned.
 ///     If the arugment is a LambdaExpression, the member name will be retrieved
 /// </summary>
 /// <param name="methodCallInfo">MethodCallInfo</param>
 /// <param name="index">Index of the argument</param>
 /// <returns>Property name</returns>
 public static string PropertyNameOf(this MethodCallInfo methodCallInfo, int index)
 {
     if (!(methodCallInfo.Arguments[index] is string propertyName))
     {
         var propertyExpression = (LambdaExpression)methodCallInfo.Arguments[index];
         propertyName = propertyExpression.GetMemberName();
     }
     return(propertyName);
 }