当前位置: 首页>>代码示例>>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;未经允许,请勿转载。