本文整理汇总了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);
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例9: EventOperation
public EventOperation(Delegate assignation)
{
_delegateMethod = assignation.Method;
MethodBody body = _delegateMethod.GetMethodBody();
_stream = new MemoryStream(body.GetILAsByteArray());
_module = _delegateMethod.Module;
}
示例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;
}
示例11: Call5
public string Call5(Delegate callback)
{
var thisArg = JsValue.Undefined;
var arguments = new JsValue[] { 1, "foo" };
return callback.DynamicInvoke(thisArg, arguments).ToString();
}
示例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];
}
}
示例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);
}
}
示例14: InterestCalculatorClass
public InterestCalculatorClass(decimal money, float interest, int years, Delegate del)
{
this.Money = money;
this.Interest = interest;
this.Years = years;
this.dele = del;
}
示例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));
}