コード例 #1
0
        GlobalOptionsWrapper ICommandExecutorImpl.GetGlobalOptions <T>(T globalOptions)
        {
            var options = new Dictionary <string, GlobalOptionAttribute>();

            foreach (var property in _typeHelper.GetGlobalOptionProperties(globalOptions))
            {
                var optionAtt = property.GetCustomAttribute <GlobalOptionAttribute>();

                if (optionAtt == null)
                {
                    continue;
                }

                _attributeDecorator.Decorate(optionAtt, property);

                if (optionAtt.ShortForm != '\0')
                {
                    options[optionAtt.ShortForm.ToString()] = optionAtt;
                }

                if (optionAtt.LongForm != null)
                {
                    options[optionAtt.LongForm] = optionAtt;
                }
            }

            return(new GlobalOptionsWrapper
            {
                GlobalOptionType = typeof(T),
                GlobalOptions = globalOptions,
                Options = options
            });
        }
コード例 #2
0
 void IAttributeDecorator.Decorate(VerbAttribute parentVerbAtt, Type globalOptionsType)
 {
     foreach (var member in _typeHelper.GetPropertiesAndMethods(parentVerbAtt.Instance))
     {
         if (member is PropertyInfo property && _typeHelper.TryGetVerbAttribute(property, out var childVerbAtt))
         {
             childVerbAtt.Property   = property;
             childVerbAtt.ParentVerb = parentVerbAtt;
             childVerbAtt.Instance   = property.GetValue(parentVerbAtt.Instance);
             _attributeDecorator.Decorate(childVerbAtt, globalOptionsType);
             parentVerbAtt.Verbs[childVerbAtt.GetName()] = childVerbAtt;
         }