public void Modify(XElement element, IModificationContext context) { if (element == null) { throw new ArgumentNullException("element"); } if (context == null) { throw new ArgumentNullException("context"); } if (element.Name != this.nameProvider.PropertyElement) { throw new ArgumentException("", "context"); } StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context); XAttribute typeAttribute = element.Attribute(this.nameProvider.TypeAttribute); Facet[] facets = null; string oldStorageType = typeAttribute.Value; string newStorageType = null; if (converter.TryConvertType(oldStorageType, out newStorageType, out facets)) { typeAttribute.Value = newStorageType; foreach (XName commonAttributeName in this.CommonPropertyAttributeNames) { if (element.Attribute(commonAttributeName) != null) { // Element contains the attribute continue; } // Seach for default facet value Facet facet = facets.FirstOrDefault(f => f.Name == commonAttributeName.LocalName); if (facet != null && facet.Value != null) { element.Add(new XAttribute(commonAttributeName, facet.Value)); } } } }
public void Modify(XAttribute attribute, IModificationContext context) { if (attribute == null) { throw new ArgumentNullException("attribute"); } if (context == null) { throw new ArgumentNullException("context"); } string oldStorageType = attribute.Value; StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context); // Try to get the collection value string pattern = @"Collection\(([^ \t]{1,}(?:\.[^ \\t]{1,}){0,})\)"; Match regex = Regex.Match(oldStorageType, pattern); bool isCollection = regex.Success; // If it was a collection type, get the inside value if (isCollection) { oldStorageType = regex.Groups[1].Value; } string newStorageType = null; Facet[] facets = null; if (converter.TryConvertType(oldStorageType, out newStorageType, out facets)) { if (isCollection) { attribute.Value = string.Format("Collection({0})", newStorageType); } else { attribute.Value = newStorageType; } } }
public void Modify(XAttribute attribute, IModificationContext context) { if (attribute == null) { throw new ArgumentNullException("attribute"); } if (context == null) { throw new ArgumentNullException("context"); } string oldStorageType = attribute.Value; StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context); string newStorageType = null; Facet[] facets; if (converter.TryConvertType(oldStorageType, out newStorageType, out facets)) { attribute.Value = newStorageType; } }