minor changes to the Enum -- mostly semantic

This commit is contained in:
dochoffiday 2015-08-30 19:10:59 -04:00
parent 7684d858d7
commit ff037bc9f3
3 changed files with 12 additions and 8 deletions

View file

@ -8,6 +8,7 @@ namespace LoremNET
{ {
return s.Replace(pattern, ""); return s.Replace(pattern, "");
} }
internal static String[] Split(this string s, string separator) internal static String[] Split(this string s, string separator)
{ {
return s.Split(new[] { separator }, StringSplitOptions.None); return s.Split(new[] { separator }, StringSplitOptions.None);

View file

@ -20,14 +20,17 @@ namespace LoremNET
return items[index]; return items[index];
} }
public static TEnum RandomEnum<TEnum>() public static TEnum Enum<TEnum>() where TEnum : struct, IConvertible
{ {
if (typeof(TEnum).IsEnum) if (typeof(TEnum).IsEnum)
{ {
var v = Enum.GetValues(typeof(TEnum)); var v = System.Enum.GetValues(typeof(TEnum));
return (TEnum)v.GetValue(LoremNET.RandomHelper.Instance.Next(v.Length)); return (TEnum)v.GetValue(LoremNET.RandomHelper.Instance.Next(v.Length));
} }
else throw new ArgumentException("Generic type must be an enum."); else
{
throw new ArgumentException("Generic type must be an enum.");
}
} }
/* http://stackoverflow.com/a/6651661/234132 */ /* http://stackoverflow.com/a/6651661/234132 */

View file

@ -51,7 +51,7 @@ string[] numbers = GetNumbers();
string number = LoremNET.Lorem.Random(numbers); string number = LoremNET.Lorem.Random(numbers);
// this will randomly select a value from the enum: // this will randomly select a value from the enum:
MyEnum value = LoremNET.Lorem.RandomEnum<MyEnum>(); MyEnum value = LoremNET.Lorem.Enum<MyEnum>();
``` ```