A GapHelper static class to create unique (non-existing) size restricted names
Possible Bug

Since Func&lt;int, string&gt; transform is not guarded against collisions (different int values may yield the same string result), the next line is wrong. It only checks for unique elements in the already available data items, not in the new results fetched from transform.


 if (hashSet.Contains( text )) {



This could be solved by trying to add each element to the set instead:

if (!hashSet.Add( text )) {


LINQ

Furthermore, I would use an IEnumerable to allow for some LINQ chaining.

public static IEnumerable&lt;string&gt; GetNextName(
  int maxSize, IEnumerable&lt;string&gt; items, Func&lt;int, string&gt; transform) {


So we could just call:

public class ProcessingTask : IProcessor {
    public void Execute( FileContent fileContent ) {
        GapHelper.GetNextName(5, fileContent.Components
            .Select(c =&gt; c.Name)).Take(20).Select(x 
                =&gt; new Component { Name = x, Content = "Foo" })
            .ToList().ForEach(fileContent.Components.Add);
    }
}


Which yields better readability. Also a fun fact about disposing an enumerator from the initial code:


 using (var nameGenerator = // ..