Exemplo n.º 1
0
		public void Initialize()
		{
			Child1 = new TheChild();
			Child1.Initialize();
			Child1.Name += "_1";

			Child2 = new TheChild();
			Child2.Initialize();
			Child2.Name += "_2";

			Name = "Father-" + DateTime.Now.Ticks;
			LastName = "Grand-" + DateTime.Now.Ticks;
			AcceptableAges = new List<int>
				                 {
					                 10,
					                 17,
					                 20,
					                 22,
					                 30
				                 };
		}
Exemplo n.º 2
0
        public void Initialize()
        {
            Child1 = new TheChild();
            Child1.Initialize();
            Child1.Name += "_1";

            Child2 = new TheChild();
            Child2.Initialize();
            Child2.Name += "_2";

            Name           = "Father-" + DateTime.Now.Ticks;
            LastName       = "Grand-" + DateTime.Now.Ticks;
            AcceptableAges = new List <int>
            {
                10,
                17,
                20,
                22,
                30
            };
        }
Exemplo n.º 3
0
    public int field4;     // Won't pass down.
    public TheChild CreateChild()
    {
        TheChild x      = new TheChild();
        var      fields = typeof(TheParent).GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

        foreach (var field in fields)
        {
            var attributes = field.GetCustomAttributes(typeof(PassDownAttribute), true);
            if (attributes.Length == 0)
            {
                continue;
            }
            var sourceValue = field.GetValue(this);
            var targetField = typeof(TheChild).GetField(field.Name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            if (targetField != null)
            {
                targetField.SetValue(x, sourceValue);
            }
        }
        return(x);
    }
 public virtual void AddChild(ChildHolder childHolder)
 {
     TheChild.Add(childHolder.TheChild); // store children in original child object
     childHolder.Parent = this;          // and pass my parent information to childs holder
 }