コード例 #1
0
        public static SelectionRule GetRule(this IPropertiesContainer container, IThreatModel model = null)
        {
            SelectionRule result = null;

            if (model == null && container is IThreatModelChild child)
            {
                model = child.Model;
            }

            if (model != null)
            {
                var schemaManager = new AutoGenRulesPropertySchemaManager(model);
                var propertyType  = schemaManager.GetPropertyType();
                if (container.HasProperty(propertyType))
                {
                    if (container.GetProperty(propertyType) is IPropertyJsonSerializableObject jsonSerializableObject)
                    {
                        result = jsonSerializableObject.Value as SelectionRule;
                    }
                }
                else
                {
                    var oldSchema       = model.GetSchema(OldSchemaName, Properties.Resources.DefaultNamespace);
                    var oldPropertyType = oldSchema?.GetPropertyType(OldPropertyName);
                    if (oldPropertyType != null)
                    {
                        if (container.GetProperty(oldPropertyType) is IPropertyJsonSerializableObject
                            jsonSerializableObject)
                        {
                            result = jsonSerializableObject.Value as SelectionRule;
                            container.AddProperty(propertyType, jsonSerializableObject.StringValue);
                            container.RemoveProperty(oldPropertyType);
                        }
                    }
                }
            }

            return(result);
        }