using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
public class StringValueAttribute : Attribute
public string Value { get; private set; }
public StringValueAttribute(string value)
[StringValue("Computer Science")]
[StringValue("Software Engineering")]
public static class EnumExtensions
public static IEnumerable<string> GetStringValues<TEnum>() where TEnum : struct, IConvertible, IComparable, IFormattable
return Enum.GetValues(typeof(TEnum))
.Select(e => e.GetStringValue())
public static IEnumerable<string> GetStringValuesOfType(Enum value)
return Enum.GetValues(value.GetType())
.Select(e => e.GetStringValue())
public static string GetStringValue(this Enum value)
Type type = value.GetType();
FieldInfo fieldInfo = type.GetField(value.ToString());
StringValueAttribute[] attributes = fieldInfo.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
string stringValue = null;
if (attributes.Length > 0)
stringValue = attributes[0].Value;
public static void Test()
var values = EnumExtensions.GetStringValues<Group>();
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");