Ejemplo n.º 1
0
        internal override void TranslateToILDelete(ILGenerator il, Type rtype)
        {
            IReflect ir     = this.func.InferType(null);
            Type     obType = Convert.ToType(ir);

            this.func.TranslateToIL(il, obType);
            this.args.TranslateToIL(il, typeof(Object[]));
            if (this.func is Binding)
            {
                MethodInfo deleteOp;
                if (ir is ClassScope)
                {
                    deleteOp = ((ClassScope)ir).owner.deleteOpMethod;
                }
                else
                {
                    deleteOp = ir.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static,
                                            null, new Type[] { obType, typeof(Object[]) }, null);
                }
                if (deleteOp != null && (deleteOp.Attributes & MethodAttributes.SpecialName) != 0 && deleteOp.ReturnType == Typeob.Boolean)
                {
                    il.Emit(OpCodes.Call, deleteOp);
                    Convert.Emit(this, il, Typeob.Boolean, rtype);
                    return;
                }
            }
            ConstantWrapper.TranslateToILInt(il, this.args.count - 1);
            il.Emit(OpCodes.Ldelem_Ref);
            Convert.Emit(this, il, Typeob.Object, Typeob.String);
            il.Emit(OpCodes.Call, CompilerGlobals.deleteMemberMethod);
            Convert.Emit(this, il, Typeob.Boolean, rtype);
        }
Ejemplo n.º 2
0
        internal override void TranslateToILDelete(ILGenerator il, Type rtype)
        {
            IReflect ir   = this.func.InferType(null);
            Type     type = Microsoft.JScript.Convert.ToType(ir);

            this.func.TranslateToIL(il, type);
            this.args.TranslateToIL(il, Typeob.ArrayOfObject);
            if (this.func is Binding)
            {
                MethodInfo deleteOpMethod;
                if (ir is ClassScope)
                {
                    deleteOpMethod = ((ClassScope)ir).owner.deleteOpMethod;
                }
                else
                {
                    deleteOpMethod = ir.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type, Typeob.ArrayOfObject }, null);
                }
                if (((deleteOpMethod != null) && ((deleteOpMethod.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope)) && (deleteOpMethod.ReturnType == Typeob.Boolean))
                {
                    il.Emit(OpCodes.Call, deleteOpMethod);
                    Microsoft.JScript.Convert.Emit(this, il, Typeob.Boolean, rtype);
                    return;
                }
            }
            ConstantWrapper.TranslateToILInt(il, this.args.count - 1);
            il.Emit(OpCodes.Ldelem_Ref);
            Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, Typeob.String);
            il.Emit(OpCodes.Call, CompilerGlobals.deleteMemberMethod);
            Microsoft.JScript.Convert.Emit(this, il, Typeob.Boolean, rtype);
        }
Ejemplo n.º 3
0
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if (method != null && !method.IsStatic)
                    {
                        MemberInfo[] propMethods = new MemberInfo[1];
                        propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
                        return(propMethods);
                    }
                }
            }
            MemberInfo[] members = reflect.GetMember(name, bindingAttr);
            if (members != null && members.Length > 0)
            {
                return(ScriptObject.WrapMembers(members, namedItem));
            }
            return(null);
        }
Ejemplo n.º 4
0
        private static MethodInfo getOperator(IReflect type, string methodName)
        {
            const BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public;
            var equalityOperator            = type.GetMethod(methodName, bindingFlags);

            return(equalityOperator);
        }
Ejemplo n.º 5
0
        private static bool TryInvokeMethod(IReflect target, string name, bool ignoreCase, object[] args, out object result)
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (target is IDispatchEx dispatchEx)
            {
                // Standard IExpando-over-IDispatchEx support appears to leak the variants it
                // creates for the invocation arguments. This issue has been reported. In the
                // meantime we'll bypass this facility and interface with IDispatchEx directly.

                result = dispatchEx.InvokeMethod(name, ignoreCase, args);
                return(true);
            }

            var flags = BindingFlags.Public;

            if (ignoreCase)
            {
                flags |= BindingFlags.IgnoreCase;
            }

            var method = target.GetMethod(name, flags);

            if (method != null)
            {
                result = method.Invoke(target, BindingFlags.InvokeMethod | flags, null, args, CultureInfo.InvariantCulture);
                return(true);
            }

            result = null;
            return(false);
        }
Ejemplo n.º 6
0
        internal virtual void TranslateToConditionalBranch(ILGenerator il, bool branchIfTrue, Label label, bool shortForm)
        {
            IReflect ir = this.InferType(null);

            if ((ir != Typeob.Object) && (ir is Type))
            {
                string     name = branchIfTrue ? "op_True" : "op_False";
                MethodInfo meth = ir.GetMethod(name, BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { (Type)ir }, null);
                if (meth != null)
                {
                    this.TranslateToIL(il, (Type)ir);
                    il.Emit(OpCodes.Call, meth);
                    il.Emit(OpCodes.Brtrue, label);
                    return;
                }
            }
            Type rtype = Microsoft.JScript.Convert.ToType(ir);

            this.TranslateToIL(il, rtype);
            Microsoft.JScript.Convert.Emit(this, il, rtype, Typeob.Boolean, true);
            if (branchIfTrue)
            {
                il.Emit(shortForm ? OpCodes.Brtrue_S : OpCodes.Brtrue, label);
            }
            else
            {
                il.Emit(shortForm ? OpCodes.Brfalse_S : OpCodes.Brfalse, label);
            }
        }
Ejemplo n.º 7
0
        internal virtual void TranslateToConditionalBranch(ILGenerator il, bool branchIfTrue, Label label, bool shortForm)
        {
            //This method is overridden in all interesting cases.
            IReflect ir = this.InferType(null);

            if (ir != Typeob.Object && ir is Type)
            {
                String     op   = branchIfTrue ? "op_True" : "op_False";
                MethodInfo meth = ir.GetMethod(op, BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { (Type)ir }, null);
                if (meth != null)
                {
                    this.TranslateToIL(il, (Type)ir);
                    il.Emit(OpCodes.Call, meth);
                    il.Emit(OpCodes.Brtrue, label);
                    return;
                }
            }
            Type t = Convert.ToType(ir);

            this.TranslateToIL(il, t);
            Convert.Emit(this, il, t, Typeob.Boolean, true);
            if (branchIfTrue)
            {
                il.Emit(shortForm ? OpCodes.Brtrue_S : OpCodes.Brtrue, label);
            }
            else
            {
                il.Emit(shortForm ? OpCodes.Brfalse_S : OpCodes.Brfalse, label);
            }
        }
        private static MethodInfo GetCreateContainerMethod(IReflect type, string createContainerMethodName)
        {
            var createContainerMethod = type.GetMethod(createContainerMethodName, BindingFlags.Static | BindingFlags.Public)
                                        ?? throw new InvalidOperationException("Unable to access container creation method. Make sure it's static and public.");

            ValidateCreateContainerParameters(createContainerMethod);
            ValidateCreateContainerReturnType(createContainerMethod);
            return(createContainerMethod);
        }
        private static OperationFilterContext GetContext(IReflect controllerType, string methodName)
        {
            var methodInfo = controllerType.GetMethod(
                name: methodName,
                bindingAttr: BindingFlags.NonPublic | BindingFlags.Static);

            return(new OperationFilterContext(
                       apiDescription: new ApiDescription(),
                       schemaRegistry: default,
Ejemplo n.º 10
0
        private static MethodInfo GetMethodInfo(IReflect source, string methodName, BindingFlags bindingFlags)
        {
            Requires.NotDefault(bindingFlags, nameof(bindingFlags));

            var method = source.GetMethod(methodName, bindingFlags);

            Requires.NotNull(method, nameof(method));

            return(method !);
        }
        private static object GetEnumeration(IReflect enumerationType, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            int listItemValue;

            if (int.TryParse(value, out listItemValue))
            {
                var fromValueMethod = enumerationType.GetMethod("FromValue", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, new[] { typeof(int) }, null);
                return(fromValueMethod.Invoke(null, new object[] { listItemValue }));
            }

            var parseMethod = enumerationType.GetMethod("Parse", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, new[] { typeof(string) }, null);

            return(parseMethod.Invoke(null, new object[] { value }));
        }
Ejemplo n.º 12
0
        private static MethodInfo DeclaringMethod(MethodInfo method, IReflect declaringType)
        {
            var flags = Default;

            flags |= method.IsStatic ? Static : Instance;
            flags |= method.IsPublic ? Public : NonPublic;
            var parameters = method.GetParameters().Select(_ => _.ParameterType).ToArray();

            return(declaringType.GetMethod(method.Name, flags, null, parameters, null) ?? method);
        }
Ejemplo n.º 13
0
 private static MethodInfo GetImplicitOperatorInfo(IReflect type)
 {
     return(type.GetMethod(
                ImplicitOperatorMethodName,
                BindingFlags.Static | BindingFlags.Public,
                null,
                new [] { typeof(string) },
                new ParameterModifier[0]
                ));
 }
Ejemplo n.º 14
0
        private static MethodInfo GetGenericMethodInfo(IReflect source, string methodName, BindingFlags bindingFlags, Type[] types)
        {
            Requires.NotDefault(bindingFlags, nameof(bindingFlags));

            var method = source.GetMethod(methodName, bindingFlags, new GenericMethodBinder(), types, null);

            Requires.NotNull(method, nameof(method));

            return(method !);
        }
Ejemplo n.º 15
0
        static Func <string, object> Bind(IReflect factory)
        {
            var method = factory.GetMethod("GetGrain",
                                           BindingFlags.Public | BindingFlags.Static, null,
                                           new[] { typeof(long), typeof(string) }, null);

            var argument = Expression.Parameter(typeof(string), "ext");
            var call     = Expression.Call(method, new Expression[] { Expression.Constant(0L), argument });
            var lambda   = Expression.Lambda <Func <string, object> >(call, argument);

            return(lambda.Compile());
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CustomTask{T}" /> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentException">methodName;Fitting method with the given name was not found.</exception>
        public CustomTask(IReflect type, string methodName, params object[] args)
        {
            var methodInfo = type.GetMethod(methodName,
                                            BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static);

            if (methodInfo == null)
            {
                throw new ArgumentException("methodName", "Fitting method with the given name was not found.");
            }

            _function = t => (T)methodInfo.Invoke(null, args);
        }
Ejemplo n.º 17
0
        static  Func<string, object> Bind(IReflect factory)
        {
            var method = factory.GetMethod("GetGrain", 
                BindingFlags.Public | BindingFlags.Static, null, 
                new[]{typeof(long), typeof(string)}, null);

            var argument = Expression.Parameter(typeof(string), "ext");
            var call = Expression.Call(method, new Expression[]{Expression.Constant(0L), argument});
            var lambda = Expression.Lambda<Func<string, object>>(call, argument);

            return lambda.Compile();
        }
Ejemplo n.º 18
0
        private static object ExecMethod(IReflect sourceType, string metodo, object sourceMethod, object[] param, BindingFlags flags)
        {
            var m = sourceType.GetMethod(metodo, flags);

            if (m == null)
            {
                throw new ArgumentException(string.Format("Unknown methond '{0}' in type '{1}'.", metodo, sourceType));
            }

            var objRet = m.Invoke(sourceMethod, param);

            return(objRet);
        }
Ejemplo n.º 19
0
        public FunctionDetour(IReflect originalClassType, string originalFunctionName, IReflect targetClassType, string targetFunctionName)
        {
            // Ensure the arguments passed in are valid

            if (string.IsNullOrWhiteSpace(originalFunctionName))
            {
                throw new ArgumentException($"The parameter '{nameof(originalFunctionName)}' can't be null / empty or whitespace!");
            }

            if (string.IsNullOrWhiteSpace(targetFunctionName))
            {
                throw new ArgumentException($"The parameter '{nameof(targetFunctionName)}' can't be null / empty or whitespace!");
            }

            if (originalClassType == null)
            {
                throw new ArgumentNullException($"The parameter '{nameof(originalClassType)}' can't be null!");
            }

            if (targetClassType == null)
            {
                throw new ArgumentNullException($"The parameter '{nameof(targetClassType)}' can't be null!");
            }

            // Get the information about the original function

            var originalFunctionInfo = originalClassType.GetMethod(originalFunctionName, MethodBindingFlags);

            if (originalFunctionInfo == null)
            {
                throw new InvalidOperationException($"Could not find function '{originalFunctionName}' in class {originalClassType}!");
            }

            // Get the information about the target function

            var targetFunctionInfo = targetClassType.GetMethod(targetFunctionName, MethodBindingFlags);

            if (targetFunctionInfo == null)
            {
                throw new InvalidOperationException($"Could not find function '{targetFunctionName}' in class {targetClassType}!");
            }

            if (targetFunctionInfo.MethodImplementationFlags != MethodImplAttributes.NoInlining)
            {
                throw new InvalidOperationException($"The function {targetFunctionName} must be decorated with the NoInlining attribute.");
            }

            InitialiseDetour(originalFunctionInfo, targetFunctionInfo);
        }
Ejemplo n.º 20
0
 private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr){
   PropertyInfo property = reflect.GetProperty(name, bindingAttr);
   if (property != null){
     MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
     MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
     if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic)){
       MethodInfo method = reflect.GetMethod(name, bindingAttr);
       if (method != null && !method.IsStatic){
         MemberInfo[] propMethods = new MemberInfo[1];
         propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
         return propMethods;
       }
     }
   }
   MemberInfo[] members = reflect.GetMember(name, bindingAttr);
   if (members != null && members.Length > 0)
     return ScriptObject.WrapMembers(members, namedItem);
   return null;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// An instance capable of detouring a method to call another method
        /// </summary>
        public MethodDetour(IReflect originalClass, string originalMethod, IReflect targetClass, string targetMethod)
        {
            if (originalClass is null || string.IsNullOrWhiteSpace(originalMethod) || targetClass is null || string.IsNullOrWhiteSpace(targetMethod))
            {
                throw new ArgumentException("One or more the parameters was invalid");
            }

            const BindingFlags bindingFlags = BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            var originalMethodInfo = originalClass.GetMethod(originalMethod, bindingFlags) ?? throw new MissingMethodException($"Failed to find the method {originalMethod} in the class {nameof(originalClass)}");

            _originalMethodHandle = originalMethodInfo.MethodHandle;

            var targetMethodInfo = targetClass.GetMethod(targetMethod, bindingFlags) ?? throw new MissingMethodException($"Failed to find the method {targetMethod} in the class {nameof(targetClass)}");

            _targetMethodHandle = targetMethodInfo.MethodHandle;

            PrepareDetour();
        }
Ejemplo n.º 22
0
 private static object InvokeMethod(IReflect type, object instance, string methodName, object[] @params, BindingFlags flags)
 {
     try
     {
         var method = type.GetMethod(methodName, flags);
         if (method == null && instance != null)
         {
             method = instance.GetType().GetMethod(methodName, flags);
         }
         if (method == null)
         {
             throw new ArgumentException(string.Format("Type '{0}' does not have a method named '{1}'.", type, methodName));
         }
         return(method.Invoke(instance, @params));
     }
     catch (AmbiguousMatchException)
     {
         return(type.InvokeMember(methodName, flags | BindingFlags.InvokeMethod, null, instance, @params, null, null, null));
     }
 }
Ejemplo n.º 23
0
        private static bool TryInvokeMethod(IReflect target, string name, bool ignoreCase, object[] args, out object result)
        {
            var flags = BindingFlags.InvokeMethod | BindingFlags.Public;

            if (ignoreCase)
            {
                flags |= BindingFlags.IgnoreCase;
            }

            var method = target.GetMethod(name, flags);

            if (method != null)
            {
                result = method.Invoke(target, flags, null, args, CultureInfo.InvariantCulture);
                return(true);
            }

            result = null;
            return(false);
        }
            //Use the below line to print out the finished sorted string
            // Console.WriteLine(stringSorted);


            //Method for running sorting-method by algoName and printing out time and words/millisecond
            static int SortAndTime(string[] words, IReflect sortClassName)
            {
                //Finds the matching method name "Run" from the Class given as parameter sortClassName
                var sortMethod = sortClassName?.GetMethod("Run", BindingFlags.Static | BindingFlags.Public);

                //Start a stopwatch
                var watch = Stopwatch.StartNew();

                //Invoke the found sortingmethod (null because the class is static) with the string array as parameter (words)
                sortMethod?.Invoke(null, new object[] { words });

                //Stop stopwatch
                watch.Stop();


                Console.WriteLine($"Total time for {sortClassName} sorting the words is: {watch.ElapsedMilliseconds} milliseconds");

                var wordsPerMilisecond = (int)(words.Length / watch.ElapsedMilliseconds);

                Console.WriteLine($"The number of words per millisecond for {sortClassName} sorting the words is: {wordsPerMilisecond}");

                return(wordsPerMilisecond);
            }
 private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
 {
     PropertyInfo property = reflect.GetProperty(name, bindingAttr);
     if (property != null)
     {
         MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
         MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
         if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
         {
             MethodInfo method = reflect.GetMethod(name, bindingAttr);
             if ((method != null) && !method.IsStatic)
             {
                 return new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) };
             }
         }
     }
     MemberInfo[] member = reflect.GetMember(name, bindingAttr);
     if ((member != null) && (member.Length > 0))
     {
         return ScriptObject.WrapMembers(member, namedItem);
     }
     return null;
 }
Ejemplo n.º 26
0
 private static bool TryInvokeMethod(IReflect type, object instance, string methodName, object[] @params, BindingFlags flags, out object result)
 {
     try
     {
         var method = type.GetMethod(methodName, flags);
         if (method == null && instance != null)
         {
             method = instance.GetType().GetMethod(methodName, flags);
         }
         if (method == null)
         {
             result = default;
             return(false);
         }
         result = method.Invoke(instance, @params);
         return(true);
     }
     catch (AmbiguousMatchException)
     {
         result = type.InvokeMember(methodName, flags | BindingFlags.InvokeMethod, null, instance, @params, null, null, null);
         return(true);
     }
 }
Ejemplo n.º 27
0
        private static object GetMethodExtended(
            IReflect type,
            string name,
            bool staticMethod,
            int parameterCount)
        {
            var          haveMethodName = false;
            BindingFlags flags          = (staticMethod ? BindingFlags.Static :
                                           BindingFlags.Instance) | BindingFlags.Public |
                                          BindingFlags.NonPublic | BindingFlags.InvokeMethod;

            foreach (var method in type.GetMethods(flags))
            {
                if (method.Name.Equals(name))
                {
                    haveMethodName = true;
                    if (method.GetParameters().Length == parameterCount)
                    {
                        return(method);
                    }
                }
            }
            return(haveMethodName ? type.GetMethod(name, flags) : null);
        }
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if ((method != null) && !method.IsStatic)
                    {
                        return(new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) });
                    }
                }
            }
            MemberInfo[] member = reflect.GetMember(name, bindingAttr);
            if ((member != null) && (member.Length > 0))
            {
                return(ScriptObject.WrapMembers(member, namedItem));
            }
            return(null);
        }
Ejemplo n.º 29
0
 private static IEnumerable<Type> GetRegisteredEvents(IReflect proxyType, object proxy)
 {
     return (IEnumerable<Type>)proxyType
                                   .GetMethod("RegisteredEvents", BindingFlags.Instance | BindingFlags.NonPublic)
                                   .Invoke(proxy, new object[] { });
 }
Ejemplo n.º 30
0
 System.Reflection.MethodInfo IReflect.GetMethod(string name, System.Reflection.BindingFlags bindingAttr)
 {
     return(typeIReflectImplementation.GetMethod(name, bindingAttr));
 }
Ejemplo n.º 31
0
 MethodInfo?IReflect.GetMethod(string name, BindingFlags bindingAttr, Binder?binder, Type[] types, ParameterModifier[]?modifiers)
 => publicIReflect.GetMethod(name, bindingAttr, binder, types, modifiers);
Ejemplo n.º 32
0
 private static MethodInfo GetMethod(string funcName, IReflect type)
 {
     return(type.GetMethod(funcName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
 }
Ejemplo n.º 33
0
 public static MethodInfo GetMethodFromTypeAndMethodName(this IReflect type, string methodName)
 {
     return(type.GetMethod(methodName,
                           BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
 }
Ejemplo n.º 34
0
        MethodInfo IReflect.GetMethod(string name, BindingFlags bindingAttr)
        {
            var ret = typeIReflectImplementation.GetMethod(name, bindingAttr);

            return(ret);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Runs the method.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="strMethod">The STR method.</param>
        /// <param name="objInstance">The obj instance.</param>
        /// <param name="objParams">The obj params.</param>
        /// <param name="eFlags">The e flags.</param>
        /// <returns></returns>
        private static object RunMethod(IReflect type, string strMethod, object objInstance, object [] objParams, BindingFlags eFlags)
        {
            MethodInfo method;
            try
            {
                if ((eFlags == InstanceBindingFlags) && (objInstance == null))
                {
                    throw new ArgumentException("The reflection non-static object argument was invalid");
                }
                if ((eFlags == StaticBindingFlags) && (objInstance != null))
                {
                    throw new ArgumentException("The reflection static object argument was invalid");
                }

                if ((objInstance != null) && (objInstance.GetType() != (Type)type) && (objInstance.GetType().BaseType != (Type)type))
                {
                    throw new ArgumentException("The object instance was of type '" + objInstance.GetType() + "' for type '" + type + "'.");
                }
                if (string.IsNullOrEmpty(strMethod))
                {
                    throw new ArgumentException("The reflection method argument was invalid");
                }
                method = type.GetMethod(strMethod, eFlags);
                if (method == null)
                {
                    throw new ArgumentException("There is no method '" + strMethod + "' for type '" + type + "'.");
                }

                var objRet = method.Invoke(objInstance, objParams);
                return objRet;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                throw;
            }
        }
Ejemplo n.º 36
0
       private static object GetMethodExtended(
 IReflect type,
 string name,
 bool staticMethod,
 int parameterCount)
       {
           var haveMethodName = false;
             BindingFlags flags = (staticMethod ? BindingFlags.Static :
           BindingFlags.Instance) | BindingFlags.Public |
           BindingFlags.NonPublic | BindingFlags.InvokeMethod;
             foreach (var method in type.GetMethods(flags)) {
           if (method.Name.Equals(name)) {
             haveMethodName = true;
             if (method.GetParameters().Length == parameterCount) {
           return method;
             }
           }
             }
             return haveMethodName ? type.GetMethod(name, flags) : null;
       }