forked from jonwingfield/sugar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some ruby-inspired extensions
- Loading branch information
1 parent
9a1f3b5
commit dfe7d46
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
bin | ||
obj | ||
TestResults | ||
*~ | ||
*.swp | ||
*.sln | ||
*.suo | ||
sugar |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Faker.Extensions | ||
{ | ||
public static class NumberExtensions | ||
{ | ||
public static IEnumerable<int> To(this int from, int to) | ||
{ | ||
if (to >= from) | ||
{ | ||
for (int i = from; i <= to; i++) | ||
{ | ||
yield return i; | ||
} | ||
} | ||
else | ||
{ | ||
for (int i = to; i >= from; i--) | ||
{ | ||
yield return i; | ||
} | ||
} | ||
} | ||
|
||
public static IEnumerable<T> Times<T>(this int num, T toReturn) | ||
{ | ||
for (int i = 0; i < num; i++) | ||
{ | ||
yield return toReturn; | ||
} | ||
} | ||
|
||
public static IEnumerable<T> Times<T>(this int num, Func<int, T> block) | ||
{ | ||
for (int i = 0; i < num; i++) | ||
{ | ||
yield return block(i); | ||
} | ||
} | ||
} | ||
} |