////////////////////////////////////////////////////////////////////////// public static void LoadActions(Type type) { foreach (MethodInfo mi in type.GetMethods()) { foreach (Attribute Attr in mi.GetCustomAttributes(true)) { ActionPropAttribute ActProp = Attr as ActionPropAttribute; if (ActProp != null) { // TODO: check method parameters // create action Action Act = new Action(type, mi, ActProp.Name, ActProp); // create dictionary entry if necessary if (!Actions.ContainsKey(ActProp.Name)) { Actions.Add(ActProp.Name, new List <Action>()); } // add action to the list of actions with this name Actions[ActProp.Name].Add(Act); } } } }
////////////////////////////////////////////////////////////////////////// public Action(Type ContextType, MethodInfo Method, string Name, ActionPropAttribute Attr) { if (ContextType == null || Method == null) { throw new NullReferenceException(); } this.ContextType = ContextType; this.Method = Method; this.Name = Name; this.Attr = Attr; if (this.Attr.Caption == "") { this.Attr.Caption = this.Name; } if (this.Attr.Tooltip == "") { this.Attr.Tooltip = this.Attr.Caption; } if (Attr.IconName != "") { try { Icon = new Bitmap(ContextType, Attr.IconName); } catch { Icon = null; } } }
////////////////////////////////////////////////////////////////////////// public Action(Type ContextType, MethodInfo Method, string Name, ActionPropAttribute Attr) { if (ContextType == null || Method == null) throw new NullReferenceException(); this.ContextType = ContextType; this.Method = Method; this.Name = Name; this.Attr = Attr; if (this.Attr.Caption == "") this.Attr.Caption = this.Name; if (this.Attr.Tooltip == "") this.Attr.Tooltip = this.Attr.Caption; if(Attr.IconName!="") { try { Icon = new Bitmap(ContextType, Attr.IconName); } catch { Icon = null; } } }