Guest User

Untitled

a guest
Jun 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public abstract class CustomerBase
  2. {
  3. public long CustomerNumber { get; set; }
  4. public string Name { get; set; }
  5. }
  6.  
  7. public abstract class CustomerWithChildern<T> : CustomerBase
  8. where T: CustomerBase
  9. {
  10. public IList<T> Childern { get; private set; }
  11.  
  12. public CustomerWithChildern()
  13. {
  14. Childern = new List<T>();
  15. }
  16. }
  17.  
  18. public class SalesOffice : CustomerWithChildern<NationalNegotiation>
  19. {
  20. }
  21.  
  22. public void WalkHierarchy(CustomerBase start)
  23. {
  24. Print(start.CustomerNumber);
  25. if (start is CustomerWithChildern<>)
  26. {
  27. foreach(ch in start.Childern)
  28. {
  29. WalkHierarchy(ch);
  30. }
  31. }
  32. }
  33.  
  34. public interface ICustomerWithChildern
  35. {
  36. IEnumerable ChildernEnum { get; }
  37. }
  38.  
  39. public abstract class CustomerWithChildern<T> : CustomerBase, ICustomerWithChildern
  40. where T: CustomerBase
  41. {
  42. public IEnumerable ChildernEnum { get { return Childern; } }
  43.  
  44. public IList<T> Childern { get; private set; }
  45.  
  46. public CustomerWithChildern()
  47. {
  48. Childern = new List<T>();
  49. }
  50. }
  51.  
  52. public void WalkHierarchy(CustomerBase start)
  53. {
  54. var x = start.CustomerNumber;
  55. var c = start as ICustomerWithChildern;
  56. if (c != null)
  57. {
  58. foreach(var ch in c.ChildernEnum)
  59. {
  60. WalkHierarchy((CustomerBase)ch);
  61. }
  62. }
  63. }
  64.  
  65. if(start.GetType().GetGenericTypeDefinition() == typeof(CustomerWithChildern<>))
  66.  
  67. Type t = typeof(CustomerWithChildern<>)
  68.  
  69. typeof(CustomerWithChildern<>).IsAssignableFrom(CustomerWithChildern<Foo>)
Add Comment
Please, Sign In to add comment