public override void ListBoxInsight_Click(object sender, EventArgs e)
 {
     _ListBoxInsight.Visible = false;
     if (_ListBoxInsight.SelectedIndex > -1)
     {
         FormatMethodAttribute att = (FormatMethodAttribute)_ListBoxInsight.Items[_ListBoxInsight.SelectedIndex];
         _TbCode.SelectedText = att.Name;
     }
     _TbCode.Focus();
 }
Beispiel #2
0
        private string BuildItemHelp(FormatMethodAttribute at)
        {
            string        tmp = @"

<h1>{0}</h1>
<h3>{1}</h3>
<hr/>
<b>Aliasses:</b></br>
{2}</br>
</br>
<b>Description:</b></br>
{3}</br>
</br>
<b>Parameters:</b></br>
{5}</br>
</br>
</hr>
<b>Example:</b></br>
{4}
</br>
";
            StringBuilder sb  = new StringBuilder();

            if (at.Parameters.Count == 0)
            {
                sb.Append("<li><i>None</i></li>");
            }
            foreach (FormatMethodParameterAttribute prm in at.Parameters)
            {
                sb.Append("<li>\r\n");
                sb.AppendFormat("{0} ", prm.Name);
                sb.AppendFormat("{0}", prm.Optional == true ? "<i>optional</i>" : "");
                sb.AppendFormat("{0}", prm.IsParams == true ? "<i>params</i>" : "");
                if (!string.IsNullOrEmpty(prm.Description))
                {
                    sb.AppendFormat("<br/>\r\n{0}", prm.Description.Replace("\r\n", "<br/>"));
                }

                if (prm.PropertyReference.PropertyType.BaseType == typeof(Enum))
                {
                    foreach (int val in EnumUtility.GetValues(prm.PropertyReference.PropertyType))
                    {
                        sb.Append("<ul>");
                        string name        = Enum.GetName(prm.PropertyReference.PropertyType, val);
                        string description = EnumUtility.GetDescription(EnumUtility.GetValueByName(prm.PropertyReference.PropertyType, name));
                        sb.AppendFormat("<li>{0}<br/>{1}</li>\r\n", name, description);
                        sb.Append("</ul>\r\n");
                    }
                }

                sb.Append("</li>");
            }

            return(string.Format(tmp, at.Name, at.ToString(), at.Aliasses, at.Description, at.Example, sb.ToString()));
        }
 public override void ListBoxInsight_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyValue == 27 || e.KeyValue == 8)
     {
         _ListBoxInsight.Visible = false;
         e.Handled = true;
     }
     if (e.KeyValue == 13 || e.KeyValue == 32)
     {
         _ListBoxInsight.Visible = false;
         FormatMethodAttribute att = (FormatMethodAttribute)_ListBoxInsight.Items[_ListBoxInsight.SelectedIndex];
         _TbCode.SelectedText = att.Name;
         e.Handled            = true;
     }
 }
        public static MethodInstance GetMethodInstance(string name)
        {
            List <Type> methodtTypes = Utils.GetObjectsWithBaseType(typeof(MethodBase), true);

            string[] aliasses = new string[0];
            foreach (Type t in methodtTypes)
            {
                FormatMethodAttribute att = FormatMethodAttribute.GetAttribute(t);
                if (att != null)
                {
                    if (att.Name.Equals(name, StringComparison.Ordinal))
                    {
                        MethodInstance instance = new MethodInstance()
                        {
                            Formatter = (MethodBase)Activator.CreateInstance(t), Name = att.Name
                        };
                        foreach (FormatMethodParameterAttribute at in att.Parameters)
                        {
                            instance.Properties.Add(at);
                        }

                        return(instance);
                    }
                    else
                    {
                        aliasses = Utils.Split(att.Aliasses, ",");
                        foreach (string alias in aliasses)
                        {
                            if (alias.Trim().Equals(name, StringComparison.Ordinal))
                            {
                                MethodInstance instance = new MethodInstance()
                                {
                                    Formatter = (MethodBase)Activator.CreateInstance(t), Name = att.Name
                                };
                                foreach (FormatMethodParameterAttribute at in att.Parameters)
                                {
                                    instance.Properties.Add(at);
                                }

                                return(instance);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #5
0
        public void ListFormatters(StringBuilder sb)
        {
            List <Type> methodtTypes             = Utils.GetObjectsWithBaseType(typeof(MethodBase), true);
            List <FormatMethodAttribute> attribs = new List <FormatMethodAttribute>();

            foreach (Type t in methodtTypes)
            {
                FormatMethodAttribute att = FormatMethodAttribute.GetAttribute(t);
                if (!string.IsNullOrEmpty(att.Name))
                {
                    attribs.Add(att);
                }
            }
            attribs = (from t in attribs
                       orderby t.Name ascending
                       select t).ToList();

            foreach (FormatMethodAttribute att in attribs)
            {
                sb.Append(BuildItemHelp(att));
            }
        }
        public override void Initialize()
        {
            _ListBoxInsight.Items.Clear();

            List <Type> methodtTypes             = Utils.GetObjectsWithBaseType(typeof(GK.Template.Methods.MethodBase), true);
            List <FormatMethodAttribute> attribs = new List <FormatMethodAttribute>();

            foreach (Type t in methodtTypes)
            {
                FormatMethodAttribute att = FormatMethodAttribute.GetAttribute(t);
                if (!string.IsNullOrEmpty(att.Name))
                {
                    attribs.Add(att);
                }
            }
            attribs = (from t in attribs
                       orderby t.Name ascending
                       select t).ToList();

            foreach (FormatMethodAttribute att in attribs)
            {
                _ListBoxInsight.Items.Add(att);
            }
        }