Пример #1
0
        private IProperty InternalAddProperty(IThreatModel model, IPropertyType propertyType, string value)
        {
            IProperty result = null;

            var associatedClass = propertyType.GetType().GetCustomAttributes <AssociatedPropertyClassAttribute>()
                                  .FirstOrDefault();

            if (associatedClass != null)
            {
                var associatedClassType = Type.GetType(associatedClass.AssociatedType, false);
                if (associatedClassType != null)
                {
                    result = Activator.CreateInstance(associatedClassType, model, propertyType) as IProperty;
                }
            }

            if (result != null)
            {
                if (_properties == null)
                {
                    _properties = new List <IProperty>();
                }
                result.StringValue = value;
                _properties.Add(result);
                Dirty.IsDirty = true;
                _propertyAdded?.Invoke(PropertiesContainer?.Get(), result);
                result.Changed += OnPropertyChanged;
            }

            return(result);
        }
        private void AddGridRow([NotNull] IPropertyType propertyType, [NotNull] GridPanel panel)
        {
            if (_schemas.SelectedItem is IPropertySchema schema)
            {
                string context = null;
                bool   isList  = false;
                if (propertyType is IListPropertyType listPt)
                {
                    context = listPt.Context;
                    isList  = true;
                }
                else if (propertyType is IListMultiPropertyType listMultiPt)
                {
                    context = listMultiPt.Context;
                    isList  = true;
                }

                var row = new GridRow(
                    propertyType.Name,
                    propertyType.Description,
                    propertyType.GetType().GetEnumFromType <PropertyValueType>().GetEnumLabel(),
                    propertyType.Priority,
                    propertyType.Visible,
                    !propertyType.DoNotPrint,
                    propertyType.ReadOnly,
                    context)
                {
                    Tag       = propertyType,
                    AllowEdit = !schema.System || _promoted
                };

                row.Cells[7].AllowEdit = isList;

                ((INotifyPropertyChanged)propertyType).PropertyChanged += OnPropertyTypePropertyChanged;
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    row.Cells[i].PropertyChanged += OnPropertyChanged;
                }
                panel.Rows.Add(row);
            }
        }