示例#1
0
        /// <summary>
        /// Instances the entity from its definition stored in custom attribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <exception cref="System.ArgumentException">Thrown if one of the params is null</exception>
        internal static Verb FromAttribute(VerbDefinitionAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            var opt = new Verb(attribute.Name, attribute.HelpText);

            return(opt);
        }
        internal static Dictionary <PropertyInfo, VerbDefinitionAttribute> ExtractPropertiesMarkedWithVerbAttribute(Type targetType)
        {
            var dictionary = new Dictionary <PropertyInfo, VerbDefinitionAttribute>();
            var properties = targetType.GetProperties().ToList();

            properties = properties.Where(x =>
            {
                // get attributes put on class definition
                VerbDefinitionAttribute classAttribute = x.PropertyType.GetCustomAttribute <VerbDefinitionAttribute>();
                if (classAttribute == null)
                {
                    return(false);
                }

                return(true);
            }).ToList();
            properties.ForEach(p =>
            {
                VerbDefinitionAttribute attribute = p.PropertyType.GetCustomAttribute <VerbDefinitionAttribute>();
                dictionary.Add(p, attribute);
            });
            return(dictionary);
        }