Esempio n. 1
0
        /// <summary>
        /// Returns a string representation of the property formatted according to the given filters.
        /// </summary>
        /// <param name="filters">Determines how you want to display the output.</param>
        /// <returns></returns>
        public string ToString(Filters filters)
        {
            if (IsEmpty)
            {
                return(string.Empty);
            }

            if (filters.HasFlag(Filters.TrimDisabled) && !IsEnabled)
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            if (!(filters.HasFlag(Filters.TrimComment) || Comment.IsEmpty))
            {
                sb.AppendLine(Comment.ToString());
            }

            sb.AppendLine(IsEnabled
                ? $"[{Name}]"
                : $"[{Name}]".AsDisabled());

            for (int i = 0; i < _properties.Count; i++)
            {
                if (!IsEnabled)
                {
                    var s = Ini.Property
                            .Builder(_properties[i])
                            .IsEnable(IsEnabled)
                            .Build()
                            .ToString(filters);

                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        sb.AppendLine(s);
                    }
                }
                else
                {
                    var s = _properties[i].ToString(filters);
                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        sb.AppendLine(s);
                    }
                }
            }

            return(sb.ToString().Trim());
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a string representation of the property formatted according to the given filters.
        /// </summary>
        /// <param name="filters">Determines how you want to display the output.</param>
        /// <returns></returns>
        public string ToString(Filters filters)
        {
            if (IsEmpty || filters.HasFlag(Filters.TrimDisabled) && !IsEnabled)
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            if (!(filters.HasFlag(Filters.TrimComment) || Comment.IsEmpty))
            {
                sb.AppendLine(Comment.ToString());
            }

            sb.AppendLine(IsEnabled ? $"{Key}={Value}" : $"{Key}={Value}".AsDisabled());

            return(sb.ToString().Trim());
        }