static public string GetStatusResponseResultForMethod(object result, Delegate method)
        {
            var      methodInfo = RuntimeReflectionExtensions.GetMethodInfo(method);
            Type     ret        = methodInfo.ReturnType;
            TypeCode returnType = Convert.GetTypeCode(ret);

            try
            {
                bool isObj = returnType == TypeCode.Object;    //Convert.GetTypeCode(returnType)
                if (isObj)
                {
                    if (result != null && Convert.GetTypeCode(result) == returnType)
                    {
                        return(GetRequestResponseSuccess());
                    }
                    return(GetRequestResponseFailure());
                }
                else
                {
                    if (Convert.GetTypeCode(result) == returnType)
                    {
                        if (returnType == TypeCode.Boolean)   //check the response value for boolean
                        {
                            return((bool)result ? GetRequestResponseSuccess() : GetRequestResponseFailure());
                        }
                        return(GetRequestResponseSuccess());
                    }
                    return(GetRequestResponseFailure());
                }
            }
            catch (Exception)
            {
                return(GetRequestResponseFailure());
            }
        }
Esempio n. 2
0
        public static MethodInfo GetMethodInfo(this Delegate func)
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(RuntimeReflectionExtensions.GetMethodInfo(func));
#else
            return(func.Method);
#endif
        }
Esempio n. 3
0
 private string getMethodName()
 {
     if (_methodName == null)
     {
         _methodName = RuntimeReflectionExtensions.GetMethodInfo(_origObject).Name;
     }
     return(_methodName);
 }
Esempio n. 4
0
        public static MethodInfo GetMethodInfo(Delegate source)
        {
#if NET35 || NET40
            return(source.Method);
#else
            return(RuntimeReflectionExtensions.GetMethodInfo(source));
#endif
        }
        public static MethodInfo GetMethodInfo(this Delegate delegateInstance)
        {
            if (delegateInstance == null)
            {
                throw new ArgumentNullException("delegateInstance");
            }

            return(RuntimeReflectionExtensions.GetMethodInfo(delegateInstance));
        }
Esempio n. 6
0
        public static void Calculate(ShowResult showResult, int a, int b)
        {
            if (a < 0 || b < 0)
            {
                Console.WriteLine("参数有误");
            }
            else
            {
                System.Reflection.MethodInfo methodInfo = RuntimeReflectionExtensions.GetMethodInfo(showResult);
                Console.WriteLine("在这里写入一条日志" + methodInfo.ToString());

                Console.WriteLine(showResult?.Invoke(a, b));
                //Console.WriteLine(showResult(a, b));
            }
        }
Esempio n. 7
0
 private string getMethodName(Delegate del)
 {
     return(RuntimeReflectionExtensions.GetMethodInfo(del).Name);
 }
        internal static string FormatObject(object value)
        {
            if (value == null)
            {
                return("null");
            }
            if (value is string)
            {
                return("\"" + value + "\"");
            }
            if (value is char)
            {
                return("'" + value + "'");
            }

            var exception = value as Exception;

            if (exception != null)
            {
                return("{" + exception.GetType().Name + "}");
            }

            var type = value.GetType();

#if NETCOREAPP1_1
            var isGenericType = new Func <Type, bool>(t => t.GetTypeInfo().IsGenericType);
#else
            var isGenericType = new Func <Type, bool>(t => t.IsGenericType);
#endif
            if (isGenericType(type) && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
            {
                var k = type.GetProperty("Key").GetValue(value, null);
                var v = type.GetProperty("Value").GetValue(value, null);
                return(String.Format("{{{0}:{1}}}", FormatObject(k), FormatObject(v)));
            }
            if (type.GetInterfaces()
                .Where(isGenericType)
                .Any(i => i.GetGenericTypeDefinition() == typeof(IGrouping <,>)))
            {
                var k = type.GetProperty("Key").GetValue(value, null);
                return(String.Format("{{{0}:{1}}}", FormatObject(k), FormatEnumerable(value)));
            }
            if (value is Type)
            {
                return("typeof(" + ExpressionParser.NameOfType((Type)value) + ")");
            }
            if (value is Delegate)
            {
                var del = (Delegate)value;

#if NETCOREAPP1_1
                var method = RuntimeReflectionExtensions.GetMethodInfo(del);
#else
                var method = del.Method;
#endif

                return(String.Format("delegate {0}, type: {2} ({1})", ExpressionParser.NameOfType(del.GetType()), String.Join(", ", method.GetParameters().Select(x => ExpressionParser.NameOfType(x.ParameterType))), ExpressionParser.NameOfType(method.ReturnType)));
            }
            if (value is IEnumerable)
            {
                return(FormatEnumerable(value));
            }
            return(value.ToString());
        }