當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。