fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var keys = new[] { "key1", "key2" };
  10.  
  11. var services = new Dictionary<string, Service>
  12. {
  13. {"key1", new Service {Components = new Dictionary<string, string> {{"comp1", "value1"}}}},
  14. {"key2", new Service {Components = new Dictionary<string, string> {{"comp2", "value2"}}}}
  15. };
  16.  
  17.  
  18. var serviceComponents = GetServiceComponents(keys, services);
  19. // do something with it
  20. }
  21.  
  22. public static IEnumerable<ServiceComponent> GetServiceComponents(string[] keys, Dictionary<string, Service> services)
  23. {
  24. var serviceComponents = new List<ServiceComponent>();
  25.  
  26. foreach (
  27. var key in
  28. keys.Select(
  29. name =>
  30. services.FirstOrDefault(
  31. x => x.Key.Equals(name))))
  32. {
  33. serviceComponents.AddRange(key.Value.Components.Select(component => new ServiceComponent
  34. {
  35. Name = key.Key,
  36. Service = component.Key,
  37. Value = component.Value,
  38. }));
  39. }
  40.  
  41. return serviceComponents.ToArray();
  42.  
  43. }
  44. }
  45.  
  46. public class Service
  47. {
  48. public Dictionary<string, string> Components { get; set; }
  49. }
  50.  
  51. public class ServiceComponent
  52. {
  53. public string Name { get; set; }
  54. public string Service { get; set; }
  55. public string Value { get; set; }
  56. }
Success #stdin #stdout 0.02s 33832KB
stdin
Standard input is empty
stdout
Standard output is empty