Advertisement
Guest User

Untitled

a guest
May 24th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public class FileDialogFilter
  2. {
  3. private readonly string _filter;
  4. private readonly string _description;
  5.  
  6. public string Description
  7. {
  8. get { return _description; }
  9. }
  10.  
  11. public string Filter
  12. {
  13. get { return _filter; }
  14. }
  15.  
  16. public FileDialogFilter(string description, string filter)
  17. {
  18. _description = description;
  19. _filter = filter;
  20. }
  21.  
  22. public static string From(params string[] values)
  23. {
  24. if (values.Length % 2 == 1)
  25. {
  26. throw new ArgumentException(@"Must have a matching filter for each description", "values");
  27. }
  28.  
  29. var filters = new FileDialogFilter[values.Length / 2];
  30.  
  31. for (var i = 0; i < filters.Length; i++)
  32. {
  33. filters[i] = new FileDialogFilter(values[2 * i], values[2 * i + 1]);
  34. }
  35.  
  36. return filters.Build();
  37. }
  38.  
  39. public override string ToString()
  40. {
  41. return string.Format("{0} ({1})|{1}", Description, Filter);
  42. }
  43. }
  44.  
  45. public static class FileDialogFilterExtensions
  46. {
  47. public static string Build(this IList<FileDialogFilter> filters)
  48. {
  49. return string.Join("|", filters);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement