Exemplo n.º 1
0
        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));
                    }
                }
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public ContextInfo(Type t)
 {
     Type        = t;
     DisplayName = t.Name;
     Description = AttributeUtil.GetDescription(t);
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 /// <summary>
 /// コンテキストを追加します。
 /// </summary>
 /// <param name="contextType"></param>
 public void RegisterContext(Type contextType)
 {
     RegisterContext(contextType, contextType.Name, AttributeUtil.GetDescription(contextType));
 }