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


C# System.Delegate類代碼示例

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


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

示例1: Remove

 public static Delegate Remove(Delegate source, Delegate value)
 {
     if (source == null) {
         return null;
     }
     return source.RemoveImpl(value);
 }
開發者ID:memsom,項目名稱:dotNetAnywhere-wb,代碼行數:7,代碼來源:Delegate.cs

示例2: AddTaskDelay

        private static void AddTaskDelay(Delegate ev, object[] paramArray, int time)
        {
            System.Threading.Thread.Sleep(time);
            bool bFired;

            if (ev != null)
            {
                foreach (Delegate singleCast in ev.GetInvocationList())
                {
                    bFired = false;
                    try
                    {
                        ISynchronizeInvoke syncInvoke = (ISynchronizeInvoke)singleCast.Target;
                        if (syncInvoke != null && syncInvoke.InvokeRequired)
                        {
                            bFired = true;
                            syncInvoke.BeginInvoke(singleCast, paramArray);
                        }
                        else
                        {
                            bFired = true;
                            singleCast.DynamicInvoke(paramArray);
                        }
                    }
                    catch (Exception)
                    {
                        if (!bFired)
                            singleCast.DynamicInvoke(paramArray);
                    }
                }
            }
        }
開發者ID:Xileck,項目名稱:tibiaapi,代碼行數:32,代碼來源:Scheduler.cs

示例3: BeginInvoke

 /// <summary>
 /// Forwards the BeginInvoke to the current application's <see cref="Dispatcher"/>.
 /// </summary>
 /// <param name="method">Method to be invoked.</param>
 /// <param name="arg">Arguments to pass to the invoked method.</param>
 public void BeginInvoke(Delegate method, object arg)
 {
     if (Application.Current != null)
     {
         Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, method, arg);
     }
 }
開發者ID:apoorv-vijay-joshi,項目名稱:FSE-2011-PDE,代碼行數:12,代碼來源:DefaultDispatcher.cs

示例4: AddDelegate

        public void AddDelegate(Type key, Delegate value)
        {
            if (key == firstKey)
            {
                throw new ArgumentException("An element with the same key already exists in the dictionary.");
            }

            if (firstKey == null && bindTo == null) // nothing
            {
                firstKey = key;
                firstValue = value;
            }
            else if (firstKey != null && bindTo == null) // one key existed
            {
                bindTo = new Dictionary<Type, Delegate>();
                bindTo.Add(firstKey, firstValue);
                firstKey = null;
                firstValue = null;
                bindTo.Add(key, value);
            }
            else
            {
                bindTo.Add(key, value);
            }
        }
開發者ID:yb199478,項目名稱:CatLib,代碼行數:25,代碼來源:DelegateBridge.cs

示例5: EnsureFunctionCode

        protected FunctionCode EnsureFunctionCode(Delegate/*!*/ dlg) {
            Debug.Assert(dlg != null);

            if (_code == null) {
                Interlocked.CompareExchange(
                    ref _code,
                    new FunctionCode(
                        (PythonContext)SourceUnit.LanguageContext,
                        dlg,
                        null,
                        "<module>",
                        "",
                        ArrayUtils.EmptyStrings,
                        GetCodeAttributes(),
                        SourceSpan.None,
                        SourceUnit.Path,
                        false,
                        true,
                        ArrayUtils.EmptyStrings,
                        ArrayUtils.EmptyStrings,
                        ArrayUtils.EmptyStrings,
                        ArrayUtils.EmptyStrings,
                        0,
                        null,
                        null
                    ),
                    null
                );
            }
            return _code;
        }
開發者ID:techarch,項目名稱:ironruby,代碼行數:31,代碼來源:RunnableScriptCode.cs

示例6: Execute

		public void Execute(Delegate method, DispatcherPriority priority)
		{
			if (application == null)
			{
				ExecuteDirectlyOrDuringATest(method);
				return;
			}

			var dispatcher = application.Dispatcher;

			if ((application != null) && isAsync)
			{
				dispatcher.BeginInvoke(method);
				return;
			}

			var notRequireUiThread = dispatcher.CheckAccess();

			if (notRequireUiThread)
			{
				ExecuteDirectlyOrDuringATest(method);
				return;
			}

			if (isAsync)
			{
				dispatcher.BeginInvoke(method, priority);
				return;
			}

			dispatcher.Invoke(method, priority);
		}
開發者ID:matteomigliore,項目名稱:HSDK,代碼行數:32,代碼來源:Execution.cs

示例7: MapListener

		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void MapListener(IEventDispatcher dispatcher, Enum type, Delegate listener, Type eventClass = null)
		{
			if (eventClass == null)
			{	
				eventClass = typeof(Event);
			}

			List<EventMapConfig> currentListeners = _suspended ? _suspendedListeners : _listeners;

			EventMapConfig config;

			int i = currentListeners.Count;

			while (i-- > 0) 
			{
				config = currentListeners [i];
				if (config.Equals (dispatcher, type, listener, eventClass))
					return;
			}

			Delegate callback = eventClass == typeof(Event) ? listener : (Action<IEvent>)delegate(IEvent evt){
				RouteEventToListener(evt, listener, eventClass);
			};

			config = new EventMapConfig (dispatcher, type, listener, eventClass, callback);

			currentListeners.Add (config);

			if (!_suspended) 
			{
				dispatcher.AddEventListener (type, callback);
			}
		}
開發者ID:mikecann,項目名稱:robotlegs-sharp-framework,代碼行數:37,代碼來源:EventMap.cs

示例8: ConnectListener

        public void ConnectListener(EventType eventType, Delegate listener)
        {
            if (disposed) { return; }
            var ex = events[eventType].CheckListener(listener);
            if (ex != null)
            {
                throw ex;
            }

            if (!ConnectedListeners.ContainsKey(eventType))
            {
                ConnectedListeners[eventType] = new ConcurrentDictionary<int, Delegate>();
            }
            else if (ConnectedListeners[eventType].Values.Contains(listener))
            {
                throw new ArgumentException("'listener' has already been connected to this event type.", "listener");
            }

            if (ConnectedListeners[eventType].Count == 0)
            {
                ConnectedListeners[eventType][0] = listener;
            }
            else
            {
                var index = ConnectedListeners[eventType].Keys.Max() + 1;
                ConnectedListeners[eventType][index] = listener;
            }
        }
開發者ID:thebecwar,項目名稱:ChatExchange.Net,代碼行數:28,代碼來源:EventManager.cs

示例9: EventOperation

 public EventOperation(Delegate assignation)
 {
     _delegateMethod = assignation.Method;
     MethodBody body = _delegateMethod.GetMethodBody();
     _stream = new MemoryStream(body.GetILAsByteArray());
     _module = _delegateMethod.Module;
 }
開發者ID:dgg,項目名稱:testing-commons,代碼行數:7,代碼來源:EventOperation.cs

示例10: Configure

        private Ptr<RPC_SERVER_INTERFACE> Configure(RpcHandle handle, Ptr<MIDL_SERVER_INFO> me, Guid iid,
                                                    Byte[] formatTypes, Byte[] formatProc, ushort[] formatProcOffsets,
                                                    Delegate[] funcs)
        {
            Ptr<RPC_SERVER_INTERFACE> svrIface = handle.CreatePtr(new RPC_SERVER_INTERFACE(handle, me, iid));
            Ptr<MIDL_STUB_DESC> stub = handle.CreatePtr(new MIDL_STUB_DESC(handle, svrIface.Handle, formatTypes, true));
            pStubDesc = stub.Handle;

            var dispatches = new IntPtr[funcs.Length];
            for (var i = 0; i < funcs.Length; ++i)
            {
              dispatches[i] = handle.PinFunction(funcs[i]);
            }
            DispatchTable = handle.Pin(dispatches);

            ProcString = handle.Pin(formatProc);
            FmtStringOffset = handle.Pin(formatProcOffsets.Clone());

            ThunkTable = IntPtr.Zero;
            pTransferSyntax = IntPtr.Zero;
            nCount = IntPtr.Zero;
            pSyntaxInfo = IntPtr.Zero;

            //Copy us back into the pinned address
            Marshal.StructureToPtr(this, me.Handle, false);
            return svrIface;
        }
開發者ID:terryfan1109,項目名稱:win32-test,代碼行數:27,代碼來源:MIDL_SERVER_INFO.cs

示例11: Call5

        public string Call5(Delegate callback)
        {
            var thisArg = JsValue.Undefined;
            var arguments = new JsValue[] { 1, "foo" };

            return callback.DynamicInvoke(thisArg, arguments).ToString();
        }
開發者ID:Willy-Kimura,項目名稱:jint,代碼行數:7,代碼來源:A.cs

示例12: CreateThunk

        public static unsafe IntPtr CreateThunk(Delegate @delegate, IntPtr methodTarget)
        {
            lock (thunkAllocatorLock)
            {
                int thunkEntry = thunkNextEntry;
                Delegate thunkDelegate;
                while ((thunkDelegate = delegates[thunkEntry]) != null)
                {
                    // TODO: Use WeakReference<Delegate> instead, and check if it has been GC
                    if (++thunkEntry >= ThunkCount)
                        thunkEntry = 0;

                    // We looped, which means nothing was found
                    // TODO: We should give it another try after performing GC
                    if (thunkEntry == thunkNextEntry)
                    {
                        throw new InvalidOperationException("No thunk available");
                    }
                }

                // Setup delegate and thunk target
                // TODO: We probably want a struct instead of 2 separate arrays
                delegates[thunkEntry] = @delegate;
                GetThunkTargets()[thunkEntry] = methodTarget;

                // Return our thunk redirect function pointer
                return GetThunkPointers()[thunkEntry];                
            }
        }
開發者ID:RainsSoft,項目名稱:SharpLang,代碼行數:29,代碼來源:MarshalHelper.cs

示例13: AddHandler

 public static void AddHandler(object target, RoutedEvent routedEvent, Delegate handler, bool handledEventsToo) {
     if (null == target)
         throw new ArgumentNullException("target");
     if (null == routedEvent)
         throw new ArgumentNullException("routedEvent");
     if (null == handler)
         throw new ArgumentNullException("handler");
     //
     RoutedEventKey key = routedEvent.Key;
     if (!routedEvents.ContainsKey(key))
         throw new ArgumentException("Specified routed event is not registered.", "routedEvent");
     RoutedEventInfo routedEventInfo = routedEvents[key];
     bool needAddTarget = true;
     if (routedEventInfo.targetsList != null) {
         RoutedEventTargetInfo targetInfo = routedEventInfo.targetsList.FirstOrDefault(info => info.target == target);
         if (null != targetInfo) {
             if (targetInfo.handlersList == null)
                 targetInfo.handlersList = new List<DelegateInfo>();
             targetInfo.handlersList.Add(new DelegateInfo(handler, handledEventsToo));
             needAddTarget = false;
         }
     }
     if (needAddTarget) {
         RoutedEventTargetInfo targetInfo = new RoutedEventTargetInfo(target);
         targetInfo.handlersList = new List<DelegateInfo>();
         targetInfo.handlersList.Add(new DelegateInfo(handler, handledEventsToo));
         if (routedEventInfo.targetsList == null)
             routedEventInfo.targetsList = new List<RoutedEventTargetInfo>();
         routedEventInfo.targetsList.Add(targetInfo);
     }
 }
開發者ID:CxSoftware,項目名稱:consoleframework,代碼行數:31,代碼來源:EventManager.cs

示例14: InterestCalculatorClass

 public InterestCalculatorClass(decimal money, float interest, int years, Delegate del)
 {
     this.Money = money;
     this.Interest = interest;
     this.Years = years;
     this.dele = del;
 }
開發者ID:mgulubov,項目名稱:SoftUniCourse-OOP,代碼行數:7,代碼來源:InterestCalculatorClass.cs

示例15: DelegateTestCase

 public DelegateTestCase(string fixtureName, Delegate testDelegate, params object[] args)
     : base(fixtureName)
 {
     this.testDelegate = testDelegate;
     foreach (Object arg in args)
         this.Parameters.Add(new TestCaseParameter(arg));
 }
開發者ID:buptkang,項目名稱:QuickGraph,代碼行數:7,代碼來源:DelegateTestCase.cs


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