public bool TryConvertTo(Type type, string stringValue, out object converted) { var listTypeBuilder = new ListTypeBuilder(type); // Gets the T from IEnumerable<T>. Type listType = listTypeBuilder.GetItemType(); if (listType == null) { throw new NotSupportedException("Property is marked as list but does not implement IEnumerable<T>."); } foreach (string listItem in stringValue.Split(new[] { seperator }, StringSplitOptions.None)) { object convertedItem; if (!itemConverter.TryConvertTo(listType, listItem, out convertedItem)) { throw new NotSupportedException($"No suitable conversion exists to convert to '{listType.FullName}'."); } listTypeBuilder.Add(convertedItem); } converted = listTypeBuilder.Build(); return(true); }
public bool TryConvertTo(Type type, string stringValue, out object converted) { var listTypeBuilder = new ListTypeBuilder(type); // Gets the T from IEnumerable<T>. Type listType = listTypeBuilder.GetItemType(); if (listType == null) { throw new NotSupportedException("Property is marked as list but does not implement IEnumerable<T>."); } foreach (string listItem in stringValue.Split(new[] { seperator }, StringSplitOptions.None)) { object convertedItem; if (!itemConverter.TryConvertTo(listType, listItem, out convertedItem)) { throw new NotSupportedException($"No suitable conversion exists to convert to '{listType.FullName}'."); } listTypeBuilder.Add(convertedItem); } converted = listTypeBuilder.Build(); return true; }