当前位置: 首页>>代码示例>>C#>>正文


C# Delegate类代码示例

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


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


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