Exemplo n.º 1
0
        /// <summary>
        /// Processes all duplicate properties within this collection according to the specified behavior.
        /// </summary>
        /// <param name="behavior">An <see cref="IniDuplicatePropertyNameBehavior" /> object specifying how duplicates are processed.</param>
        /// <param name="ignoreCase"><see langword="true" /> to ignore character casing during name comparison.</param>
        public void ProcessDuplicates(IniDuplicatePropertyNameBehavior behavior, bool ignoreCase)
        {
            List <IniProperty> removedProperties = new List <IniProperty>();

            switch (behavior)
            {
            case IniDuplicatePropertyNameBehavior.Abort:
                if (Properties.DistinctBy(property => ignoreCase ? property.Name.ToLower() : property.Name).Count() != Count)
                {
                    throw Throw.Format("Duplicate property found.");
                }
                break;

            case IniDuplicatePropertyNameBehavior.Ignore:
                for (int i = 1; i < Count; i++)
                {
                    if (Properties.Take(i).Any(property => property.Name.Equals(Properties[i].Name, ignoreCase ? SpecialStringComparisons.IgnoreCase : SpecialStringComparisons.None)))
                    {
                        removedProperties.Add(Properties[i]);
                    }
                }
                break;

            case IniDuplicatePropertyNameBehavior.Overwrite:
                for (int i = 1; i < Count; i++)
                {
                    IniProperty firstProperty = Properties.Take(i).FirstOrDefault(property => property.Name.Equals(Properties[i].Name, ignoreCase ? SpecialStringComparisons.IgnoreCase : SpecialStringComparisons.None));
                    if (firstProperty != null)
                    {
                        firstProperty.Value = Properties[i].Value;
                        removedProperties.Add(Properties[i]);
                    }
                }
                break;

            case IniDuplicatePropertyNameBehavior.Duplicate:
                break;

            default:
                throw Throw.InvalidEnumArgument(nameof(behavior), behavior);
            }

            Properties.RemoveRange(removedProperties);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Processes all duplicate properties within this collection according to the specified behavior.
 /// </summary>
 /// <param name="behavior">An <see cref="IniDuplicatePropertyNameBehavior" /> object specifying how duplicates are processed.</param>
 public void ProcessDuplicates(IniDuplicatePropertyNameBehavior behavior)
 {
     ProcessDuplicates(behavior, false);
 }