private IEnumerable <Command> CreateCommandFromElement(XElement element) { Debug.Assert(element.HasAttributes, element.ToString()); switch (element.LocalName()) { case ElementNames.Set: { foreach (XAttribute attribute in element.Attributes()) { yield return(CreateCommandFromAttribute(attribute)); } break; } case ElementNames.Append: { foreach (XAttribute attribute in element.Attributes()) { yield return(new AppendCommand(GetPropertyName(attribute), GetValue(attribute))); } break; } case ElementNames.Prefix: { foreach (XAttribute attribute in element.Attributes()) { yield return(new PrefixCommand(GetPropertyName(attribute), GetValue(attribute))); } break; } case ElementNames.Tag: { XAttribute attribute = element .Attributes() .FirstOrDefault(f => f.LocalName() == AttributeNames.Value); if (attribute != null) { yield return(new AddTagCommand(GetValue(attribute))); } break; } case ElementNames.Add: { foreach (XAttribute attribute in element.Attributes()) { string propertyName = GetAttributeName(attribute); PropertyDefinition property = Entity.FindProperty(propertyName); if (property == null) { Throw(ExceptionMessages.PropertyIsNotDefined(propertyName)); } else if (!property.IsCollection) { Throw(ExceptionMessages.CannotAddItemToNonCollectionProperty(propertyName)); } yield return(new AddItemCommand(propertyName, GetValue(attribute))); } break; } default: { Throw(ExceptionMessages.CommandIsNotDefined(element.LocalName())); break; } } }