Exemple #1
0
 private void GetProperties(Form form, Object obj, ref int y)
 {
     foreach (PropertyInfo property in obj.GetType().GetProperties())
     {
         LabelAttribute attribute = property.GetCustomAttributes(true).OfType <LabelAttribute>().First();
         Controls.AddLabel(form, y, 0, ControlWidth, ControlHeight, attribute.LabelText);
         if (property.PropertyType.IsEnum)
         {
             Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, property.PropertyType.GetEnumNames(), property.GetValue(obj).ToString());
         }
         else
         {
             Controls.AddTextBox(form, y, ControlWidth, ControlWidth, ControlHeight, property.GetValue(obj)?.ToString());
         }
         y += ControlHeight * 2;
     }
 }
Exemple #2
0
 private void GetFields(Form form, Object obj, ref int y, ApplicationDataContext applicationDataContext)
 {
     foreach (FieldInfo field in obj.GetType().GetFields())
     {
         LabelAttribute attribute = field.GetCustomAttributes(true).OfType <LabelAttribute>().First();
         Controls.AddLabel(form, y, 0, ControlWidth, ControlHeight, attribute.LabelText);
         if (field.FieldType.IsGenericType)
         {
             IList list = (IList)field.GetValue(obj);
             Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, list.Cast <object>().ToArray(), "");
         }
         else
         {
             if (field.FieldType.GetCustomAttributes(true).OfType <CommunicationTypeAttribute>().First().CommunicationType == "Композиция")
             {
                 Button createObjectButton = Controls.AddButton(form, y, ControlWidth, ControlWidth, ControlHeight, "Посмотреть объект");
                 createObjectButton.Click += (sender, e) =>
                 {
                     Object newObj = (Object)field.GetValue(obj);
                     newObj.Update(applicationDataContext, false);
                 };
             }
             else
             {
                 List <Object> list = new List <Object>();
                 foreach (Object element in applicationDataContext.Objects)
                 {
                     if (element.GetType() == field.FieldType && element != field.GetValue(this))
                     {
                         list.Add(element);
                     }
                 }
                 Controls.AddComboBox(form, y, ControlWidth, ControlWidth, ControlHeight, list.Cast <object>().ToArray(), field.GetValue(this));
             }
         }
         y += ControlHeight * 2;
     }
 }