Skip to content

Solution # 2 - My attempt to remove the two if #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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);
}
}
}