示例#1
0
        /// <summary>
        /// Appends all arguments from <paramref name="settings"/>.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public static string[] CollectAll(this AssemblyOptionSettings settings)
        {
            if (settings == null)
            {
                settings = new AssemblyOptionSettings();
            }
            var result = new List <string>();

            // ignore pre (Assembly attribute)
            //result.AddRange(AppendArguments(settings, preCommand: true));
            result.AddRange(AppendArguments(settings, preCommand: false));
            return(result.ToArray());
        }
示例#2
0
        /// <summary>
        /// Appends pre or post command arguments.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="preCommand"></param>
        public static string[] AppendArguments(AssemblyOptionSettings settings, bool preCommand)
        {
            var result = new List <string>();

            foreach (var property in typeof(AssemblyOptionSettings).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                foreach (string argument in GetArgumentFromProperty(property, settings, preCommand: preCommand))
                {
                    if (!string.IsNullOrEmpty(argument))
                    {
                        result.Add(argument);
                    }
                }
            }
            return(result.ToArray());
        }
示例#3
0
        /// <summary>
        /// Gets and processes <paramref name="property"/> value from <paramref name="settings"/>.
        /// </summary>
        /// <param name="property"></param>
        /// <param name="settings">The settings.</param>
        /// <param name="preCommand">Pre or post command.</param>
        /// <returns></returns>
        public static IEnumerable <string> GetArgumentFromProperty(PropertyInfo property, AssemblyOptionSettings settings, bool preCommand)
        {
            var autoPropertyAttribute = GetAutoPropertyAttributeOrNull(property);
            var parameterAttribute    = GetParameterAttributeOrNull(property);

            if (autoPropertyAttribute?.Format != null)
            {
                if (autoPropertyAttribute.PreCommand == preCommand)
                {
                    yield return(GetArgumentFromAutoProperty(autoPropertyAttribute, property, property.GetValue(settings)));
                }
            }
            else if (!preCommand && (autoPropertyAttribute == null || !autoPropertyAttribute.PreCommand) || (autoPropertyAttribute != null && autoPropertyAttribute.PreCommand && preCommand))
            {
                if (property.PropertyType == typeof(bool))
                {
                    yield return(GetArgumentFromBoolProperty(property, (bool)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(bool?))
                {
                    yield return(GetArgumentFromNullableBoolProperty(property, (bool?)property.GetValue(settings), parameterAttribute));
                }
                else if (property.PropertyType == typeof(int?))
                {
                    yield return(GetArgumentFromNullableIntProperty(property, (int?)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(Int64?))
                {
                    yield return(GetArgumentFromNullableInt64Property(property, (Int64?)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(UInt64?))
                {
                    yield return(GetArgumentFromNullableUInt64Property(property, (UInt64?)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(UInt16?))
                {
                    yield return(GetArgumentFromNullableUInt16Property(property, (UInt16?)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(string))
                {
                    yield return(GetArgumentFromStringProperty(property, (string)property.GetValue(settings), parameterAttribute));
                }
                else if (property.PropertyType == typeof(TimeSpan?))
                {
                    yield return(GetArgumentFromNullableTimeSpanProperty(property, (TimeSpan?)property.GetValue(settings)));
                }
                else if (property.PropertyType == typeof(string[]))
                {
                    foreach (string arg in GetArgumentFromStringArrayProperty(property, (string[])property.GetValue(settings)))
                    {
                        yield return(arg);
                    }
                }
            }
        }