Exemplo n.º 1
0
        public T Add <T>(string title, IParentable parent) where T : SurveyObjectBase
        {
            int    id       = 0;
            object instance = new object();

            if (typeof(T) == typeof(Survey))
            {
                id       = Surveys.GetLastId() + 1;
                instance = Activator.CreateInstance(typeof(Survey), new object[] { id, title }) as Survey;
                parent.AddChild((Survey)instance);
            }
            else
            if (typeof(T) == typeof(Question))
            {
                var p = parent as Survey;
                if (p != null)
                {
                    id       = p.Questions.GetLastId() + 1;
                    instance = (Question)Activator.CreateInstance(typeof(Question), new object[] { id, title });
                    parent.AddChild((Question)instance);
                }
            }
            else
            {
                var p = parent as Question;
                if (p != null)
                {
                    id       = p.Answers.GetLastId() + 1;
                    instance = (Answer)Activator.CreateInstance(typeof(Answer), new object[] { id, title });
                    parent.AddChild((Answer)instance);
                }
            }

            return((T)instance);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add object to parent item
 /// </summary>
 /// <remarks>
 /// Doesn't check Id !!!!
 /// </remarks>
 /// <typeparam name="T">SurveyObjectBase</typeparam>
 /// <param name="item">Item to add</param>
 /// <param name="parent">Container item</param>
 /// <returns></returns>
 public T Add <T>(SurveyObjectBase item, IParentable parent) where T : SurveyObjectBase
 {
     parent.AddChild(item);
     return((T)item);
 }
Exemplo n.º 3
0
 public MyObject(string name, IParentable parent)
 {
     this.Name = name;
     this.Parent = parent;
     Children = new List<MyObject>();
 }