public static void SetRule(this IPropertiesContainer container, SelectionRule rule, IThreatModel model = null) { if (model == null && container is IThreatModelChild child) { model = child.Model; } if (model != null) { var schemaManager = new AutoGenRulesPropertySchemaManager(model); var propertyType = schemaManager.GetPropertyType(); var property = container.GetProperty(propertyType) ?? container.AddProperty(propertyType, null); if (property is IPropertyJsonSerializableObject jsonSerializableObject) { jsonSerializableObject.Value = rule; } } }
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); }