Inheritance: ValidateAttribute
Example #1
0
        bool IsPropertyNotNullInSceneAndPrefab(SerializedProperty property)
        {
            NotNullAttribute myAttribute         = (NotNullAttribute)base.attribute;
            bool             isPrefabAllowedNull = myAttribute.IgnorePrefab;

            return(IsPropertyOnPrefab(property) && isPrefabAllowedNull);
        }
Example #2
0
        public void ValidInstanceFieldsPasses()
        {
            var inst = new ValidClass();

            inst.Action = () => { };
            Assert.DoesNotThrow(() =>
                                NotNullAttribute.ValidInstanceFields(inst)//test point
                                );
        }
Example #3
0
        public override void OnGUILayout()
        {
            NotNullAttribute attr = GetAttr <NotNullAttribute>();

            //bool isNotNull = IsValid();
            //if(!isNotNull)
            //{
            //    EditorGUILayout.HelpBox(string.IsNullOrEmpty(attr.UnvalidMsg) ? "" : attr.UnvalidMsg, MessageType.Error);
            //}
        }
Example #4
0
        public void ValidInstanceFieldsFails()
        {
            LogAssert.ignoreFailingMessages = true;

            var inst = new ValidClass();

            inst.Action = null;
            Assert.DoesNotThrow(() =>
                                NotNullAttribute.ValidInstanceFields(inst) //test point
                                );
        }
        public void WithNull()
        {
            // arrange
            object Value = null;
            var Attrib = new NotNullAttribute();

            // act
            var Result = Attrib.IsValid(Value);

            // assert
            Assert.That(Result, Is.False);
        }
Example #6
0
        private static Attribute ConvertToNotNull(XmlNhvmRuleConverterArgs rule)
        {
            NhvmNotNull      notNullRule   = (NhvmNotNull)rule.schemaRule;
            NotNullAttribute thisAttribute = new NotNullAttribute();

            log.Info("Converting to NotNullAttribute");

            if (notNullRule.message != null)
            {
                thisAttribute.Message = notNullRule.message;
            }
            AssignTagsFromString(thisAttribute, notNullRule.tags);

            return(thisAttribute);
        }
Example #7
0
        public void InjectWhenParameterIsReferenceType()
        {
            var typeName   = Guid.NewGuid().ToString("N");
            var methodName = Guid.NewGuid().ToString("N");

            AssemblyManager.Manage((assembly) =>
            {
                var notNullAttributeCtor = assembly.MainModule.Import(
                    typeof(NotNullAttribute).GetConstructor(Type.EmptyTypes));
                var attribute = new CustomAttribute(notNullAttributeCtor);
                var type      = AssemblyManager.AddType(assembly, typeName);

                var parameter = new ParameterDefinition(assembly.MainModule.Import(typeof(object)));
                parameter.CustomAttributes.Add(attribute);

                var method = AssemblyManager.AddMethod(type, methodName,
                                                       new List <ParameterDefinition> {
                    parameter
                },
                                                       null);

                var processor = method.Body.GetILProcessor();
                processor.Append(Instruction.Create(OpCodes.Ret));
            }, (assembly) =>
            {
                var injector = new NotNullAttribute();

                var targetMethod = (from type in assembly.MainModule.GetAllTypes()
                                    where type.Name == typeName
                                    from method in type.GetMethods()
                                    where method.Name == methodName
                                    select method).First();

                Assert.AreEqual(1, targetMethod.Body.Instructions.Count);
                injector.Inject(targetMethod.Parameters[0]);
                var instructions = targetMethod.Body.Instructions;
                Assert.AreEqual(6, instructions.Count);
                Assert.AreEqual(OpCodes.Ldarg, instructions[0].OpCode);
                Assert.AreEqual(OpCodes.Brtrue_S, instructions[1].OpCode);
                Assert.AreEqual(OpCodes.Ldstr, instructions[2].OpCode);
                Assert.AreEqual(OpCodes.Newobj, instructions[3].OpCode);
                Assert.AreEqual(OpCodes.Throw, instructions[4].OpCode);
                Assert.AreEqual(OpCodes.Ret, instructions[5].OpCode);
            }, false);
        }
Example #8
0
        /// <summary>
        /// Configures additional attributes for an option item or option group, such as collapsed state and group visibility.
        /// </summary>
        /// <param name="item">The item or group to configure.</param>
        /// <param name="propertyInfo">The associated property info.</param>
        protected virtual void ConfigureItem(IOptionItem item, PropertyInfo propertyInfo)
        {
            NullableAttribute nullableAttribute =
                (NullableAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(NullableAttribute));

            if (nullableAttribute != null)
            {
                item.Attributes[OptionItem.SupportNullValueAttribute] = nullableAttribute.IsNullable;
            }
            else
            {
                CanBeNullAttribute canBeNull =
                    (CanBeNullAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(CanBeNullAttribute));
                NotNullAttribute notNull =
                    (NotNullAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(NotNullAttribute));
                if (canBeNull != null)
                {
                    item.Attributes[OptionItem.SupportNullValueAttribute] = true;
                }
                else if (notNull != null)
                {
                    item.Attributes[OptionItem.SupportNullValueAttribute] = false;
                }
            }

            DescriptionAttribute attribute = GetAttribute <DescriptionAttribute>(propertyInfo);

            if (attribute != null && !attribute.IsDefaultAttribute())
            {
                item.Attributes[OptionItem.DescriptionAttribute] = attribute.Description;
            }

            var customAttributes = Attribute.GetCustomAttributes(propertyInfo);

            foreach (var attrib in customAttributes.OfType <OptionItemAttributeAttribute>())
            {
                item.Attributes[attrib.Name] = attrib.Value;
            }
        }
        private void WriteRequireNotNull(ILWriter writer, PropertyInfo property, NotNullAttribute notNullAttribute)
        {
            if (property.PropertyType.IsClass || property.PropertyType.IsInterface)
            {
                writer.LoadFirstParameter();
                writer.GetPropertyValue(property);
                writer.LoadNull();
                var elseLabel = writer.IfEqualThen();

                var message = CommonResults.PropertyCannotBeNull.WithValues(property.ReflectedType.Name, property.Name);
                WriteFailureResult(writer, ValidationKind.RequireNotNull, message);
                writer.Return();

                writer.MarkLabel(elseLabel);
            }
            else
            {
                //Value types, pointers, everything that can't be null is here
                WriteNotApplicableResult(writer, ValidationKind.RequireNotNull);
                writer.Return();
            }
        }
Example #10
0
        /// <summary>
        /// Возвращает значение, показывающее является ли значение элемента управления допустимым
        /// </summary>
        /// <returns></returns>
        protected virtual bool ValidateData(out string message)
        {
            message = "";
            foreach (Control control in panelControls.Controls)
            {
                if (control is ThresholdControl)
                {
                    return(((ThresholdControl)control).ValidateData());
                }
                if (control is ComboBox)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    NotNullAttribute notNullAttribute =
                        (NotNullAttribute)propertyInfo.GetCustomAttributes(typeof(NotNullAttribute), false).FirstOrDefault();

                    object controlVal = ((ComboBox)control).SelectedItem;
                    if (controlVal == null && notNullAttribute != null)
                    {
                        if (message != "")
                        {
                            message += "\n ";
                        }
                        ExcelImportAttribute fca = (ExcelImportAttribute)
                                                   propertyInfo.GetCustomAttributes(typeof(ExcelImportAttribute), false).First();
                        message += $"'{fca.Title}' should not be empty";
                        return(false);
                    }
                }
            }

            return(true);
        }
        public void KnownRulesConvertAssing()
        {
            NhvMapping       map = XmlMappingLoader.GetXmlMappingFor(typeof(WellKnownRules));
            NhvmClass        cm  = map.@class[0];
            XmlClassMapping  rm  = new XmlClassMapping(cm);
            MemberInfo       mi;
            List <Attribute> attributes;

            mi         = typeof(WellKnownRules).GetField("AP");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual("A string value", ((ACustomAttribute)attributes[0]).Value1);
            Assert.AreEqual(123, ((ACustomAttribute)attributes[0]).Value2);
            Assert.AreEqual("custom message", ((ACustomAttribute)attributes[0]).Message);

            mi         = typeof(WellKnownRules).GetField("StrProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            NotEmptyAttribute nea = FindAttribute <NotEmptyAttribute>(attributes);

            Assert.AreEqual("not-empty message", nea.Message);

            NotNullAttribute nna = FindAttribute <NotNullAttribute>(attributes);

            Assert.AreEqual("not-null message", nna.Message);

            NotNullNotEmptyAttribute nnea = FindAttribute <NotNullNotEmptyAttribute>(attributes);

            Assert.AreEqual("notnullnotempty message", nnea.Message);

            LengthAttribute la = FindAttribute <LengthAttribute>(attributes);

            Assert.AreEqual("length message", la.Message);
            Assert.AreEqual(1, la.Min);
            Assert.AreEqual(10, la.Max);

            PatternAttribute pa = FindAttribute <PatternAttribute>(attributes);

            Assert.AreEqual("pattern message", pa.Message);
            Assert.AreEqual("[0-9]+", pa.Regex);
            Assert.AreEqual(RegexOptions.Compiled, pa.Flags);

            EmailAttribute ea = FindAttribute <EmailAttribute>(attributes);

            Assert.AreEqual("email message", ea.Message);

            IPAddressAttribute ipa = FindAttribute <IPAddressAttribute>(attributes);

            Assert.AreEqual("ipAddress message", ipa.Message);

            EANAttribute enaa = FindAttribute <EANAttribute>(attributes);

            Assert.AreEqual("ean message", enaa.Message);

            CreditCardNumberAttribute ccna = FindAttribute <CreditCardNumberAttribute>(attributes);

            Assert.AreEqual("creditcardnumber message", ccna.Message);

            IBANAttribute iban = FindAttribute <IBANAttribute>(attributes);

            Assert.AreEqual("iban message", iban.Message);

            mi         = typeof(WellKnownRules).GetField("DtProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            FutureAttribute fa = FindAttribute <FutureAttribute>(attributes);

            Assert.AreEqual("future message", fa.Message);
            PastAttribute psa = FindAttribute <PastAttribute>(attributes);

            Assert.AreEqual("past message", psa.Message);

            mi         = typeof(WellKnownRules).GetField("DecProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            DigitsAttribute dga = FindAttribute <DigitsAttribute>(attributes);

            Assert.AreEqual("digits message", dga.Message);
            Assert.AreEqual(5, dga.IntegerDigits);
            Assert.AreEqual(2, dga.FractionalDigits);

            MinAttribute mina = FindAttribute <MinAttribute>(attributes);

            Assert.AreEqual("min message", mina.Message);
            Assert.AreEqual(100, mina.Value);

            MaxAttribute maxa = FindAttribute <MaxAttribute>(attributes);

            Assert.AreEqual("max message", maxa.Message);
            Assert.AreEqual(200, maxa.Value);

            DecimalMaxAttribute decimalmaxa = FindAttribute <DecimalMaxAttribute>(attributes);

            Assert.AreEqual("decimal max message", decimalmaxa.Message);
            Assert.AreEqual(200.1m, decimalmaxa.Value);

            DecimalMinAttribute decimalmina = FindAttribute <DecimalMinAttribute>(attributes);

            Assert.AreEqual("decimal min message", decimalmina.Message);
            Assert.AreEqual(99.9m, decimalmina.Value);

            mi         = typeof(WellKnownRules).GetField("BProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            AssertTrueAttribute ata = FindAttribute <AssertTrueAttribute>(attributes);

            Assert.AreEqual("asserttrue message", ata.Message);
            AssertFalseAttribute afa = FindAttribute <AssertFalseAttribute>(attributes);

            Assert.AreEqual("assertfalse message", afa.Message);


            mi         = typeof(WellKnownRules).GetField("ArrProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            SizeAttribute sa = FindAttribute <SizeAttribute>(attributes);

            Assert.AreEqual("size message", sa.Message);
            Assert.AreEqual(2, sa.Min);
            Assert.AreEqual(9, sa.Max);

            mi         = typeof(WellKnownRules).GetField("Pattern");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            PatternAttribute spa = FindAttribute <PatternAttribute>(attributes);

            Assert.AreEqual("{validator.pattern}", spa.Message);
            Assert.AreEqual(@"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", spa.Regex);
            Assert.AreEqual(RegexOptions.CultureInvariant | RegexOptions.IgnoreCase, spa.Flags);
        }
 public void SetUp()
 {
     _attribute = new NotNullAttribute();
 }
Example #13
0
        /// <summary>
        /// Возвращает значение, показывающее является ли значение элемента управления допустимым
        /// </summary>
        /// <returns></returns>
        protected virtual bool ValidateData(out string message)
        {
            message = "";
            foreach (Control control in _importingControls)
            {
                if (control is TextBox)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    if (propertyInfo.PropertyType.Name.ToLower() != "string")
                    {
                        continue;
                    }

                    string controlVal = control.Text;

                    NotNullAttribute notNullAttribute =
                        (NotNullAttribute)propertyInfo.GetCustomAttributes(typeof(NotNullAttribute), false).FirstOrDefault();
                    if (controlVal == null || (notNullAttribute != null && controlVal.Trim() == ""))
                    {
                        if (message != "")
                        {
                            message += "\n ";
                        }
                        ExcelImportAttribute fca = (ExcelImportAttribute)
                                                   propertyInfo.GetCustomAttributes(typeof(ExcelImportAttribute), false).First();
                        message += $"'{fca.Title}' should not be empty";
                        return(false);
                    }
                }
                if (control is RichTextBox)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    if (propertyInfo.PropertyType.Name.ToLower() != "string")
                    {
                        continue;
                    }

                    string controlVal = ((RichTextBox)control).Rtf;

                    NotNullAttribute notNullAttribute =
                        (NotNullAttribute)propertyInfo.GetCustomAttributes(typeof(NotNullAttribute), false).FirstOrDefault();
                    if (controlVal == null || (notNullAttribute != null && controlVal.Trim() == ""))
                    {
                        if (message != "")
                        {
                            message += "\n ";
                        }
                        ExcelImportAttribute fca = (ExcelImportAttribute)
                                                   propertyInfo.GetCustomAttributes(typeof(ExcelImportAttribute), false).First();
                        message += $"'{fca.Title}' should not be empty";
                        return(false);
                    }
                }
                //if (control is NumericUpDown && control.Tag != null)
                //{
                //    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                //    if (propertyInfo == null) continue;

                //    string typeName = propertyInfo.PropertyType.Name.ToLower();
                //    switch (typeName)
                //    {
                //        case "int32":
                //            {
                //                int val = (int)propertyInfo.GetValue(obj, null);
                //                int controlVal = (int)((NumericUpDown)control).Value;
                //                if (val != controlVal)
                //                    return true;

                //                break;
                //            }
                //        case "int16":
                //            {
                //                Int16 val = (Int16)propertyInfo.GetValue(obj, null);
                //                Int16 controlVal = (Int16)((NumericUpDown)control).Value;
                //                if (val != controlVal)
                //                    return true;

                //                break;
                //            }
                //        case "double":
                //            {
                //                double val = (double)propertyInfo.GetValue(obj, null);
                //                double controlVal = (double)((NumericUpDown)control).Value;
                //                if (val != controlVal)
                //                    return true;

                //                break;
                //            }
                //    }
                //}
                //if (control is DateTimePicker)
                //{
                //    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                //    if (propertyInfo == null) continue;

                //    DateTime val = (DateTime)propertyInfo.GetValue(obj, null);
                //    if (val != ((DateTimePicker)control).Value)
                //        return true;
                //}
                //if (control is CheckBox)
                //{
                //    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                //    if (propertyInfo == null) continue;

                //    bool val = (bool)propertyInfo.GetValue(obj, null);
                //    bool controlVal = ((CheckBox)control).Checked;
                //    if (val != controlVal)
                //        return true;
                //}
                if (control is AttachedFileControl)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    string m;
                    if (((AttachedFileControl)control).ValidateData(out m))
                    {
                        return(true);
                    }
                    if (m != "")
                    {
                        message += "\n ";
                    }

                    message += "Not set " + propertyInfo.Name;
                    return(false);
                }
                //if (control is LifelengthViewer)
                //{
                //    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                //    if (propertyInfo == null) continue;

                //    Lifelength val = (Lifelength)propertyInfo.GetValue(obj, null);
                //    Lifelength controlVal = ((LifelengthViewer)control).Lifelength;
                //    if (!val.IsEqual(controlVal))
                //        return true;
                //}
                if (control is DictionaryComboBox)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    object controlVal = ((DictionaryComboBox)control).SelectedItem;
                    if (controlVal == null)
                    {
                        if (message != "")
                        {
                            message += "\n ";
                        }

                        message += "Not set " + propertyInfo.Name;
                        return(false);
                    }
                }
                //if (control is ThresholdControl)
                //{
                //    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                //    if (propertyInfo == null) continue;

                //    object val = propertyInfo.GetValue(obj, null);
                //    object controlVal = ((ThresholdControl)control).Threshold;
                //    if (val.ToString() != controlVal.ToString())
                //        return true;
                //}
                if (control is ComboBox)
                {
                    PropertyInfo propertyInfo = control.Tag as PropertyInfo;
                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    object controlVal = ((ComboBox)control).SelectedItem;
                    if (controlVal == null)
                    {
                        if (message != "")
                        {
                            message += "\n ";
                        }

                        message += "Not set " + propertyInfo.Name;
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        protected void UpdateControl()
        {
            Text = $"{_typeToImport.Name} Import Form";

            panelControls.Controls.Clear();

            if (_typeToImport == null)
            {
                return;
            }

            List <PropertyInfo> properties = GetTypeProperties(_typeToImport);

            if (properties.Count == 0)
            {
                return;
            }

            int columnCount = 1;//количество колонок ЭУ

            List <Label>   labels   = new List <Label>();
            List <Control> controls = new List <Control>();
            Dictionary <PropertyInfo, Control> pairControls = new Dictionary <PropertyInfo, Control>();
            string errorMessage = "";

            foreach (PropertyInfo t in properties)
            {
                PropertyInfo         pairProperty = null;
                ExcelImportAttribute attr         =
                    (ExcelImportAttribute)t.GetCustomAttributes(typeof(ExcelImportAttribute), false).First();
                labels.Add(new Label {
                    Text = attr.Title, AutoSize = true
                });

                //Если значение должно быть не пустым или не NULL
                //то шрифт леибла утснанавливается в ЖИРНЫЙ(BOLD)
                NotNullAttribute notNullAttribute =
                    (NotNullAttribute)t.GetCustomAttributes(typeof(NotNullAttribute), false).FirstOrDefault();
                if (notNullAttribute != null)
                {
                    labels.Last().Font = new Font(labels.Last().Font, FontStyle.Bold);
                }

                Control c = null;
                if (!string.IsNullOrEmpty(attr.PairControlPropertyName))
                {
                    pairProperty = _typeToImport.GetProperty(attr.PairControlPropertyName);
                }

                if (pairProperty != null)
                {
                    try
                    {
                        c = GetControl(pairProperty, attr.PairControlWidht, attr.PairControlEnabled);
                    }
                    catch (Exception ex)
                    {
                        if (errorMessage != "")
                        {
                            errorMessage += "\n ";
                        }
                        errorMessage += $"Pair property '{attr.PairControlPropertyName}' raise error {ex.Message}";
                    }
                    if (c is ThresholdControl)
                    {
                        columnCount = 2;
                    }
                    pairControls.Add(t, c);
                }

                c = null;

                try
                {
                    int cw = pairProperty != null ? attr.Width - attr.PairControlWidht - 5 : attr.Width;
                    c = GetControl(t, cw, true);
                }
                catch (Exception ex)
                {
                    if (errorMessage != "")
                    {
                        errorMessage += "\n ";
                    }
                    errorMessage += $"'{attr.Title}' raise error {ex.Message}";
                }
                if (c is LifelengthViewer)
                {
                    ((LifelengthViewer)c).LeftHeader = attr.Title;
                }
                if (c is ThresholdControl)
                {
                    columnCount = 2;
                }
                controls.Add(c);
            }

            #region Компоновка контролов в одну колонку
            if (columnCount == 1)
            {
                #region расчет длины лейблов и контролов

                int maxLabelXSize   = 0;
                int maxControlXSize = 0;//максимальная длиня ЭУ
                for (int i = 0; i < labels.Count; i++)
                {
                    //на каждый лейбл приходится по одному контролу,
                    //поэтому обе коллекции просматриваются одновременно
                    if (controls[i] != null && controls[i] is LifelengthViewer)
                    {
                        LifelengthViewer llv = (LifelengthViewer)controls[i];
                        if (llv.LeftHeaderWidth > maxLabelXSize)
                        {
                            maxLabelXSize = llv.LeftHeaderWidth;
                        }
                        if (llv.WidthWithoutLeftHeader > maxControlXSize)
                        {
                            maxControlXSize = llv.WidthWithoutLeftHeader;
                        }
                        if (i > 0 && controls[i - 1] != null && controls[i - 1] is LifelengthViewer)
                        {
                            llv.ShowHeaders = false;
                        }
                        continue;
                    }
                    //выше рассматривались контролы, имеющие собственные лейблы
                    //теперь идет просмотр самих леблов
                    if (labels[i].PreferredWidth > maxLabelXSize)
                    {
                        maxLabelXSize = labels[i].PreferredWidth;
                    }
                    //размеры контролов
                    if (controls[i] != null && controls[i].Size.Width > maxControlXSize)
                    {
                        maxControlXSize = controls[i].Size.Width;
                    }
                }
                #endregion

                for (int i = 0; i < properties.Count; i++)
                {
                    Control pairControl = null;
                    if (pairControls.ContainsKey(properties[i]))
                    {
                        pairControl = pairControls[properties[i]];
                    }

                    if (i == 0)
                    {
                        labels[i].Location = new Point(3, 3);
                        if (controls[i] != null)
                        {
                            if (controls[i] is LifelengthViewer)
                            {
                                controls[i].Location =
                                    new Point((maxLabelXSize + labels[i].Location.X) - ((LifelengthViewer)controls[i]).LeftHeaderWidth, 3);
                            }
                            else
                            {
                                if (pairControl != null)
                                {
                                    pairControl.Location = new Point(maxLabelXSize + labels[i].Location.X + 5, 3);

                                    controls[i].Location = new Point(pairControl.Location.X + pairControl.Size.Width + 5, 3);
                                    controls[i].Width    = maxControlXSize - (pairControl.Size.Width + 5);
                                }
                                else
                                {
                                    controls[i].Location = new Point(maxLabelXSize + labels[i].Location.X + 5, 3);
                                    controls[i].Width    = maxControlXSize;
                                }
                            }
                        }
                    }
                    else
                    {
                        Point labelLocation = new Point(3, 0);
                        if (controls[i - 1] != null)
                        {
                            labelLocation.Y = controls[i - 1].Location.Y + controls[i - 1].Size.Height + 5;
                        }
                        else
                        {
                            labelLocation.Y = labels[i - 1].Location.Y + labels[i - 1].Size.Height + 5;
                        }

                        labels[i].Location = labelLocation;
                        if (controls[i] != null)
                        {
                            if (controls[i] is LifelengthViewer)
                            {
                                controls[i].Location =
                                    new Point((maxLabelXSize + labelLocation.X) - ((LifelengthViewer)controls[i]).LeftHeaderWidth, labelLocation.Y);
                            }
                            else
                            {
                                if (pairControl != null)
                                {
                                    pairControl.Location = new Point(maxLabelXSize + labelLocation.X + 5, labelLocation.Y);

                                    controls[i].Location = new Point(pairControl.Location.X + pairControl.Size.Width + 5, labelLocation.Y);
                                    controls[i].Width    = maxControlXSize - (pairControl.Size.Width + 5);
                                }
                                else
                                {
                                    controls[i].Location = new Point(maxLabelXSize + labelLocation.X + 5, labelLocation.Y);
                                    controls[i].Width    = maxControlXSize;
                                }
                            }
                        }
                    }


                    if (controls[i] == null || (controls[i] != null && !(controls[i] is LifelengthViewer)))
                    {
                        //Если контрол не является LifelengthViewer-ом то нужно добавить лейбл
                        panelControls.Controls.Add(labels[i]);
                    }
                    if (pairControl != null)
                    {
                        panelControls.Controls.Add(pairControl);
                    }

                    panelControls.Controls.Add(controls[i]);
                }
            }
            #endregion

            #region Компоновка контролов в две колонки
            if (columnCount == 2)
            {
                #region расчет длины лейблов и контролов

                int  fMaxLabelXSize = 0, sMaxLabelXSize = 0;
                int  fMaxControlXSize = 0, sMaxControlXSize = 0;
                bool checkFirst = true;//флаг проверяемой колонки

                for (int i = 0; i < labels.Count; i++)
                {
                    //на каждый лейбл приходится по одному контролу,
                    //поэтому обе коллекции просматриваются одновременно
                    if (controls[i] != null && controls[i] is ThresholdControl)
                    {
                        //контрол порога выполнения директивы
                        //влияет на длину лейблов обоих колонок
                        ThresholdControl ddtc = (ThresholdControl)controls[i];
                        //размеры заголовков
                        if (ddtc.MaxFirstColLabelWidth > fMaxLabelXSize)
                        {
                            fMaxLabelXSize = ddtc.MaxFirstColLabelWidth;
                        }
                        if (ddtc.MaxSecondColLabelWidth > sMaxLabelXSize)
                        {
                            sMaxLabelXSize = ddtc.MaxSecondColLabelWidth;
                        }

                        //размеры контролов
                        if (ddtc.MaxFirstColControlWidth > fMaxControlXSize)
                        {
                            fMaxControlXSize = ddtc.MaxFirstColControlWidth;
                        }
                        if (ddtc.MaxSecondColControlWidth > sMaxControlXSize)
                        {
                            sMaxControlXSize = ddtc.MaxSecondColControlWidth;
                        }

                        //т.к. DetailDirectiveThresholdControl занимает 2 колонки,
                        //то следующий контрол всегда будет располагаться в первой колонке
                        checkFirst = true;
                        continue;
                    }

                    if (controls[i] != null && controls[i] is LifelengthViewer)
                    {
                        LifelengthViewer llv = (LifelengthViewer)controls[i];

                        if (checkFirst && llv.LeftHeaderWidth > fMaxLabelXSize)
                        {
                            fMaxLabelXSize = llv.LeftHeaderWidth;
                        }
                        if (!checkFirst && llv.LeftHeaderWidth > sMaxLabelXSize)
                        {
                            sMaxLabelXSize = llv.LeftHeaderWidth;
                        }

                        //размеры контролов
                        if (checkFirst && llv.WidthWithoutLeftHeader > fMaxControlXSize)
                        {
                            fMaxControlXSize = llv.WidthWithoutLeftHeader;
                        }
                        if (!checkFirst && llv.WidthWithoutLeftHeader > sMaxControlXSize)
                        {
                            sMaxControlXSize = llv.WidthWithoutLeftHeader;
                        }

                        checkFirst = !checkFirst;
                        continue;
                    }

                    //выше рассматривались контролы, имеющие собственные лейблы
                    //теперь идет просмотр самих леблов
                    if (checkFirst && labels[i].PreferredWidth > fMaxLabelXSize)
                    {
                        fMaxLabelXSize = labels[i].PreferredWidth;
                    }
                    if (!checkFirst && labels[i].PreferredWidth > sMaxLabelXSize)
                    {
                        sMaxLabelXSize = labels[i].PreferredWidth;
                    }

                    //размеры контролов
                    if (controls[i] != null)
                    {
                        if (checkFirst && controls[i].Size.Width > fMaxControlXSize)
                        {
                            fMaxControlXSize = controls[i].Size.Width;
                        }
                        if (!checkFirst && controls[i].Size.Width > sMaxControlXSize)
                        {
                            sMaxControlXSize = controls[i].Size.Width;
                        }
                    }

                    checkFirst = !checkFirst;
                }
                #endregion

                checkFirst = true;
                const int firstCol  = 3;
                int       secondCol = (3 + fMaxLabelXSize + 5 + fMaxControlXSize + 50);
                for (int i = 0; i < labels.Count; i++)
                {
                    int top, left, labelSize, controlsize;
                    if (i == 0)
                    {
                        top         = 3;
                        left        = firstCol;
                        labelSize   = fMaxLabelXSize;
                        controlsize = fMaxControlXSize;
                    }
                    else
                    {
                        if (checkFirst ||
                            (controls[i] != null && controls[i] is ThresholdControl))
                        {
                            left        = firstCol;
                            labelSize   = fMaxLabelXSize;
                            controlsize = fMaxControlXSize;

                            //определение самого нижнего Bottoma 2-х предыдущих контролов
                            int bottom1, bottom2;
                            //определение нижней точки предыдущего контрола
                            //(он будет либо во второй колонке предыдущего ряда, либо занимать весь ряд)
                            if (controls[i - 1] != null)
                            {
                                bottom2 = controls[i - 1].Bottom + 5;
                            }
                            else
                            {
                                bottom2 = labels[i - 1].Bottom + 5;
                            }
                            //определение нижней точки пред-предыдущего контрола
                            //он может и отсутствовать
                            if ((i - 2) >= 0)
                            {
                                if (controls[i - 2] != null)
                                {
                                    bottom1 = controls[i - 2].Bottom + 5;
                                }
                                else
                                {
                                    bottom1 = labels[i - 2].Bottom + 5;
                                }
                            }
                            else
                            {
                                bottom1 = 0;
                            }

                            top = bottom1 > bottom2 ? bottom1 : bottom2;
                        }
                        else
                        {
                            left        = secondCol;
                            labelSize   = sMaxLabelXSize;
                            controlsize = sMaxControlXSize;

                            top = controls[i - 1] != null ? controls[i - 1].Location.Y : labels[i - 1].Location.Y;
                        }
                    }

                    if (controls[i] != null && controls[i] is ThresholdControl)
                    {
                        ThresholdControl ddtc = (ThresholdControl)controls[i];
                        controls[i].Location = new Point(3, top);
                        //выравнивание первой колонки
                        ddtc.SetFirstColumnPos(firstCol + fMaxLabelXSize);
                        //выравнивание второй колонки
                        ddtc.SetSecondColumnPos(secondCol + sMaxLabelXSize);

                        panelControls.Controls.Add(controls[i]);
                        checkFirst = true;
                        continue;
                    }

                    if (controls[i] != null && controls[i] is LifelengthViewer)
                    {
                        controls[i].Location =
                            new Point((labelSize + left) - ((LifelengthViewer)controls[i]).LeftHeaderWidth, top);
                        panelControls.Controls.Add(controls[i]);
                        checkFirst = !checkFirst;
                        continue;
                    }

                    labels[i].Location = new Point(left, top);
                    if (controls[i] != null)
                    {
                        controls[i].Location = new Point(labelSize + left + 5, top);
                        controls[i].Width    = controlsize;
                    }
                    panelControls.Controls.Add(labels[i]);
                    panelControls.Controls.Add(controls[i]);
                    checkFirst = !checkFirst;
                }
            }
            #endregion

            if (errorMessage != "")
            {
                MessageBox.Show(errorMessage, (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }