private Operation CreateOperationFromAttribute( XElement element, ElementKind kind, XAttribute attribute, bool throwOnId = false) { string attributeName = attribute.LocalName(); if (throwOnId && DefaultComparer.NameEquals(attributeName, AttributeNames.Id)) { Throw(ErrorMessages.CannotUseOperationOnProperty(element, attributeName)); } PropertyDefinition property; string name = attribute.LocalName(); if (name == PropertyDefinition.TagsName) { property = PropertyDefinition.Tags; } else { property = GetProperty(attribute); } switch (kind) { case ElementKind.With: { return(new Operation(property, GetValue(attribute), _depth, OperationKind.With)); } case ElementKind.Without: { if (!property.IsCollection) { Throw(ErrorMessages.CannotUseOperationOnNonCollectionProperty(element, property.Name)); } return(new Operation(property, GetValue(attribute), _depth, OperationKind.Without)); } default: { Debug.Assert(kind == ElementKind.New, kind.ToString()); return(new Operation(property, GetValue(attribute), _depth, OperationKind.With)); } } }
private PropertyDefinition GetProperty(XAttribute attribute) { string propertyName = attribute.LocalName(); if (!Entity.TryGetProperty(propertyName, out PropertyDefinition property)) { Throw(ErrorMessages.PropertyIsNotDefined(propertyName), attribute); } return(property); }
private IPropertyOperation CreateOperationFromAttribute( XElement element, XAttribute attribute, bool throwOnId = false, bool throwOnTag = false, bool throwOnSet = false, bool throwOnAdd = false) { string attributeName = attribute.LocalName(); if (throwOnId && DefaultComparer.NameEquals(attributeName, AttributeNames.Id)) { Throw(ErrorMessages.CannotUseCommandOnProperty(element, attributeName)); } if (DefaultComparer.NameEquals(attributeName, AttributeNames.Tag)) { if (throwOnTag) { Throw(ErrorMessages.CannotUseCommandOnProperty(element, attributeName)); } return(new AddTagOperation(GetValue(attribute), Depth)); } PropertyDefinition property = GetProperty(attribute); if (property.IsCollection) { if (throwOnAdd) { Throw(ErrorMessages.CannotUseCommandOnCollectionProperty(element, property.Name)); } return(new AddItemOperation(property, GetValue(attribute), Depth)); } else { if (throwOnSet) { Throw(ErrorMessages.CannotUseCommandOnNonCollectionProperty(element, property.Name)); } return(new SetOperation(property, GetValue(attribute), Depth)); } }
private PropertyDefinition GetProperty(XAttribute attribute) { string propertyName = attribute.LocalName(); if (DefaultComparer.NameEquals(propertyName, PropertyDefinition.TagsName)) { return(PropertyDefinition.Tags); } if (_entityDefinition.TryGetProperty(propertyName, out PropertyDefinition property)) { return(property); } Throw(ErrorMessages.PropertyIsNotDefined(propertyName), attribute); return(null); }
public static bool NameEquals(XAttribute attribute, string name) { return(NameEquals(attribute.LocalName(), name)); }
private string GetAttributeName(XAttribute attribute) { return(attribute.LocalName()); }
public static string UnknownAttribute(XAttribute attribute) { return($"Element '{attribute.Parent?.LocalName()}' contains unknown attribute '{attribute.LocalName()}'."); }
private IPropertyOperation CreateOperationFromAttribute( XElement element, ElementKind kind, XAttribute attribute, char separator = ',', bool throwOnId = false, bool throwOnCollection = false) { string attributeName = attribute.LocalName(); if (throwOnId && DefaultComparer.NameEquals(attributeName, AttributeNames.Id)) { Throw(ErrorMessages.CannotUseOperationOnProperty(element, attributeName)); } PropertyDefinition property; string name = attribute.LocalName(); if (name == PropertyDefinition.TagsName) { property = PropertyDefinition.Tags; } else { property = GetProperty(attribute); } if (throwOnCollection && property.IsCollection) { Throw(ErrorMessages.CannotUseOperationOnCollectionProperty(element, property.Name)); } switch (kind) { case ElementKind.Add: return(new AddOperation(property, GetValue(attribute), Depth)); case ElementKind.AddRange: return(new AddRangeOperation(property, GetValue(attribute), separator, Depth)); case ElementKind.Remove: return(new RemoveOperation(property, GetValue(attribute), Depth)); case ElementKind.RemoveRange: return(new RemoveRangeOperation(property, GetValue(attribute), separator, Depth)); default: { Debug.Assert(kind == ElementKind.Set || kind == ElementKind.New, kind.ToString()); if (property.IsCollection) { return(new AddOperation(property, GetValue(attribute), Depth)); } else { return(new SetOperation(property, GetValue(attribute), Depth)); } } } }