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


C# Delegate.GetType方法代碼示例

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


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

示例1: Transcribe

        public static Delegate Transcribe(Type sourceEventHandlerType, Delegate destinationEventHandler)
        {
            if (destinationEventHandler == null)
                throw new ArgumentNullException("destinationEventHandler");
            if (destinationEventHandler.GetType() == sourceEventHandlerType)
                return destinationEventHandler; // already OK

            var sourceArgs = VerifyStandardEventHandler(sourceEventHandlerType);
            var destinationArgs = VerifyStandardEventHandler(destinationEventHandler.GetType());
            var name = "_wrap" + Interlocked.Increment(ref methodIndex);
            var paramTypes = new Type[sourceArgs.Length + 1];

            paramTypes[0] = destinationEventHandler.GetType();
            for (int i = 0; i < sourceArgs.Length; i++)
            {
                paramTypes[i + 1] = sourceArgs[i].ParameterType;
            }

            var dynamicMethod = new DynamicMethod(name, null, paramTypes);
            var invoker = paramTypes[0].GetMethod("Invoke");
            var ilGenerator = dynamicMethod.GetILGenerator();
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.Emit(OpCodes.Ldarg_2);

            if (!destinationArgs[1].ParameterType.IsAssignableFrom(sourceArgs[1].ParameterType))
            {
                ilGenerator.Emit(OpCodes.Castclass, destinationArgs[1].ParameterType);
            }
            ilGenerator.Emit(OpCodes.Call, invoker);
            ilGenerator.Emit(OpCodes.Ret);

            return dynamicMethod.CreateDelegate(sourceEventHandlerType, destinationEventHandler);
        }
開發者ID:kkalinowski,項目名稱:lib12,代碼行數:34,代碼來源:EventHandlerTranscriber.cs

示例2: DelegateEntry

			public DelegateEntry delegateEntry; // next delegate in the invocation list

			// A DelegateEntry holds information about a delegate that is part
			// of an invocation list of a multicast delegate.
			public DelegateEntry (Delegate del, string targetLabel)
			{
				type = del.GetType().FullName;
				assembly = del.GetType().Assembly.FullName;
				target = targetLabel;
				targetTypeAssembly = del.Method.DeclaringType.Assembly.FullName;
				targetTypeName = del.Method.DeclaringType.FullName;
				methodName = del.Method.Name;
			}
開發者ID:GirlD,項目名稱:mono,代碼行數:13,代碼來源:DelegateSerializationHolder.cs

示例3: OnListenerAdding

        static public void OnListenerAdding(string eventType, Delegate listenerBeingAdded)
        {
            if (!eventTable.ContainsKey(eventType))
            {
                eventTable.Add(eventType, null);
            }

            Delegate d = eventTable[eventType];
            if (d != null && d.GetType() != listenerBeingAdded.GetType())
            {
                throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
            }
        }
開發者ID:azanium,項目名稱:Klumbi-Unity,代碼行數:13,代碼來源:Messenger.cs

示例4: MakeFuncCaller

		public static Func<object[], Delegate, object> MakeFuncCaller(Delegate delg)
		{
			var argsParam = Expression.Parameter(typeof(object[]));
			var delegateParam = Expression.Parameter(typeof(Delegate));

			var invoke = delg.GetType().GetMethod("Invoke");
			var hasReturn = invoke.ReturnType != typeof(void);
			var locals = invoke.GetParameters().Select(
				p => Expression.Variable(p.ParameterType.IsByRef ? p.ParameterType.GetElementType() : p.ParameterType))
				.ToArray();
			var assignments = Expression.Block(
				invoke.GetParameters().Select((p, i) =>
					Expression.Assign(
						locals[i],
						Expression.Convert(
							Expression.ArrayIndex(argsParam, Expression.Constant(i)), locals[i].Type)))
					.Concat(new Expression[] { Expression.Empty() }));

			Expression call = Expression.Call(
				Expression.Convert(delegateParam, delg.GetType()),
				invoke, locals);
			var resultVar = hasReturn
				? (Expression)Expression.Variable(invoke.ReturnType)
				: Expression.Constant(null, typeof(object));
			if (hasReturn)
				call = Expression.Assign(resultVar, call);

			var byrefAssignments = Expression.Block(
				invoke.GetParameters()
				.Select((p, i) => new { Type = p.ParameterType, Index = i })
				.Where(data => data.Type.IsByRef)
				.Select(data => Expression.Assign(
					Expression.ArrayAccess(argsParam, Expression.Constant(data.Index)),
					Expression.Convert(locals[data.Index], typeof(object))))
				.Concat(new Expression[] { Expression.Empty() })
				.ToArray());

			var callerBlock = Expression.Block(locals,
				assignments,
				call,
				byrefAssignments,
				Expression.Convert(resultVar, typeof(object)));

			if (hasReturn)
				callerBlock = Expression.Block(new[] { (ParameterExpression)resultVar }, callerBlock);

			var callerLambda = Expression.Lambda<Func<object[], Delegate, object>>(callerBlock, argsParam, delegateParam);
			return callerLambda.Compile();
		}
開發者ID:ArthurYiL,項目名稱:JustMockLite,代碼行數:49,代碼來源:MockingUtil.CodeGen.cs

示例5: CreateDelegate

        public static Delegate CreateDelegate(Delegate dlg)
        {
            if (dlg == null)
                throw new ArgumentNullException ();
            if (dlg.Target != null)
                throw new ArgumentException ();
            if (dlg.Method == null)
                throw new ArgumentException ();

            get_runtime_types ();

            var ret_type = dlg.Method.ReturnType;
            var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();

            var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
            var ig = dynamic.GetILGenerator ();

            LocalBuilder retval = null;
            if (ret_type != typeof (void))
                retval = ig.DeclareLocal (ret_type);

            ig.Emit (OpCodes.Call, wait_for_bridge_processing_method);

            var label = ig.BeginExceptionBlock ();

            for (int i = 0; i < param_types.Length; i++)
                ig.Emit (OpCodes.Ldarg, i);
            ig.Emit (OpCodes.Call, dlg.Method);

            if (retval != null)
                ig.Emit (OpCodes.Stloc, retval);

            ig.Emit (OpCodes.Leave, label);

            bool  filter = Debugger.IsAttached || !JNIEnv.PropagateExceptions;
            if (filter) {
                ig.BeginExceptFilterBlock ();

                ig.Emit (OpCodes.Call, mono_unhandled_exception_method);
                ig.Emit (OpCodes.Ldc_I4_1);
                ig.BeginCatchBlock (null);
            } else {
                ig.BeginCatchBlock (typeof (Exception));
            }

            ig.Emit (OpCodes.Dup);
            ig.Emit (OpCodes.Call, exception_handler_method);

            if (filter)
                ig.Emit (OpCodes.Throw);

            ig.EndExceptionBlock ();

            if (retval != null)
                ig.Emit (OpCodes.Ldloc, retval);

            ig.Emit (OpCodes.Ret);

            return dynamic.CreateDelegate (dlg.GetType ());
        }
開發者ID:yudhitech,項目名稱:xamarin-android,代碼行數:60,代碼來源:JNINativeWrapper.cs

示例6: WeakDelegate

		public WeakDelegate(Delegate callback)
            : base(callback.Target)
        {
            methodname = callback.Method.Name;
            type = callback.GetType();
            rm = new ResourceManager("Strings", Assembly.GetExecutingAssembly());
        }
開發者ID:ahaha0807,項目名稱:num_banda,代碼行數:7,代碼來源:HidReader.cs

示例7: Unsubscribe

		void IEventDispatcher.Unsubscribe(Delegate receiver)
		{
			if (receiver is Action)
				Unsubscribe((Action)receiver);
			else
				throw new ArgumentException(string.Format("Type {0} doesn't match event type {1}. Make sure that all subscribers have the same signature.", receiver.GetType().Name, Event.GetType().Name));
		}
開發者ID:Magicolo,項目名稱:PseudoFramework,代碼行數:7,代碼來源:EventDispatcher.cs

示例8: IsLegalHandler

        // Check to see if the given delegate is a legal handler for this type.
        //  It either needs to be a type that the registering class knows how to
        //  handle, or a RoutedEventHandler which we can handle without the help
        //  of the registering class.
        internal bool IsLegalHandler(Delegate handler)
        {
            Type handlerType = handler.GetType();

            return ((handlerType == HandlerType) ||
                (handlerType == typeof(RoutedEventHandler)));
        }
開發者ID:prabby,項目名稱:miniclr,代碼行數:11,代碼來源:RoutedEvent.cs

示例9: AddHandler

        /// <summary>
        /// Adds a class handler to the manager.
        /// </summary>
        /// <param name="classType">The type for which the handler is defined; must be a supertype of the manager's owner type.</param>
        /// <param name="handler">A delegate which represents the class handler to add to the type.</param>
        /// <param name="handledEventsToo">A value indicating whether the handler should receive events which have already been handled by other handlers.</param>
        public void AddHandler(Type classType, Delegate handler, Boolean handledEventsToo)
        {
            if (classType != this.ownerType && !this.ownerType.IsSubclassOf(classType))
                throw new ArgumentException(PresentationStrings.ClassTypeMustBeSubclassOfOwnerType.Format(classType.Name, ownerType.Name));

            if (routedEvent.DelegateType != handler.GetType())
                throw new ArgumentException(PresentationStrings.HandlerTypeMismatch.Format(handler.Method.Name, routedEvent.DelegateType.Name), "handler");

            lock (handlers)
            {
                var ordinalByType     = (short)0;
                var ordinalWithinType = ordinal++;

                var currentType = this.ownerType;
                while (currentType != classType)
                {
                    ordinalByType++;
                    currentType = currentType.BaseType;
                }

                var metadata = new RoutedEventHandlerMetadata(handler, ordinalByType, ordinalWithinType, handledEventsToo);
                handlers.Add(metadata);

                if (!sortSuspended)
                {
                    Sort();
                }
            }
        }
開發者ID:RUSshy,項目名稱:ultraviolet,代碼行數:35,代碼來源:RoutedEventClassHandlerManager.cs

示例10: Remove

        public static Delegate Remove (Delegate a, Delegate b) {
          CodeContract.Ensures(((object)a) == null && ((object)b) == null ==> ((object)result) == null);
          CodeContract.Ensures(((object)a) == null && ((object)b) != null ==> ((object)result) == null);
          CodeContract.Ensures(((object)a) != null && ((object)b) == null ==> ((object)result) == (object)a);
          CodeContract.Ensures(((object)a) != null && ((object)b) != null ==> ((object)result) != null && result.GetType() == a.GetType() && Owner.Same(result, a));

          return default(Delegate);
        }
開發者ID:asvishnyakov,項目名稱:CodeContracts,代碼行數:8,代碼來源:System.Delegate.cs

示例11: EventForwarder

		public EventForwarder(Delegate realDelegate)
		{
			this.realDelegate = realDelegate;

			Type type = realDelegate.GetType();
			MethodInfo proxyMethod = typeof(EventForwarder).GetMethod("ForwardEvent" + realDelegate.Method.GetParameters().Length);
			proxyDelegate = Delegate.CreateDelegate(type, this, proxyMethod);
		}
開發者ID:kingjiang,項目名稱:SharpDevelopLite,代碼行數:8,代碼來源:EventForwarder.cs

示例12: ReflectionDetourNotifier

        public ReflectionDetourNotifier(HookFactory hookFactory, Delegate targetDelegate)
        {
            _targetDelegate = targetDelegate;
            _hookDelegate = GenerateInterceptor(targetDelegate);

            Hook = hookFactory(Marshal.GetFunctionPointerForDelegate(_targetDelegate),
                Marshal.GetFunctionPointerForDelegate(_hookDelegate));
            _detour = Hook.CreateDetour(_targetDelegate.GetType());
        }
開發者ID:sgraf812,項目名稱:BananaHook,代碼行數:9,代碼來源:ReflectionDetourNotifier.cs

示例13: GenerateInterceptor

        private Delegate GenerateInterceptor(Delegate targetDelegate)
        {
            Type delegateType = targetDelegate.GetType();
            MethodInfo mi = delegateType.GetMethod("Invoke");
            ParameterExpression[] parameters = (from p in mi.GetParameters()
                                                select Expression.Parameter(p.ParameterType, p.Name)).ToArray();

            var builder = new InterceptorFuncBuilder(this);
            return builder.CreateLambdaBody(parameters, delegateType, mi);
        }
開發者ID:sgraf812,項目名稱:BananaHook,代碼行數:10,代碼來源:ReflectionDetourNotifier.cs

示例14: IsMatch

        public bool IsMatch(Delegate action)
        {
            if (action == null) return false;

            if (action.Target != TargetWeakReference.Target) return false;
            if (action.GetType() != ActionType) return false;
            if (action.Method != Method) return false;

            return true;
        }
開發者ID:philcockfield,項目名稱:Open.TestHarness.SL,代碼行數:10,代碼來源:WeakDelegateReference.cs

示例15: HostCall

        public HostCall(string name, Delegate function)
        {
            m_Method = function.GetType().GetMethod("Invoke");
            if (m_Method.ReturnType != typeof(double))
                throw new ArgumentException("Required return type for delegate is double");

            m_Name = name;
            m_Function = function;
            var parameters = Method.GetParameters();
            m_ParameterList = new object[parameters.Length];
        }
開發者ID:JoshuaSmyth,項目名稱:SimpleExpressionParser,代碼行數:11,代碼來源:HostCall.cs


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