static void Main(string[] args) { TotalInt total = delegate(int x) { int tt = 0; for (int i = 0; i < x; i++) { tt += i; } return(tt); }; Console.WriteLine(total(5)); HelloWorld hw = delegate(string s) { Console.WriteLine("Well well well " + s); }; hw(" Hello world anonymously "); hw = new HelloWorld(PrintSomething); //from pre c# 2.0 days hw(" from pre c# 2.0 days"); ///////////////////////////////////////////////////////////// StandardDelegate standard = Count; standard(); ////////////////////////////////// }
/// <summary> /// 移除事件 /// </summary> /// <param name="name"></param> /// <param name="Del"></param> public void RemoveEventHandler(string name, StandardDelegate Del) { if (EventMap.ContainsKey(name)) { if (EventMap[name] != null) { EventMap[name] -= Del; } } }
//移除某事件处理函数 public static void RemoveEventHandler(string eventName, StandardDelegate d) { if (m_eventMap.ContainsKey(eventName)) { if (m_eventMap[eventName] != null) { m_eventMap[eventName] -= d; } } }
/// <summary> /// 移除某事件 /// </summary> /// <param name="eventName"></param> /// <param name="func"></param> public void RemoveEventHandle(string eventName, StandardDelegate func) { if (m_eventDic.ContainsKey(eventName)) { if (m_eventDic[eventName] != null) { m_eventDic[eventName] -= func; } } }
/// <summary> /// 注册事件 /// </summary> /// <param name="name"></param> /// <param name="Del"></param> public void AddEventHandler(string name, StandardDelegate Del) { if (!EventMap.ContainsKey(name)) { EventMap.Add(name, Del); } else { EventMap[name] += Del; } }
//添加某事件处理 public static void AddEventHandler(string eventName, StandardDelegate d) { if (!m_eventMap.ContainsKey(eventName)) { m_eventMap[eventName] = d; } else { m_eventMap[eventName] += d; } }
/// <summary> /// 添加事件 /// </summary> /// <param name="eventName">事件名称</param> /// <param name="func">回调函数</param> public void AddEventHandle(string eventName, StandardDelegate func) { if (!m_eventDic.ContainsKey(eventName)) { m_eventDic.Add(eventName, func); } else { m_eventDic[eventName] += func; } }
//触发某事件,将通知到所有的事件监听对象 public static void RaiseEvent(string eventName, INotifyArgs e) { StandardDelegate fun = null; if (m_eventMap.TryGetValue(eventName, out fun)) { if (null != fun) { fun(e); } } }
/// <summary> /// 触发通知某个事件 /// </summary> /// <param name="eventName">事件名称</param> /// <param name="args">携带的参数</param> public void NotifireEvent(string eventName, params object[] args) { StandardDelegate fun = null; if (m_eventDic.TryGetValue(eventName, out fun)) { if (null != fun) { fun(args); } } }
/// <summary> /// 执行事件 /// </summary> /// <param name="name"></param> /// <param name="arg"></param> public void RaiseEvent(string name, params object[] arg) { if (EventMap.ContainsKey(name)) { StandardDelegate fun = null; if (EventMap.TryGetValue(name, out fun)) { if (fun != null) { fun(arg); } } } }
/// <summary> /// 移除某事件的所有委托 /// </summary> /// <param name="eventName"></param> public void RemoveAllEventHandle(string eventName) { if (m_eventDic.ContainsKey(eventName)) { if (m_eventDic[eventName] != null) { Delegate[] deArr = m_eventDic[eventName].GetInvocationList(); for (int i = 0; i < deArr.Length; i++) { StandardDelegate de = (StandardDelegate)deArr[i]; RemoveEventHandle(eventName, de); } } } }
public void Initialise(ContextMenu parentMenu, string description, StandardDelegate onClickMethod, ContextMenu subMenu) { transform.name = description; this.parentMenu = parentMenu; textLabel.text = description; this.onClickMethod = onClickMethod; this.subMenu = subMenu; if (subMenu == null) { subMenuArrow.gameObject.SetActive(false);//hide the arrow that would show more options } else { subMenu.parentMenu = parentMenu;//show our menu has a parent } }
public void UnregisterOnMoveEvent(StandardDelegate callback) { OnMoveEvent -= callback; }
protected override void OnDestroy() { if(_backgroundImage != null) { _backgroundImage.Recycle(); _backgroundImage.Dispose(); _backgroundImage = null; } Utils.RemoveBitmapsOfButtonStroked(_root); base.OnDestroy(); CloseAllDialog -= Finish; }
//-------------------------------------------------------------- // EVENT CATCHING METHODS //-------------------------------------------------------------- protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate (savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); Window.SetBackgroundDrawable(new ColorDrawable(Color.Transparent)); SetContentView(Resource.Layout.Dialog); _root = FindViewById<LinearLayout>(Resource.Id.alertContainer); _root.SetPadding(Builder.StrokeBorderWidth, Builder.StrokeBorderWidth, Builder.StrokeBorderWidth, Builder.StrokeBorderWidth); _root.SetMinimumWidth ((int)(WindowManager.DefaultDisplay.Width * MinWidthRatio)); _root.SetMinimumHeight((int)(WindowManager.DefaultDisplay.Height * MinHeightRatio)); if(_root.ViewTreeObserver.IsAlive) { _root.ViewTreeObserver.AddOnGlobalLayoutListener(this); } _title = FindViewById<TextView>(Resource.Id.alertTitle); _title.SetTextColor(Builder.StrokeColor); _title.Gravity = GravityFlags.CenterHorizontal; if(String.IsNullOrEmpty(Builder.Title)) { _title.Visibility = ViewStates.Gone; } else { _title.Text = Builder.Title; } _content = FindViewById<LinearLayout>(Resource.Id.alertContent); switch (Builder.ContentType) { case DialogBuilder.DialogContentType.TextView: if(!String.IsNullOrEmpty(Builder.Message)) { _message = new TextView(this); _message.Text = Builder.Message; _message.SetTextSize(Android.Util.ComplexUnitType.Dip, TextSize); _message.SetTextColor(Builder.TextColor); _message.Gravity = GravityFlags.CenterHorizontal; _content.AddView(_message, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); } break; case DialogBuilder.DialogContentType.EditText: _field = new EditText(this); _field.Hint = Builder.Message; _field.SetTextSize(Android.Util.ComplexUnitType.Dip, TextSize); // Limit the length _field.SetFilters( new IInputFilter[] { new InputFilterLengthFilter(Constants.MaxLengthName) } ); _content.AddView(_field, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); break; case DialogBuilder.DialogContentType.None: foreach(View view in Builder.Content) { _content.AddView(view, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); } break; default: break; } _buttonLayout = FindViewById<LinearLayout>(Resource.Id.buttonLayout); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) _buttonLayout.LayoutParameters; lp.TopMargin = Builder.StrokeBorderWidth; _buttonLayout.LayoutParameters = lp; _positiveButton = FindViewById<ButtonStroked>(Resource.Id.positiveButton); _negativeButton = FindViewById<ButtonStroked>(Resource.Id.negativeButton); if(String.IsNullOrEmpty(Builder.PositiveText) && String.IsNullOrEmpty(Builder.NegativeText)) { _positiveButton.Visibility = ViewStates.Gone; _negativeButton.Visibility = ViewStates.Gone; } else if(String.IsNullOrEmpty(Builder.PositiveText)) { _positiveButton.Visibility = ViewStates.Gone; LinearLayout.LayoutParams lpNeg = (LinearLayout.LayoutParams) _negativeButton.LayoutParameters; lpNeg.Weight = 2; _negativeButton.LayoutParameters = lpNeg; } else if(String.IsNullOrEmpty(Builder.NegativeText)) { _negativeButton.Visibility = ViewStates.Gone; LinearLayout.LayoutParams lpPos = (LinearLayout.LayoutParams) _positiveButton.LayoutParameters; lpPos.Weight = 2; _positiveButton.LayoutParameters = lpPos; } else { LinearLayout.LayoutParams lpPos = (LinearLayout.LayoutParams) _positiveButton.LayoutParameters; lpPos.LeftMargin = Builder.StrokeBorderWidth/2; _positiveButton.LayoutParameters = lpPos; LinearLayout.LayoutParams lpNeg = (LinearLayout.LayoutParams) _negativeButton.LayoutParameters; lpNeg.RightMargin = Builder.StrokeBorderWidth/2; _negativeButton.LayoutParameters = lpNeg; } UtilsUI.SetDialogButton(this, _positiveButton, _field, TetrisColor.Green, Builder.PositiveText, Builder.PositiveAction, true); UtilsUI.SetDialogButton(this, _negativeButton, _field, TetrisColor.Yellow, Builder.NegativeText, Builder.NegativeAction, false); CloseAllDialog += Finish; }