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


C# Delegate.GetMethodInfo方法代码示例

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


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

示例1: Create

        public static AsyncInvocationRegion Create(Delegate @delegate)
        {
#if PORTABLE
            return Create(@delegate.GetMethodInfo());
#else
            return Create(@delegate.Method);
#endif
        }
开发者ID:et1975,项目名称:nunit,代码行数:8,代码来源:AsyncInvocationRegion.cs

示例2: IsAsyncOperation

        public static bool IsAsyncOperation(Delegate @delegate)
        {
#if PORTABLE
            return IsAsyncOperation(@delegate.GetMethodInfo());
#else
            return IsAsyncOperation(@delegate.Method);
#endif
        }
开发者ID:et1975,项目名称:nunit,代码行数:8,代码来源:AsyncInvocationRegion.cs

示例3: ClearCore

        void IActionInvoker.ClearIfMatched(Delegate action, object recipient) {
            object target = Target;
            if(recipient != target)
                return;
#if !NETFX_CORE
            if(action != null && action.Method.Name != MethodName)
#else
            if(action != null && action.GetMethodInfo().Name != MethodName)
#endif
                return;
            targetReference = null;
            ClearCore();
        }
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:13,代码来源:ActionInvokerBase.cs

示例4: IsMatch

        /// <summary>
        /// Returns a value indicating whether the current weak delegate is a match (equivalent) for the specified strong delegate.
        /// </summary>
        /// <param name="strongDelegate">The <see cref="Delegate">delegate</see> to evaluate.</param>
        /// <returns>True if the current weak delegate is a match for the specified strong delegate; otherwise, false.</returns>
        public virtual bool IsMatch( Delegate strongDelegate )
        {
            if ( strongDelegate == null )
                return false;

            if ( !object.Equals( strongDelegate.Target, Target ) )
                return false;

            if ( !strongDelegate.GetMethodInfo().Equals( method ) )
                return false;

            return true;
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:18,代码来源:WeakDelegate.cs

示例5: ScriptUserdataDelegate

 public ScriptUserdataDelegate(Script script, Delegate value) : base(script) {
     this.m_Delegate = value;
     this.m_Value = value;
     this.m_ValueType = value.GetType();
     var method = m_Delegate.GetMethodInfo();
     var infos = method.GetParameters();
     var dynamicDelegate = method.Name.Equals(Script.DynamicDelegateName);
     int length = dynamicDelegate ? infos.Length - 1 : infos.Length;
     m_Objects = new object[length];
     for (int i = 0; i < length; ++i) {
         var p = infos[dynamicDelegate ? i + 1 : i];
         m_Parameters.Add(new FunctionParameter(p.ParameterType, p.DefaultValue));
     }
 }
开发者ID:qingfeng346,项目名称:Scorpio-CSharp,代码行数:14,代码来源:ScriptUserdataDelegate.cs

示例6: RegisterFunction

        public void RegisterFunction(string functionName, Delegate function, bool isOverWritable)
        {
            if (string.IsNullOrEmpty(functionName))
                throw new ArgumentNullException("functionName");

            if (function == null)
                throw new ArgumentNullException("function");

            Type funcType = function.GetType();

            if (!funcType.FullName.StartsWith("System.Func"))
                throw new ArgumentException("Only System.Func delegates are permitted.", "function");

            #if NETFX_CORE
            foreach (Type genericArgument in funcType.GenericTypeArguments)
            #else
            foreach (Type genericArgument in funcType.GetGenericArguments())
            #endif
                if (genericArgument != typeof(double))
                    throw new ArgumentException("Only doubles are supported as function arguments", "function");

            functionName = ConvertFunctionName(functionName);

            if (functions.ContainsKey(functionName) && !functions[functionName].IsOverWritable)
            {
                string message = string.Format("The function \"{0}\" cannot be overwriten.", functionName);
                throw new Exception(message);
            }

            #if NETFX_CORE
            int numberOfParameters = function.GetMethodInfo().GetParameters().Length;
            #else
            int numberOfParameters = function.Method.GetParameters().Length;
            #endif

            if (functions.ContainsKey(functionName) && functions[functionName].NumberOfParameters != numberOfParameters)
            {
                string message = string.Format("The number of parameters cannot be changed when overwriting a method.");
                throw new Exception(message);
            }

            FunctionInfo functionInfo = new FunctionInfo(functionName, numberOfParameters, isOverWritable, function);

            if (functions.ContainsKey(functionName))
                functions[functionName] = functionInfo;
            else
                functions.Add(functionName, functionInfo);
        }
开发者ID:CasperWollesen,项目名称:Jace,代码行数:48,代码来源:FunctionRegistry.cs

示例7: DelegateReference

        /// <summary>
        /// Initializes a new instance of <see cref="DelegateReference"/>.
        /// </summary>
        /// <param name="delegate">The original <see cref="Delegate"/> to create a reference for.</param>
        /// <param name="keepReferenceAlive">If <see langword="false" /> the class will create a weak reference to the delegate, allowing it to be garbage collected. Otherwise it will keep a strong reference to the target.</param>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="delegate"/> is not assignable to <see cref="Delegate"/>.</exception>
        public DelegateReference(Delegate @delegate, bool keepReferenceAlive)
        {
            if (@delegate == null)
                throw new ArgumentNullException("delegate");

            if (keepReferenceAlive)
            {
                this._delegate = @delegate;
            }
            else
            {
                _weakReference = new WeakReference(@delegate.Target);
                _method = @delegate.GetMethodInfo();
                _delegateType = @delegate.GetType();
            }
        }
开发者ID:No3x,项目名称:YAHW,代码行数:22,代码来源:DelegateReference.cs

示例8: SubscriberReference

        public SubscriberReference(Delegate action)
        {
            if (action == null)
                throw new ArgumentNullException("action");

            // If the delegates target is null, we can't hold a reference to it.
            // This happens when the callback method is static or a it has been 
            // created as a lambda/anonymous delegate that doesn't capture any 
            // instance variables. (Causes the compiler to generate a static method.)
            if (action.Target == null)
                throw new InvalidOperationException("Subscription with a static delegate method is not supported");

            _weakReference = new WeakReference(action.Target);
            _delegateType = action.GetType();
            _delegateMethod = action.GetMethodInfo();
        }
开发者ID:peter-h4nsen,项目名称:StockBuddy,代码行数:16,代码来源:SubscriberReference.cs

示例9: GetArguments

            private object[] GetArguments(Delegate valueFactory) {
                object[] arguments = new object[valueFactory.GetMethodInfo().GetParameters().Length];

                IEnumerable<ImportDefinition> ctorImportDefinitions = ImportDefinitions.Where(ReflectionModelServices.IsImportingParameter);
                foreach (ImportDefinition ctorImportDefinition in ctorImportDefinitions) {
                    ParameterInfo parameterInfo = ReflectionModelServices.GetImportingParameter(ctorImportDefinition).Value;
                    IEnumerable<Export> value;
                    if (_imports.TryGetValue(ctorImportDefinition, out value)) {
                        arguments[parameterInfo.Position] = value.Single().Value;
                        _imports.Remove(ctorImportDefinition);
                    } else {
                        throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "There is no export for parameter of type {0}",
                            parameterInfo.ParameterType));
                    }
                }

                return arguments;
            }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:18,代码来源:CompositionBatchExtensions.FactoryReflectionComposablePart.cs

示例10: InternalWeakDelegate

        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="InternalWeakDelegate"/> class.
        /// </summary>
        /// <param name="delegate">
        /// The original <see cref="System.Delegate"/> to create a weak reference for.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="delegate"/> is <see langword="null"/>.
        /// </exception>
        public InternalWeakDelegate(Delegate @delegate)
        {
            if (@delegate == null)
            throw new ArgumentNullException("delegate");

              object target = @delegate.Target;
              TargetReference = (target != null) ? new WeakReference(target) : null;
            #if !NETFX_CORE && !NET45
              MethodInfo = @delegate.Method;
            #else
              MethodInfo = @delegate.GetMethodInfo();
            #endif

              DelegateType = @delegate.GetType();

              Debug.Assert(
            (TargetReference != null && !MethodInfo.IsStatic)
            || (TargetReference == null && MethodInfo.IsStatic),
            "Sanity check.");

              CheckForClosure(MethodInfo);
              CheckForNonPublicEventHandler(target, MethodInfo);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:33,代码来源:InternalWeakDelegate.cs

示例11: GetMethod

 private static MethodInfo GetMethod(Delegate x)
 {
     return x.GetMethodInfo();
 }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:4,代码来源:AstMethods.cs

示例12: appendEventHandler

 private void appendEventHandler(StringBuilder sb, String name, Delegate eh)
 {
     if (eh != null)
         sb.AppendFormat("{0}={1};", name, eh.GetMethodInfo().Name);
     else
         sb.AppendFormat("{0}=null;", name);
 }
开发者ID:nats-io,项目名称:csnats,代码行数:7,代码来源:Options.cs

示例13: WeakDelegate

 /// <summary>
 /// Initializes a new instance of <see cref="WeakDelegate"/>
 /// </summary>
 /// <param name="delegate"></param>
 public WeakDelegate(Delegate @delegate)
 {
     _target = new WeakReference(@delegate.Target);
     _method = @delegate.GetMethodInfo();
 }
开发者ID:msdevno,项目名称:UWPWorkshop,代码行数:9,代码来源:WeakDelegate.cs

示例14: FromDelegate

		/// <summary>
		/// Creates a CallbackFunction from a delegate.
		/// </summary>
		/// <param name="script">The script.</param>
		/// <param name="del">The delegate.</param>
		/// <param name="accessMode">The access mode.</param>
		/// <returns></returns>
		public static CallbackFunction FromDelegate(Script script, Delegate del, InteropAccessMode accessMode = InteropAccessMode.Default)
		{
			if (accessMode == InteropAccessMode.Default)
				accessMode = m_DefaultAccessMode;

#if NETFX_CORE
			MethodMemberDescriptor descr = new MethodMemberDescriptor(del.GetMethodInfo(), accessMode);
#else
			MethodMemberDescriptor descr = new MethodMemberDescriptor(del.Method, accessMode);
#endif
			return descr.GetCallbackFunction(script, del.Target);
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:19,代码来源:CallbackFunction.cs

示例15: CallDelegate

        /*!*/
        internal static MSA.Expression CallDelegate(Delegate/*!*/ method, MSA.Expression[]/*!*/ arguments)
        {
            MethodInfo methodInfo = method.GetMethodInfo();

            // We prefer to peek inside the delegate and call the target method directly. However, we need to
            // exclude DynamicMethods since Delegate.Method returns a dummy MethodInfo, and we cannot emit a call to it.
            if (methodInfo.DeclaringType == null || !methodInfo.DeclaringType.IsPublic() || !methodInfo.IsPublic) {
                // do not inline:
                return Ast.Call(AstUtils.Constant(method), method.GetType().GetMethod("Invoke"), arguments);
            }

            if (method.Target != null) {
                // inline a closed static delegate:
                if (methodInfo.IsStatic) {
                    return Ast.Call(null, method.GetMethodInfo(), ArrayUtils.Insert(AstUtils.Constant(method.Target), arguments));
                }

                // inline a closed instance delegate:
                return Ast.Call(AstUtils.Constant(method.Target), methodInfo, arguments);
            }

            // inline an open static delegate:
            if (methodInfo.IsStatic) {
                return Ast.Call(null, methodInfo, arguments);
            }

            // inline an open instance delegate:
            return Ast.Call(arguments[0], methodInfo, ArrayUtils.RemoveFirst(arguments));
        }
开发者ID:TerabyteX,项目名称:main,代码行数:30,代码来源:AstFactory.cs


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