Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class CustomerBase
- {
- public long CustomerNumber { get; set; }
- public string Name { get; set; }
- }
- public abstract class CustomerWithChildern<T> : CustomerBase
- where T: CustomerBase
- {
- public IList<T> Childern { get; private set; }
- public CustomerWithChildern()
- {
- Childern = new List<T>();
- }
- }
- public class SalesOffice : CustomerWithChildern<NationalNegotiation>
- {
- }
- public void WalkHierarchy(CustomerBase start)
- {
- Print(start.CustomerNumber);
- if (start is CustomerWithChildern<>)
- {
- foreach(ch in start.Childern)
- {
- WalkHierarchy(ch);
- }
- }
- }
- public interface ICustomerWithChildern
- {
- IEnumerable ChildernEnum { get; }
- }
- public abstract class CustomerWithChildern<T> : CustomerBase, ICustomerWithChildern
- where T: CustomerBase
- {
- public IEnumerable ChildernEnum { get { return Childern; } }
- public IList<T> Childern { get; private set; }
- public CustomerWithChildern()
- {
- Childern = new List<T>();
- }
- }
- public void WalkHierarchy(CustomerBase start)
- {
- var x = start.CustomerNumber;
- var c = start as ICustomerWithChildern;
- if (c != null)
- {
- foreach(var ch in c.ChildernEnum)
- {
- WalkHierarchy((CustomerBase)ch);
- }
- }
- }
- if(start.GetType().GetGenericTypeDefinition() == typeof(CustomerWithChildern<>))
- Type t = typeof(CustomerWithChildern<>)
- typeof(CustomerWithChildern<>).IsAssignableFrom(CustomerWithChildern<Foo>)
Add Comment
Please, Sign In to add comment