當前位置: 首頁>>代碼示例>>C#>>正文


C# Expression.GetMethodName方法代碼示例

本文整理匯總了C#中System.Linq.Expressions.Expression.GetMethodName方法的典型用法代碼示例。如果您正苦於以下問題:C# Expression.GetMethodName方法的具體用法?C# Expression.GetMethodName怎麽用?C# Expression.GetMethodName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Linq.Expressions.Expression的用法示例。


在下文中一共展示了Expression.GetMethodName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Invoke

        public void Invoke(IRibbonControl control, Expression<Action> caller, params object[] parameters)
        {
            try
            {
                CallbackTarget callbackTarget =
                    vstoContribContext.TagToCallbackTargetLookup[control.Tag + caller.GetMethodName()];

                IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(control.Context);

                Type type = viewModelInstance.GetType();
                PropertyInfo property = type.GetProperty(callbackTarget.Method);

                if (property != null)
                {
                    type.InvokeMember(callbackTarget.Method,
                        BindingFlags.SetProperty,
                        null,
                        viewModelInstance,
                        new[]
                        {
                            parameters.Single()
                        });
                }
                else
                {
                    type.InvokeMember(callbackTarget.Method,
                        BindingFlags.InvokeMethod,
                        null,
                        viewModelInstance,
                        new[]
                        {
                            control
                        }
                            .Concat(parameters)
                            .ToArray());
                }
            }
            catch (TargetInvocationException e)
            {
                var innerEx = e.InnerException;
                PreserveStackTrace(innerEx);
                if (vstoContribContext.ErrorHandlers.Count == 0)
                {
                    Trace.TraceError(innerEx.ToString());
                }

                var handled = vstoContribContext.ErrorHandlers.Any(errorHandler => errorHandler.Handle(innerEx));

                if (!handled)
                    throw innerEx;
            }
        }
開發者ID:huangchao-shanghai,項目名稱:VSTOContrib,代碼行數:52,代碼來源:RibbonFactoryController.cs

示例2: InvokeGetContent

        public string InvokeGetContent(IRibbonControl control, Expression<Action> caller, params object[] parameters)
        {
            // Remove any previous registered callbacks for this dynamic context
            vstoContribContext.RemoveCallbacksForDynamicContext(control.Tag);
            
            // Delegate to the view model to get the raw xml
            var xmlString = InvokeGet(control, caller, parameters);

            if (xmlString == null) return null;

            // Rewrite the XML with our callbacks, registering new callback targets
            var ribbonXmlRewriter = new RibbonXmlRewriter(vstoContribContext, ribbonViewModelResolver);
            var ribbonType = vstoContribContext.TagToCallbackTargetLookup[control.Tag + caller.GetMethodName()].RibbonType;
            return ribbonXmlRewriter.RewriteDynamicXml(ribbonType, control.Tag, xmlString.ToString());
        }
開發者ID:JoyPeterson,項目名稱:VSTOContrib,代碼行數:15,代碼來源:RibbonFactoryController.cs

示例3: InvokeGet

        public object InvokeGet(IRibbonControl control, Expression<Action> caller, params object[] parameters)
        {
            var methodName = caller.GetMethodName();
            CallbackTarget callbackTarget = vstoContribContext.TagToCallbackTargetLookup[control.Tag + methodName];

            var view = (object)control.Context;
            IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(view);
            VstoContribLog.Debug(l => l("Ribbon callback {0} being invoked on {1} (View: {2}, ViewModel: {3})",
                methodName, control.Id, view.ToLogFormat(), viewModelInstance.ToLogFormat()));

            Type type = viewModelInstance.GetType();
            PropertyInfo property = type.GetProperty(callbackTarget.Method);

            if (property != null)
            {
                return type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.GetProperty,
                                         null,
                                         viewModelInstance,
                                         null);
            }

            try
            {
                return type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.InvokeMethod,
                                         null,
                                         viewModelInstance,
                                         new[]
                                         {
                                             control
                                         }
                                             .Concat(parameters)
                                             .ToArray());
            }
            catch (MissingMethodException)
            {
                throw new InvalidOperationException(
                    string.Format("Expecting method with signature: {0}.{1}(IRibbonControl control)",
                                  type.Name,
                                  callbackTarget.Method));
            }
        }
開發者ID:JoyPeterson,項目名稱:VSTOContrib,代碼行數:43,代碼來源:RibbonFactoryController.cs

示例4: Invoke

        public void Invoke(IRibbonControl control, Expression<Action> caller, params object[] parameters)
        {
            try
            {
                var methodName = caller.GetMethodName();
                CallbackTarget callbackTarget =
                    vstoContribContext.TagToCallbackTargetLookup[control.Tag + methodName];

                var view = (object)control.Context;
                IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(view);
                VstoContribLog.Debug(l => l("Ribbon callback {0} being invoked on {1} (View: {2}, ViewModel: {3})",
                    methodName, control.Id, view.ToLogFormat(), viewModelInstance.ToLogFormat()));

                Type type = viewModelInstance.GetType();
                PropertyInfo property = type.GetProperty(callbackTarget.Method);

                if (property != null)
                {
                    type.InvokeMember(callbackTarget.Method,
                        BindingFlags.SetProperty,
                        null,
                        viewModelInstance,
                        new[]
                        {
                            parameters.Single()
                        });
                }
                else
                {
                    type.InvokeMember(callbackTarget.Method,
                        BindingFlags.InvokeMethod,
                        null,
                        viewModelInstance,
                        new[]
                        {
                            control
                        }
                            .Concat(parameters)
                            .ToArray());
                }
            }
            catch (TargetInvocationException e)
            {
                var innerEx = e.InnerException;
                PreserveStackTrace(innerEx);
                if (vstoContribContext.ErrorHandlers != null && vstoContribContext.ErrorHandlers.Count == 0)
                {
                    Trace.TraceError(innerEx.ToString());
                }

                var handled = vstoContribContext.ErrorHandlers != null && vstoContribContext.ErrorHandlers.Any(errorHandler => errorHandler.Handle(innerEx));

                if (!handled)
                    throw innerEx;
            }
        }
開發者ID:JoyPeterson,項目名稱:VSTOContrib,代碼行數:56,代碼來源:RibbonFactoryController.cs

示例5: InvokeGet

        public object InvokeGet(IRibbonControl control, Expression<Action> caller, params object[] parameters)
        {
            CallbackTarget callbackTarget = vstoContribContext.TagToCallbackTargetLookup[control.Tag + caller.GetMethodName()];

            IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(control.Context);

            Type type = viewModelInstance.GetType();
            PropertyInfo property = type.GetProperty(callbackTarget.Method);

            if (property != null)
            {
                return type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.GetProperty,
                                         null,
                                         viewModelInstance,
                                         null);
            }

            try
            {
                return type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.InvokeMethod,
                                         null,
                                         viewModelInstance,
                                         new[]
                                         {
                                             control
                                         }
                                             .Concat(parameters)
                                             .ToArray());
            }
            catch (MissingMethodException)
            {
                throw new InvalidOperationException(
                    string.Format("Expecting method with signature: {0}.{1}(IRibbonControl control)",
                                  type.Name,
                                  callbackTarget.Method));
            }
        }
開發者ID:huangchao-shanghai,項目名稱:VSTOContrib,代碼行數:39,代碼來源:RibbonFactoryController.cs


注:本文中的System.Linq.Expressions.Expression.GetMethodName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。