• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Delegate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Add

 // Adds an EventKey -> Delegate mapping if it doesn't exist or 
 // combines a delegate to an existing EventKey
 public void Add(EventKey eventKey, Delegate handler) {
    Monitor.Enter(m_events);
    Delegate d;
    m_events.TryGetValue(eventKey, out d);
    m_events[eventKey] = Delegate.Combine(d, handler);
    Monitor.Exit(m_events);
 }
开发者ID:Helen1987,项目名称:edu,代码行数:9,代码来源:Ch11-1-EventSet.cs


示例2: addTrack

 /////////////////////////////////////////////////////
 // track methods
 /////////////////////////////////////////////////////
 public void addTrack(String name, Delegate onCompleteHandler=null)
 {
     if(_tracks.ContainsKey(name) == false){
         _tracks[name] = new SoundTrack( new Sound( name ), gameObject, onCompleteHandler );
         _tracks[name].volume = _trackVolume;
     }
 }
开发者ID:crl,项目名称:UniStarling,代码行数:10,代码来源:AudioService.cs


示例3: RemoveImpl

		protected override Delegate RemoveImpl(Delegate d)
		{
			MulticastDelegate ret = null, cur = null;

			for (MulticastDelegate del = this; del != null; del = (MulticastDelegate)del.mNext)
			{
				// Miss out the one we're removing
				if (!del.Equals(d))
				{
					if (ret == null)
					{
						ret = (MulticastDelegate)object.MemberwiseClone(del);
						cur = ret;
					}
					else
					{
						cur.mNext = (MulticastDelegate)object.MemberwiseClone(del);
						cur = (MulticastDelegate)cur.mNext;
					}
				}
			}
			if (cur != null)
			{
				cur.mNext = null;
			}

			return ret;
		}
开发者ID:carriercomm,项目名称:Proton-1,代码行数:28,代码来源:MulticastDelegate.cs


示例4: DelegateData

 public DelegateData(Delegate del, Type delType, Type module, BuildingEvents[] ID)
 {
     delegateInstance = del;
     moduleType = module;
     eventID = ID;
     delegateType = delType;
 }
开发者ID:dreadicon,项目名称:ModularSkylines,代码行数:7,代码来源:BuildingBehaviorDelegates.cs


示例5: registerDelegate

        public void registerDelegate(Delegate newOne)
        /* pre:  Have a list of delegates which could be empty. For the new delegate, have delegate identifier, name, topic 
         *       and whether presenting (true) or not (false).
         * post: Register a delegate by adding him/her to the top of the delegates stack. A delegate may only be a presenter
         *       if there is a presentation slot available (use availSlots), otherwise register the delegate and display an
         *       appropriate message. NO DUPLICATE DELEGATES ARE REGISTERED (on delegate identifier) - display an appropriate 
         *       message in such a case. 
         */
        {

            Stack temp = new Stack();
            Delegate cur;
            bool foundPos = false;
            while ((Delegates.Count > 0) && (!foundPos))
            {
                cur = (Delegate)Delegates.Pop();
                temp.Push(cur);
                if (cur.Equals(newOne))
                    foundPos = true;
            }
            while (temp.Count > 0)
                Delegates.Push(temp.Pop());
            if (foundPos)
                Console.WriteLine("Delegate " + newOne.DelID + " already registered.");
            else
            {
                if (newOne.Presenter)
                    if (availSlots() < 1)
                    {
                        Console.WriteLine("Delegate {0} registered but cannot present - not enough slots", newOne.DelID);
                        newOne.Presenter = false;
                    }
                Delegates.Push(newOne);
            }
        }
开发者ID:BeesZA,项目名称:wrws202,代码行数:35,代码来源:Conference.cs


示例6: SoundTrack

    private float _volumeRatio = 1; // sound volume ratio

    #endregion Fields

    #region Constructors

    /**
     * INIT soundTrack, hook up controls
     *  @param soundObject: Sound
     *  @param gameObject: GameObject
     * 	@param onCompleteHandler: Delegate
     **/
    public SoundTrack(Sound soundObject, GameObject gameObject, Delegate onCompleteHandler=null)
    {
        _soundObj = soundObject;
        _channel = gameObject.AddComponent("AudioSource") as AudioSource;
        _channel.clip = _soundObj.clip;
        _complete = onCompleteHandler;
    }
开发者ID:crl,项目名称:UniStarling,代码行数:19,代码来源:SoundTrack.cs


示例7: ContinuationTaskFromTask

 public ContinuationTaskFromTask(Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions)
     : base(action, state, InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, antecedent.Scheduler)
 {
     Contract.Requires(action is Action<Task> || action is Action<Task, object>, "Invalid delegate type in ContinuationTaskFromTask");
     _antecedent = antecedent;
     CapturedContext = ExecutionContext.Capture();
 }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:7,代码来源:ContinuationTaskFromTask.cs


示例8: Combine

 /// <summary>
 /// Concatenates an invocation list of 2 delegates.
 /// </summary>
 public static Delegate Combine(Delegate a, Delegate b)
 {
     if (a == null) return b;
     if (b == null) return a;
     a.Add(b);
     return a;
 }
开发者ID:nguyenkien,项目名称:api,代码行数:10,代码来源:Delegate.cs


示例9: EvaluateParameter

        /// <summary>
        ///     Gets the current value of the parameter given (optional) compiled query arguments.
        /// </summary>
        internal object EvaluateParameter(object[] arguments)
        {
            if (_cachedDelegate == null)
            {
                if (_funcletizedExpression.NodeType
                    == ExpressionType.Constant)
                {
                    return ((ConstantExpression)_funcletizedExpression).Value;
                }
                ConstantExpression ce;
                if (TryEvaluatePath(_funcletizedExpression, out ce))
                {
                    return ce.Value;
                }
            }

            try
            {
                if (_cachedDelegate == null)
                {
                    // Get the Func<> type for the property evaluator
                    var delegateType = TypeSystem.GetDelegateType(_compiledQueryParameters.Select(p => p.Type), _type);

                    // Now compile delegate for the funcletized expression
                    _cachedDelegate = Lambda(delegateType, _funcletizedExpression, _compiledQueryParameters).Compile();
                }
                return _cachedDelegate.DynamicInvoke(arguments);
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:36,代码来源:QueryParameterExpression.cs


示例10: AddEventHandler

 public sealed override void AddEventHandler(Object target, Delegate handler)
 {
     MethodInfo addMethod = this.AddMethod;
     if (!addMethod.IsPublic)
         throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod);
     addMethod.Invoke(target, new Object[] { handler });
 }
开发者ID:huamichaelchen,项目名称:corert,代码行数:7,代码来源:RuntimeEventInfo.cs


示例11: RemoveEventHandler

 public void RemoveEventHandler(object target, Delegate handler)
 {
     var removeMethod = GetRemoveMethod();
     if (removeMethod == null)
         throw new InvalidOperationException("no public remove method");
     removeMethod.Invoke(target, new object[] { handler });
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:7,代码来源:EventInfo.cs


示例12: AddEventHandler

 public void AddEventHandler(object target, Delegate handler)
 {
     var addMethod = GetAddMethod();
     if (addMethod == null)
         throw new InvalidOperationException("no public add method");
     addMethod.Invoke(target, new object[] { handler });
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:7,代码来源:EventInfo.cs


示例13: FireAndForget

 /// <summary>
 /// Executes the specified delegate with the specified arguments
 /// asynchronously on a thread pool thread
 /// </summary>
 /// <param name="d"></param>
 /// <param name="args"></param>
 public static void FireAndForget(Delegate d, params object[] args)
 {
     // Invoke the wrapper asynchronously, which will then
     // execute the wrapped delegate synchronously (in the
     // thread pool thread)
     if (d != null) wrapperInstance.BeginInvoke(d, args, callback, null);
 }
开发者ID:robincornelius,项目名称:omvviewer-light,代码行数:13,代码来源:ThreadUtil.cs


示例14: InterestCalculator

 public InterestCalculator(decimal money, decimal interest, int years, Delegate del)
 {
     this.Money = money;
     this.Interest = interest;
     this.Years = years;
     this.PayOutValue = del(money, interest, years);
 }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:7,代码来源:InterestCalculator.cs


示例15: GetDelegateMethodInfo

        public static MethodInfo GetDelegateMethodInfo(Delegate del)
        {
            if (del == null)
                throw new ArgumentException();
            Delegate[] invokeList = del.GetInvocationList();
            del = invokeList[invokeList.Length - 1];
            RuntimeTypeHandle typeOfFirstParameterIfInstanceDelegate;
            bool isOpenResolver;
            IntPtr originalLdFtnResult = RuntimeAugments.GetDelegateLdFtnResult(del, out typeOfFirstParameterIfInstanceDelegate, out isOpenResolver);
            if (originalLdFtnResult == (IntPtr)0)
                return null;

            MethodHandle methodHandle = default(MethodHandle);
            RuntimeTypeHandle[] genericMethodTypeArgumentHandles = null;

            bool callTryGetMethod = true;

            unsafe
            {
                if (isOpenResolver)
                {
                    OpenMethodResolver* resolver = (OpenMethodResolver*)originalLdFtnResult;
                    if (resolver->ResolverType == OpenMethodResolver.OpenNonVirtualResolve)
                    {
                        originalLdFtnResult = resolver->CodePointer;
                        // And go on to do normal ldftn processing.
                    }
                    else if (resolver->ResolverType == OpenMethodResolver.DispatchResolve)
                    {
                        callTryGetMethod = false;
                        methodHandle = resolver->Handle.AsMethodHandle();
                        genericMethodTypeArgumentHandles = null;
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(resolver->ResolverType == OpenMethodResolver.GVMResolve);

                        callTryGetMethod = false;
                        methodHandle = resolver->Handle.AsMethodHandle();

                        RuntimeTypeHandle declaringTypeHandleIgnored;
                        MethodNameAndSignature nameAndSignatureIgnored;
                        if (!TypeLoaderEnvironment.Instance.TryGetRuntimeMethodHandleComponents(resolver->GVMMethodHandle, out declaringTypeHandleIgnored, out nameAndSignatureIgnored, out genericMethodTypeArgumentHandles))
                            return null;
                    }
                }
            }

            if (callTryGetMethod)
            {
                if (!ReflectionExecution.ExecutionEnvironment.TryGetMethodForOriginalLdFtnResult(originalLdFtnResult, ref typeOfFirstParameterIfInstanceDelegate, out methodHandle, out genericMethodTypeArgumentHandles))
                    return null;
            }
            MethodBase methodBase = ReflectionCoreExecution.ExecutionDomain.GetMethod(typeOfFirstParameterIfInstanceDelegate, methodHandle, genericMethodTypeArgumentHandles);
            MethodInfo methodInfo = methodBase as MethodInfo;
            if (methodInfo != null)
                return methodInfo;
            return null; // GetMethod() returned a ConstructorInfo.
        }
开发者ID:tijoytom,项目名称:corert,代码行数:59,代码来源:DelegateMethodInfoRetriever.cs


示例16: Main

	static void Main ()
	{
		Delegate [] d = new Delegate [] { new Function<int, int, bool> (f1) };
		Assert.AreEqual (1, d.Length, "#1");
		MethodInfo mi = d [0].Method;
		Assert.AreEqual (typeof (Program), mi.DeclaringType, "#2");
		Assert.AreEqual ("Boolean f1(Int32, Int32)", mi.ToString (), "#2");
	}
开发者ID:mono,项目名称:gert,代码行数:8,代码来源:test.cs


示例17: RemoveImpl

		protected virtual Delegate RemoveImpl(Delegate d)
		{
			if (d.Equals(this))
			{
				return null;
			}
			return this;
		}
开发者ID:carriercomm,项目名称:Proton-1,代码行数:8,代码来源:Delegate.cs


示例18: DisplayDelegateInfo

 public static void DisplayDelegateInfo(Delegate del)
 {
     foreach (var item in del.GetInvocationList())
     {
         Console.WriteLine("Method Name {0}", del.Method);
         Console.WriteLine("Type Name {0}", del.Target);
     }
 }
开发者ID:TatevAghasaryan,项目名称:ToMIC,代码行数:8,代码来源:Program.cs


示例19: Remove

		public static Delegate Remove(Delegate source, Delegate value)
		{
			if (source == null)
			{
				return null;
			}
			return source.RemoveImpl(value);
		}
开发者ID:carriercomm,项目名称:Proton-1,代码行数:8,代码来源:Delegate.cs


示例20: RemoveEventHandler

        public virtual void RemoveEventHandler(Object target, Delegate handler)
        {
            MethodInfo removeMethod = RemoveMethod;
            if (!removeMethod.IsPublic)
                throw new InvalidOperationException(SR.InvalidOperation_NoPublicRemoveMethod);

            removeMethod.Invoke(target, new object[] { handler });
        }
开发者ID:huamichaelchen,项目名称:corert,代码行数:8,代码来源:EventInfo.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DelegateCollection类代码示例发布时间:2022-05-24
下一篇:
C# DelegadoRespuesta类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap