mirror of
https://github.com/tonytins/Lorem.NET.git
synced 2025-03-15 04:32:23 +00:00
minor changes to the Enum -- mostly semantic
This commit is contained in:
parent
7684d858d7
commit
ff037bc9f3
3 changed files with 12 additions and 8 deletions
|
@ -8,6 +8,7 @@ namespace LoremNET
|
|||
{
|
||||
return s.Replace(pattern, "");
|
||||
}
|
||||
|
||||
internal static String[] Split(this string s, string separator)
|
||||
{
|
||||
return s.Split(new[] { separator }, StringSplitOptions.None);
|
||||
|
|
|
@ -20,14 +20,17 @@ namespace LoremNET
|
|||
return items[index];
|
||||
}
|
||||
|
||||
public static TEnum RandomEnum<TEnum>()
|
||||
public static TEnum Enum<TEnum>() where TEnum : struct, IConvertible
|
||||
{
|
||||
if (typeof(TEnum).IsEnum)
|
||||
{
|
||||
var v = Enum.GetValues(typeof(TEnum));
|
||||
return (TEnum)v.GetValue(LoremNET.RandomHelper.Instance.Next(v.Length));
|
||||
}
|
||||
else throw new ArgumentException("Generic type must be an enum.");
|
||||
if (typeof(TEnum).IsEnum)
|
||||
{
|
||||
var v = System.Enum.GetValues(typeof(TEnum));
|
||||
return (TEnum)v.GetValue(LoremNET.RandomHelper.Instance.Next(v.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Generic type must be an enum.");
|
||||
}
|
||||
}
|
||||
|
||||
/* http://stackoverflow.com/a/6651661/234132 */
|
||||
|
|
|
@ -51,7 +51,7 @@ string[] numbers = GetNumbers();
|
|||
string number = LoremNET.Lorem.Random(numbers);
|
||||
|
||||
// this will randomly select a value from the enum:
|
||||
MyEnum value = LoremNET.Lorem.RandomEnum<MyEnum>();
|
||||
MyEnum value = LoremNET.Lorem.Enum<MyEnum>();
|
||||
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue