本文整理汇总了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);
}
示例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;
}
}
示例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;
}
示例4: DelegateData
public DelegateData(Delegate del, Type delType, Type module, BuildingEvents[] ID)
{
delegateInstance = del;
moduleType = module;
eventID = ID;
delegateType = delType;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
}
示例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 });
}
示例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 });
}
示例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 });
}
示例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);
}
示例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);
}
示例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.
}