fork download
  1. using System;
  2.  
  3. public class Program {
  4. public static void Main() {
  5. Console.WriteLine(ToSeparatedCommaString<DateTimeKind>(new DateTimeKind[] {DateTimeKind.Local, DateTimeKind.Unspecified, DateTimeKind.Utc}));
  6. }
  7. public static string ToSeparatedCommaString<T>(T[] enums) where T : struct, IComparable, IFormattable, IConvertible { //Não garante que seja enum mas sempre limita alguma coisa
  8. var commaString = string.Empty;
  9. if (!typeof(T).IsEnum) {
  10. throw new ArgumentException("Tipo de enums é inválido");
  11. }
  12. foreach (var item in enums) {
  13. Enum enumerador = item as Enum;
  14. commaString += enumerador.GetStringValue() + ",";
  15. }
  16. return commaString.TrimEnd(',');
  17. }
  18. }
  19.  
  20. public static class EnumExt {
  21. public static string GetStringValue(this Enum value) => "nome"; //só para testar
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/57318/101
Success #stdin #stdout 0.02s 16032KB
stdin
Standard input is empty
stdout
nome,nome,nome