/// <summary>
        /// Ordinals for properties defined on base class take precedence
        /// </summary>
        /// <returns></returns>
        protected IEnumerable <PropertyInfo> getHelpMethodsSorted(ParamsObject inputParams)
        {
            //Sort
            List <PropertyInfo> helpMethods = inputParams.GetType().GetProperties()
                                              .Where(p => p.PropertyType.IsAssignableFrom(
                                                         typeof(String)) &&
                                                     p.GetCustomAttribute <HelpTextAttribute>() != null)
                                              .OrderBy(s => s.GetCustomAttribute <HelpTextAttribute>().Ordinal)
                                              .ToList();

            //base class props don't move in ordinal
            IEnumerable <PropertyInfo> baseClassMethods = inputParams.GetType().BaseType.GetProperties()
                                                          .Where(p => p.PropertyType.IsAssignableFrom(
                                                                     typeof(String)) &&
                                                                 p.GetCustomAttribute <HelpTextAttribute>() != null);

            foreach (PropertyInfo pi in baseClassMethods)
            {
                //find pi in helpMethods
                //remove it, then place it in its correct position
                HelpTextAttribute attr         = pi.GetCustomAttribute <HelpTextAttribute>();
                PropertyInfo      helpMethodPi = helpMethods.Where(p => p.Name == pi.Name).FirstOrDefault();
                bool success = helpMethods.Remove(helpMethodPi);
                helpMethods.Insert(attr.Ordinal, helpMethodPi);
            }
            return(helpMethods);
        }
        protected IEnumerable <SwitchAttribute> getOrderedSwitches(ParamsObject inputParams)
        {
            IEnumerable <SwitchAttribute> allAttrs =
                inputParams.GetType().GetProperties()
                .Where(pi => pi.GetCustomAttribute <SwitchAttribute>() != null)
                .Select(pi => pi.GetCustomAttribute <SwitchAttribute>());

            IEnumerable <SwitchAttribute> withOrdinals = allAttrs.Where(sa => sa.DefaultOrdinal != null).OrderBy(sa => sa.DefaultOrdinal);
            IEnumerable <SwitchAttribute> noOrdinals   = allAttrs.Where(sa => sa.DefaultOrdinal == null);

            return(withOrdinals.Concat(noOrdinals));
        }
Exemple #3
0
 private void GetAvailableSwitchProperties()
 {
     _availableSwitchProps = new List <SwitchParameterEntity>();
     foreach (PropertyInfo _pi in _paramsObject.GetType().GetProperties())
     {
         SwitchAttribute _attr = _pi.GetCustomAttribute <SwitchAttribute>();
         if (_attr != null)
         {
             _availableSwitchProps.Add(new SwitchParameterEntity {
                 SwitchProperty = _pi, SwitchAttribute = _attr
             });
         }
     }
 }