Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions dotnet/src/SinglePath/FieldsToFetch.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace SinglePath
{
public class FieldsToFetch
{
private HashSet<string> ensuredFieldNames;
private readonly HashSet<string> fieldsToFetch;
private readonly HashSet<string> _ensuredFieldNames;
private readonly HashSet<string> _fieldsToFetch;

public IEnumerable<string> Fields
public FieldsToFetch()
{
_fieldsToFetch = new HashSet<string>();
_ensuredFieldNames = new HashSet<string>();
}

public IEnumerable<string> Fields
{
get
{
HashSet<string> fieldsWeMustReturn = ensuredFieldNames == null
? new HashSet<string>()
: new HashSet<string>(ensuredFieldNames);
foreach (var fieldToReturn in GetFieldsToReturn())
HashSet<string> fieldsWeMustReturn = new HashSet<string>(_ensuredFieldNames);

foreach (var fieldToReturn in GetFieldsToReturn())
{
fieldsWeMustReturn.Remove(fieldToReturn);
yield return fieldToReturn;
Expand All @@ -32,19 +34,12 @@ public IEnumerable<string> Fields

private IEnumerable<string> GetFieldsToReturn()
{
if (fieldsToFetch == null)
yield break;
foreach (var field in fieldsToFetch)
{
yield return field;
}
return _fieldsToFetch;
}

public void EnsureHasField(string ensuredFieldName)
public void EnsureHasField(string ensuredFieldName)
{
if (ensuredFieldNames == null)
ensuredFieldNames = new HashSet<string>();
ensuredFieldNames.Add(ensuredFieldName);
_ensuredFieldNames.Add(ensuredFieldName);
}
}
}