当前位置: 首页>>代码示例>>C#>>正文


C# MethodBase.Invoke方法代码示例

本文整理汇总了C#中System.Reflection.MethodBase.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.Invoke方法的具体用法?C# MethodBase.Invoke怎么用?C# MethodBase.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodBase的用法示例。


在下文中一共展示了MethodBase.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTest

        private static TestResult RunTest(object instance, MethodBase method)
        {
            var result = new TestResult { Name = method.Name };

            var sw = new Stopwatch();
            sw.Start();
            try
            {
                method.Invoke(instance, null);
                result.WasSuccessful = true;
            }
            catch (Exception ex)
            {
                result.WasSuccessful = false;
                result.Message = ex.ToString();
            }
            finally
            {
                sw.Stop();

                result.Duration = sw.ElapsedMilliseconds;
            }

            return result;
        }
开发者ID:hbidadi,项目名称:UnitTestsForDiagnosticsEndpoints,代码行数:25,代码来源:DiagnosticsController.cs

示例2: Create

        private ServiceEntry Create(string serviceId, MethodBase implementationMethod)
        {
            var type = implementationMethod.DeclaringType;

            return new ServiceEntry
            {
                Descriptor = new ServiceDescriptor
                {
                    Id = serviceId
                },
                Func = parameters =>
                {
                    var instance = _serviceFactory.Create(type);

                    var list = new List<object>();
                    foreach (var parameterInfo in implementationMethod.GetParameters())
                    {
                        var value = parameters[parameterInfo.Name];
                        var parameterType = parameterInfo.ParameterType;

                        var parameter = _typeConvertibleService.Convert(value, parameterType);
                        list.Add(parameter);
                    }

                    var result = implementationMethod.Invoke(instance, list.ToArray());

                    return result;
                }
            };
        }
开发者ID:cjt908,项目名称:Rpc,代码行数:30,代码来源:ClrServiceEntryFactory.cs

示例3: ExecutePrivate

        private void ExecutePrivate(MethodBase entryPoint, IEnumerable<string> additionalReferences)
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => CurrentDomainOnAssemblyResolve(args.Name, additionalReferences);

            Environment.SetEnvironmentVariable("CSharpRunner_ArtifactsPath", artifactsPath);

            entryPoint.Invoke(entryPoint.DeclaringType, null);
        }
开发者ID:Tdue21,项目名称:teamcitycsharprunner,代码行数:8,代码来源:Executor.cs

示例4: callAsync

        public Task<object> callAsync(MethodBase method, object[] args)
        {
            Func<object> work = () =>
            {
                return method.Invoke(target, UnwrapArgs(method, args));
            };

            if (queue != null)
                return Task.Factory.StartNew<object>(work, new System.Threading.CancellationToken(false), TaskCreationOptions.None, queue);
            else
                return Task.FromResult<object>(work.Invoke());
        }
开发者ID:nodekit-io,项目名称:nodekit-windows,代码行数:12,代码来源:NKScriptInvocation.cs

示例5: call

        public object call(MethodBase method, object[] args)
        {
            Func<object> work = () =>
            {
                return method.Invoke(target, UnwrapArgs(method, args));
            };

            if (queue != null)
            {
                var t = Task.Factory.StartNew<object>(work, new System.Threading.CancellationToken(false), TaskCreationOptions.None, queue);
                t.Wait();
                return t.Result;
            }
            else
                return work.Invoke();
        }
开发者ID:nodekit-io,项目名称:nodekit-windows,代码行数:16,代码来源:NKScriptInvocation.cs

示例6: FastCall

 private static object FastCall(object o, MethodBase method, ParameterInfo[] Parameters, object[] args, Type objType, IReflect objIReflect)
 {
     int upperBound = args.GetUpperBound(0);
     for (int i = 0; i <= upperBound; i++)
     {
         ParameterInfo info = Parameters[i];
         object defaultValue = args[i];
         if ((defaultValue is Missing) && info.IsOptional)
         {
             defaultValue = info.DefaultValue;
         }
         args[i] = ObjectType.CTypeHelper(defaultValue, info.ParameterType);
     }
     VBBinder.SecurityCheckForLateboundCalls(method, objType, objIReflect);
     if (((objType != objIReflect) && !method.IsStatic) && !DoesTargetObjectMatch(o, method))
     {
         return InvokeMemberOnIReflect(objIReflect, method, BindingFlags.InvokeMethod, o, args);
     }
     VerifyObjRefPresentForInstanceCall(o, method);
     return method.Invoke(o, args);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:LateBinding.cs

示例7: HandleVirtualMethods

        private object HandleVirtualMethods(MethodBase method, object[] args) {
            var methodName = method.Name;

            // Handle properties if they are CMS properties
            if (methodName.StartsWith("get_")) {
                bool propertyExists;
                var currentPage = (CmsPage)_target;
                var propertyName = methodName.Substring(4);
                var propertyData = currentPage.Property.GetPropertyValue(propertyName, out propertyExists);

                if (propertyExists) {
                    return GetPropertyValue(method, propertyData);
                }
            }

            // Handle everything else that isn't a CMS property
            try {
                return method.Invoke(_target, args);
            }
            catch (Exception exception) {
                throw GetExceptionToRethrow(exception);
            }
        }
开发者ID:KalikoCMS,项目名称:KalikoCMS.Core,代码行数:23,代码来源:PageProxy.cs

示例8: RunTest

        public void RunTest(MethodBase method)
        {
            try
            {
                LogTestCaseStart(method.Name);
                teststarted = true;
                method.Invoke(this, null);
                LogTestCasePassed(method.Name);

            }

            catch (TargetInvocationException aex)
            {
                Logger.RecordMessage(aex.InnerException.Message, MessageType.Exception, MessageSeverity.Error);
                LogTestCaseFailed(method.Name);

                throw aex.InnerException;
            }
            finally
            {
                teststarted = false;
            }
        }
开发者ID:fudder,项目名称:cs493,代码行数:23,代码来源:SOAPTestBase.cs

示例9: InvokeAndUnwrapException

		protected static object InvokeAndUnwrapException(MethodBase mb, object obj, object[] args)
		{
#if FIRST_PASS
			return null;
#else
			try
			{
				return mb.Invoke(obj, args);
			}
			catch (TargetInvocationException x)
			{
				throw ikvm.runtime.Util.mapException(x.InnerException);
			}
#endif
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:15,代码来源:MemberWrapper.cs

示例10: InvokeMethodWithoutTargetInvocationException

        public static object InvokeMethodWithoutTargetInvocationException(MethodBase method, object obj, object[] args)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            try
            {
                return method.Invoke(obj, args);
            }
            catch (TargetInvocationException ex)
            {
                RethrowWithNoStackTraceLoss(ex.InnerException);
                throw;
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:15,代码来源:ExceptionUtils.cs

示例11: CompileTimeValidate

        ///<summary>
        /// Validate the aspect usage
        ///</summary>
        ///<param name="method">The method that the aspect is applied on</param>
        ///<returns>Returns true if all checks pass</returns>
        public override bool CompileTimeValidate(MethodBase method)
        {
            if (method == null)
            {
                this.RaiseError(1, "The PostCompile aspect can only be applied on methods.", method.AsSignature());

                return false;
            }

            if (!method.IsStatic)
            {
                this.RaiseError(2, "The PostCompile aspect can only be applied on static methods.", method.AsSignature());

                return false;
            }

            if (method.GetParameters().Length > 0)
            {
                this.RaiseError(3, "The PostCompile aspect can only be applied on methods without arguments.", method.AsSignature());

                return false;
            }

            if (method as MethodInfo == null)
            {
                this.RaiseError(4, "The PostCompile aspect can not be applied on constructor/deconstructors", method.AsSignature());

                return false;
            }

            if (((MethodInfo)method).ReturnType != typeof(void))
            {
                this.RaiseError(5, "The PostCompile aspect can only be applied on methods returning nothing.", method.AsSignature());

                return false;
            }

            this.Describe("On compilation, this method will be invoked", method);

            try
            {
                method.Invoke(null, null);
                this.Describe("Last post-compile run succeeded at {0}".F(DateTime.Now), method);
            }
            catch (TargetInvocationException ex) // when this exception is thrown, consider it a success, and optionally check if it has more descriptions to add
            {
                if (ex.InnerException is PostCompileSuccessException)
                {
                    this.Describe("Last post-compile run succeeded at {0}".F(DateTime.Now), method);

                    foreach (var d in (ex.InnerException as PostCompileSuccessException).Descriptions)
                    {
                        this.Describe(d, method);
                    }
                }
                else
                {
                    this.Describe("Last post-compile run failed at {0}".F(DateTime.Now), method);
                    this.Describe(ex.ToString(), method);
                }
            }
            catch (Exception ex)
            {
                this.Describe("Last post-compile run failed at {0}".F(DateTime.Now), method);
                this.Describe(ex.ToString(), method);
            }

            return true;
        }
开发者ID:mylemans,项目名称:PostSharpAspects,代码行数:74,代码来源:PostCompileAttribute.cs

示例12: Intercept

        /// <summary>
        /// Intercepts the <see cref="MethodBase"/> in the proxy to return a replaced value.
        /// </summary>
        /// <param name="methodBase">
        /// The <see cref="MethodBase"/> containing information about the current
        /// invoked property.
        /// </param>
        /// <param name="value">
        /// The object to set the <see cref="MethodBase"/> to if it is a setter.
        /// </param>
        /// <returns>
        /// The <see cref="object"/> replacing the original implementation value.
        /// </returns>
        public object Intercept(MethodBase methodBase, object value)
        {
            const string Getter = "get_";
            const string Setter = "set_";
            var name = methodBase.Name;
            var key = name.Substring(4);
            var parameters = value == null ? new object[] { } : new[] { value };

            // Attempt to get the value from the lazy members.
            if (name.StartsWith(Getter))
            {
                if (this.lazyDictionary.ContainsKey(key))
                {
                    return this.lazyDictionary[key].Value;
                }
            }

            // Set the value, remove the old lazy value.
            if (name.StartsWith(Setter))
            {
                if (this.lazyDictionary.ContainsKey(key))
                {
                    this.lazyDictionary.Remove(key);
                }
            }

            return methodBase.Invoke(this.target, parameters);
        }
开发者ID:robertjf,项目名称:umbraco-ditto,代码行数:41,代码来源:LazyInterceptor.cs

示例13: NonOwnerInvocationHandler

        private object NonOwnerInvocationHandler(object target, MethodBase method, object[] parameters)
        {
            object result = null;

            try
            {
                if(method.Name.Equals("set_HotOrNot"))
                {
                    result = method.Invoke(target, parameters);
                }
                else
                {
                    throw new UnauthorizedAccessException("You are not permitted to update another's personal information!");
                }
            }
            catch(ApplicationException ex)
            {
                return ex.StackTrace;
            }

            return result;
        }
开发者ID:alannet,项目名称:example,代码行数:22,代码来源:ProxyDynamicNetFixture.cs

示例14: InvokeSetupMethod

 private void InvokeSetupMethod(MethodBase method)
 {
     if (method == null) return;
     try
     {
         method.Invoke(_testInstance, new Object[0]);
     }
     catch
     {
         Debug.LogError(string.Format("[{2}] {0}.{1}", _testType, method.Name, "FAIL"));
     }
 }
开发者ID:nikmarkovic,项目名称:mugd-module-test-unit,代码行数:12,代码来源:TestRunner.cs

示例15: Rewrite

        public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
        {
            Type returnType;
            if (callee.ReturnsSomething(out returnType))
                throw new ArgumentException("The IgnoreOnDecompilation attribute may only be applied to methods returning a void result. Use StaticEvaluation instead.");

            if (_call)
            {
                callee.Invoke(args.Select(a => a.Sample).ToArray());
            }

            return true;
        }
开发者ID:venusdharan,项目名称:systemsharp,代码行数:13,代码来源:ComponentsAttributes.cs


注:本文中的System.Reflection.MethodBase.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。