/// <summary> /// Gets a mapping from a metadata field with multiple values on <see cref="ContentData"/> to a property on an instance of T. /// </summary> /// <typeparam name="T">The type that is being mapped to.</typeparam> /// <param name="propertyInfo">The property on T.</param> /// <param name="fieldName">The name of the metadata field with multiple values to map.</param> /// <returns>An <see cref="Action"/> that maps a single metadata field on <see cref="ContentData"/> to a single property on an instance of T.</returns> private static Action <ContentData, T> GetEnumerableMapping <T>(PropertyInfo propertyInfo, string fieldName) where T : new() { var mapToPropertyType = StringMapper.GetEnumerableMapping(propertyInfo.PropertyType); var setProperty = ExpressionUtil.GetPropertySetter <T>(propertyInfo); return((contentData, t) => { var metadata = GetMetadata(contentData, fieldName); var rawValues = metadata.Text.Split(metadata.Separator[0]); var values = mapToPropertyType(rawValues); setProperty(t, values); }); }
/// <summary> /// Gets a mapping from multiple matching elements Smart Form XML elements to a property on an instance of T. /// </summary> /// <typeparam name="T">The type being mapped to.</typeparam> /// <param name="propertyInfo">The property on T being mapped to.</param> /// <param name="xpath">The xpath for the field values being mapped.</param> /// <returns>An <see cref="Action"/> that maps an multiple matching fields from the Smart Form XML to a property on an instance of T.</returns> private static Action <XNode, T> GetEnumerableMapping <T>(PropertyInfo propertyInfo, string xpath) where T : new() { var mapToPropertyType = StringMapper.GetEnumerableMapping(propertyInfo.PropertyType); var setProperty = ExpressionUtil.GetPropertySetter <T>(propertyInfo); return((xml, t) => { var elements = xml.XPathSelectElements(xpath).ToList(); if (!elements.Any()) { return; } var rawValues = elements.Select(GetXmlInnerText).ToList(); var values = mapToPropertyType(rawValues); setProperty(t, values); }); }