Skip to content

Instantly share code, notes, and snippets.

@taeber
Last active June 20, 2019 15:38
Show Gist options
  • Save taeber/4989133 to your computer and use it in GitHub Desktop.
Save taeber/4989133 to your computer and use it in GitHub Desktop.
To return any object as an Enumerable...
using System.Collections.Generic;
public static class ObjectHelper
{
public static IEnumerable<T> AsEnumerable<T>(this T self)
{
yield return self;
}
}
/*
class Data { }
interface IWorker
{
public Data GetData();
public List<Data> GetAllData();
}
class ResultsObject
{
public IEnumerable<Data> Results { get; set; }
}
...
public bool SetResults(IWorker worker, out ResultsObject results)
{
if (ConditionMet())
{
results.Data = worker.GetData().AsEnumerable();
}
else
{
results.Data = worker.GetAllData();
}
return true;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment