Last active
June 20, 2019 15:38
-
-
Save taeber/4989133 to your computer and use it in GitHub Desktop.
To return any object as an Enumerable...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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