using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Text.RegularExpressions; namespace ST.Library.UI.NodeEditor { /// /// STNode node characteristics /// Used to describe STNode developer information and some behaviors /// public class STNodeAttribute : Attribute { private string _Path; /// /// Get the path that the STNode node expects in the tree control /// public string Path { get { return _Path; } } private string _Author; /// /// Get the author name of the STNode node /// public string Author { get { return _Author; } } private string _Mail; /// /// Get the author mailbox of the STNode node /// public string Mail { get { return _Mail; } } private string _Link; /// /// Get the author link of the STNode node /// public string Link { get { return _Link; } } private string _Description; /// /// Get the description information of the STNode node /// public string Description { get { return _Description; } } private static char[] m_ch_splitter = new char[] { '/', '\\' }; private static Regex m_reg = new Regex(@"^https?://", RegexOptions.IgnoreCase); /// /// Constructs an STNode property /// /// expected path public STNodeAttribute(string strPath) : this(strPath, null, null, null, null) { } /// /// Constructs an STNode property /// /// expected path /// Description public STNodeAttribute(string strPath, string strDescription) : this(strPath, null, null, null, strDescription) { } /// /// Constructs an STNode property /// /// expected path /// STNode author name /// STNode author mailbox /// STNode author link /// STNode node description information public STNodeAttribute(string strPath, string strAuthor, string strMail, string strLink, string strDescription) { if (!string.IsNullOrEmpty(strPath)) strPath = strPath.Trim().Trim(m_ch_splitter).Trim(); this._Path = strPath; this._Author = strAuthor; this._Mail = strMail; this._Description = strDescription; if (string.IsNullOrEmpty(strLink) || strLink.Trim() == string.Empty) return; strLink = strLink.Trim(); if (m_reg.IsMatch(strLink)) this._Link = strLink; else this._Link = "http://" + strLink; } private static Dictionary m_dic = new Dictionary(); /// /// Get type helper function /// /// Node Type /// Function information public static MethodInfo GetHelpMethod(Type stNodeType) { if (m_dic.ContainsKey(stNodeType)) return m_dic[stNodeType]; var mi = stNodeType.GetMethod("ShowHelpInfo"); if (mi == null) return null; if (!mi.IsStatic) return null; var ps = mi.GetParameters (); if (ps.Length != 1) return null; if (ps[0].ParameterType != typeof(string)) return null; m_dic.Add(stNodeType, mi); return mi; } /// /// Execute the helper function for the corresponding node type /// /// Node Type public static void ShowHelp(Type stNodeType) { var mi = STNodeAttribute.GetHelpMethod (stNodeType); if (mi == null) return; mi.Invoke(null, new object[] { stNodeType.Module.FullyQualifiedName }); } } }