本文整理汇总了C#中Delegate.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Delegate.GetType方法的具体用法?C# Delegate.GetType怎么用?C# Delegate.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Delegate
的用法示例。
在下文中一共展示了Delegate.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnListenerAdding
static public void OnListenerAdding(string eventType, Delegate listenerBeingAdded) {
if (!eventTable.ContainsKey(eventType)) {
eventTable.Add(eventType, null);
}
Delegate d = eventTable[eventType];
if (d != null && d.GetType() != listenerBeingAdded.GetType()) {
throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
}
}
示例2: RemoveHandler
public void RemoveHandler(Delegate h)
{
Delegate aux, res;
if (handlers.TryGetValue(h.GetType(), out aux))
{
res = Delegate.Remove(aux, h);
handlers.Remove(h.GetType());
handlers.Add(h.GetType(), res);
}
}
示例3: OnListenerRemoving
static public void OnListenerRemoving(string eventType, Delegate listenerBeingRemoved) {
if (eventTable.ContainsKey(eventType)) {
Delegate d = eventTable[eventType];
if (d == null) {
throw new ListenerException(string.Format("Attempting to remove listener with for event type {0} but current listener is null.", eventType));
} else if (d.GetType() != listenerBeingRemoved.GetType()) {
throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
}
} else {
throw new ListenerException(string.Format("Attempting to remove listener for type {0} but Messenger doesn't know about this event type.", eventType));
}
}
示例4: AddHandler
public void AddHandler(Delegate h)
{
Delegate aux;
if (handlers.ContainsKey(h.GetType()))
{
if (handlers.TryGetValue(h.GetType(), out aux))
{
aux = Delegate.Combine(aux, h);
// aux += h;
handlers.Remove(h.GetType());
handlers.Add(h.GetType(), aux);
}
}
else
handlers.Add(h.GetType(), h);
}
示例5: Combine
public static Delegate Combine(Delegate a, Delegate b) {
if (a == null) {
return b;
} else if (b == null) {
return a;
}
if (a.GetType() != b.GetType()) {
throw new ArgumentException("Incompatible delegate types");
}
return a.CombineImpl(b);
}
示例6: CombineImpl
protected override Delegate CombineImpl(Delegate follow)
{
if (follow == null)
return this;
// Verify that the types are the same...
if (this.GetType() != follow.GetType())
throw new ArgumentException("DlgtTypeMis");
MulticastDelegate dFollow = (MulticastDelegate)follow;
MulticastDelegate[] resultList;
int followCount = 1;
MulticastDelegate[] followList = dFollow._invocationList;
if (followList != null)
followCount = (int)dFollow._invocationCount;
int resultCount;
MulticastDelegate[] invocationList = _invocationList;
if (invocationList == null)
{
resultCount = 1 + followCount;
resultList = new MulticastDelegate[resultCount];
resultList[0] = this;
if (followList == null)
{
resultList[1] = dFollow;
}
else
{
for (int i = 0; i < followCount; i++)
resultList[1 + i] = followList[i];
}
return NewMulticastDelegate(resultList, resultCount);
}
else
{
int invocationCount = _invocationCount;
resultCount = invocationCount + followCount;
resultList = null;
if (resultCount <= invocationList.Length)
{
resultList = invocationList;
if (followList == null)
{
if (!TrySetSlot(resultList, invocationCount, dFollow))
resultList = null;
}
else
{
for (int i = 0; i < followCount; i++)
{
if (!TrySetSlot(resultList, invocationCount + i, followList[i]))
{
resultList = null;
break;
}
}
}
}
if (resultList == null)
{
int allocCount = invocationList.Length;
while (allocCount < resultCount)
allocCount *= 2;
resultList = new MulticastDelegate[allocCount];
for (int i = 0; i < invocationCount; i++)
resultList[i] = invocationList[i];
if (followList == null)
{
resultList[invocationCount] = dFollow;
}
else
{
for (int i = 0; i < followCount; i++)
resultList[invocationCount + i] = followList[i];
}
}
return NewMulticastDelegate(resultList, resultCount);
}
}
示例7: OnListenerRemoving
public static void OnListenerRemoving(string eventType, Delegate listenerBeingRemoved)
{
#if LOG_ALL_MESSAGES || LOG_REMOVE_LISTENER
Debug.Log("MESSENGER OnListenerRemoving \t\"" + eventType + "\"\t{" + listenerBeingRemoved.Target + " -> " + listenerBeingRemoved.Method + "}");
#endif
if (eventTable.ContainsKey (eventType)) {
Delegate d = eventTable [eventType];
if (d == null) {
throw new ListenerException (string.Format ("Attempting to remove listener with for event type {0} but current listener is null.", eventType));
} else if (d.GetType () != listenerBeingRemoved.GetType ()) {
throw new ListenerException (string.Format ("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType ().Name, listenerBeingRemoved.GetType ().Name));
}
} else {
throw new ListenerException (string.Format ("Attempting to remove listener for type {0} but Messenger doesn't know about this event type.", eventType));
}
}
示例8: OnListenerAdding
public static void OnListenerAdding(string eventType, Delegate listenerBeingAdded)
{
#if LOG_ALL_MESSAGES || LOG_ADD_LISTENER
Debug.Log("MESSENGER OnListenerAdding \t\"" + eventType + "\"\t{" + listenerBeingAdded.Target + " -> " + listenerBeingAdded.Method + "}");
#endif
if (!eventTable.ContainsKey (eventType)) {
eventTable.Add (eventType, null);
}
Delegate d = eventTable [eventType];
if (d != null && d.GetType () != listenerBeingAdded.GetType ()) {
throw new ListenerException (string.Format ("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType ().Name, listenerBeingAdded.GetType ().Name));
}
}
示例9: UpdateInvokeInfo
public void UpdateInvokeInfo(Delegate d, int callArgs)
{
int args = callArgs - 1;
var t = d.GetType ();
_d = d;
// Set up args arrays
if (t.Namespace == "PlayScript") {
bool isActionP = t.Name.StartsWith ("ActionP");
bool isFuncP = t.Name.StartsWith ("FuncP");
int argsP = 1;
if (isActionP || isFuncP) {
if (t.IsGenericType) {
argsP += t.GetGenericArguments ().Length;
}
if (isFuncP) {
argsP--;
}
_args = new object[argsP];
_params = new object[args - (argsP - 1)];
_args [argsP - 1] = _params;
_targetArray = new object[args][];
_targetIndex = new int[args];
for (int i = 0; i < args; i++) {
if (i < argsP - 1) {
_targetArray [i] = _args;
_targetIndex [i] = i;
} else {
_targetArray [i] = _params;
_targetIndex [i] = i - (argsP - 1);
}
}
}
} else {
_args = new object[args];
_params = null;
}
}
示例10: AddEventHandler
/// <summary>
/// This adds the delegate value as a listener to when this event is fired
/// by the component, invoking the addOnXXX method.
/// </summary>
public override void AddEventHandler(object component, Delegate value)
{
FillMethods();
if (component != null)
{
ISite site = GetSite(component);
#if FEATURE_ICOMPONENTCHANGESERVICE
IComponentChangeService changeService = null;
// Announce that we are about to change this component
//
if (site != null)
{
changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
}
if (changeService != null)
{
#if FEATURE_CHECKOUTEXCEPTION
try {
changeService.OnComponentChanging(component, this);
}
catch (CheckoutException coEx) {
if (coEx == CheckoutException.Canceled) {
return;
}
throw coEx;
}
#else
changeService.OnComponentChanging(component, this);
#endif // FEATURE_CHECKOUTEXCEPTION
}
#endif // FEATURE_ICOMPONENTCHANGESERVICE
bool shadowed = false;
if (site != null && site.DesignMode)
{
// Events are final, so just check the class
if (EventType != value.GetType())
{
throw new ArgumentException(SR.Format(SR.ErrorInvalidEventHandler, Name));
}
IDictionaryService dict = (IDictionaryService)site.GetService(typeof(IDictionaryService));
if (dict != null)
{
Delegate eventdesc = (Delegate)dict.GetValue(this);
eventdesc = Delegate.Combine(eventdesc, value);
dict.SetValue(this, eventdesc);
shadowed = true;
}
}
if (!shadowed)
{
_addMethod.Invoke(component, new[] { value });
}
#if FEATURE_ICOMPONENTCHANGESERVICE
// Now notify the change service that the change was successful.
//
if (changeService != null)
{
changeService.OnComponentChanged(component, this, null, value);
}
#endif
}
}