public virtual void Help([Description("コマンド名")] String commandName) { if (String.IsNullOrEmpty(commandName)) { // コマンドの一覧 if (Contexts.Count > 0) { Console.NotifyMessage("[Contexts]"); foreach (var ctxInfo in Contexts) { if (AttributeUtil.IsBrowsable(ctxInfo.Type)) { Console.NotifyMessage(String.Format("{0} - {1}", ctxInfo.DisplayName.Replace("Context", ""), ctxInfo.Description)); } } } Console.NotifyMessage("[Commands]"); foreach (var command in GetCommands()) { Console.NotifyMessage(String.Format("{0} - {1}", command.Key, command.Value)); } } else { // コマンドの説明 MethodInfo methodInfo = GetCommand(commandName); if (methodInfo == null) { Console.NotifyMessage("指定された名前はこのコンテキストのコマンドに見つかりません。"); return; } String desc = AttributeUtil.GetDescription(methodInfo); if (!String.IsNullOrEmpty(desc)) { Console.NotifyMessage(desc); } ParameterInfo[] paramInfo = methodInfo.GetParameters(); if (paramInfo.Length > 0) { Console.NotifyMessage("引数:"); foreach (var paramInfoItem in paramInfo) { desc = AttributeUtil.GetDescription(paramInfoItem); Console.NotifyMessage(String.Format("- {0}: {1}", (String.IsNullOrEmpty(desc) ? paramInfoItem.Name : desc), paramInfoItem.ParameterType)); } } } }
private ICollection <ConfigurationPropertyInfo> GetConfigurationPropertiesFromConfiguration(IConfiguration config) { List <ConfigurationPropertyInfo> propInfoList = new List <ConfigurationPropertyInfo>(); // 既存のIConfigurationから作り出す MemberInfo[] memberInfoArr = config.GetType().GetMembers(BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance); foreach (var memberInfo in memberInfoArr) { if (!AttributeUtil.IsBrowsable(memberInfo)) { continue; } PropertyInfo pi = memberInfo as PropertyInfo; FieldInfo fi = memberInfo as FieldInfo; if (pi == null && fi == null) { continue; } String name = (pi == null) ? fi.Name : pi.Name; Type type = (pi == null) ? fi.FieldType : pi.PropertyType; Object defaultValue = AttributeUtil.GetDefaultValue(memberInfo); propInfoList.Add(new ConfigurationPropertyInfo { Description = AttributeUtil.GetDescription(memberInfo), Name = name, Type = type, MemberInfo = memberInfo, DefaultValue = (defaultValue ?? (type.IsValueType ? Activator.CreateInstance(type) : null)) }); } // ICustomConfiguration if (config is ICustomConfiguration) { propInfoList.AddRange(((ICustomConfiguration)config).GetConfigurationPropertyInfo()); } return(propInfoList); }
public virtual IDictionary <String, String> GetCommands() { MethodInfo[] methodInfoArr = this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public); Type t = typeof(Context); Dictionary <String, String> commands = new Dictionary <string, string>(); foreach (var methodInfo in methodInfoArr) { if (t.IsAssignableFrom(methodInfo.DeclaringType) && !methodInfo.IsConstructor && !methodInfo.IsFinal && !methodInfo.IsSpecialName) { if (!AttributeUtil.IsBrowsable(methodInfo) || (commands.ContainsKey(methodInfo.Name))) { continue; } commands.Add(methodInfo.Name, AttributeUtil.GetDescription(methodInfo)); } } return(commands); }
public virtual MethodInfo GetCommand(String commandName) { MethodInfo methodInfo = this.GetType().GetMethod(commandName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); if (methodInfo != null && (methodInfo.IsFinal || methodInfo.IsConstructor || methodInfo.IsSpecialName || AttributeUtil.IsBrowsable(methodInfo))) { return(methodInfo); } return(null); }