Beispiel #1
0
        private void Initialize()
        {
            List <ModelAction> actions = new List <ModelAction>();
            Type type = this.Provider.GetType();

            MethodInfo[] methods = type.GetMethods();

            int l = methods.Length;

            for (int i = 0; i < l; i++)
            {
                MethodInfo  current   = methods[i];
                ModelAction toBeAdded = null;
                object      attribute = null;
                if ((MethodMarkerType != null && current.HasCustomAttributeOfType(MethodMarkerType, out attribute)) ||
                    MethodMarkerType == null
                    )
                {
                    toBeAdded = new ModelAction(this.Provider, current);
                    ModelActionAttribute actionAttr = attribute as ModelActionAttribute;
                    if (actionAttr != null)
                    {
                        toBeAdded.Description = actionAttr.Description;
                    }
                }

                if (toBeAdded != null)
                {
                    actions.Add(toBeAdded);
                }
            }

            this.Actions = actions;
        }
Beispiel #2
0
        public string Write(ModelActionMenu menu)
        {
            StringBuilder builder = new StringBuilder();
            int           l       = menu.Actions.Count;

            string title = string.Format("{0} [{1}]", menu.Provider.GetType().Name, menu.MethodMarkerType.Name);

            builder.AppendLine(title);
            builder.AppendLine();

            for (int i = 0; i < l; i++)
            {
                ModelAction action = menu.Actions[i];
                string      name   = action.Name;
                string      desc   = !string.IsNullOrEmpty(action.Description) ? string.Format("({0})", action.Description) : string.Empty;
                builder.AppendFormat("{0}. {1} {2}\r\n", i + 1, name, desc);
            }

            return(builder.ToString());
        }