private object BuildTypedArray(string[][] rows, Type type) { var fieldNames = rows.First().Select(x => x.Trim()); var destinationType = type.GetElementType(); var setters = fieldNames.Select(f => destinationType.GetSetter(f)).ToArray(); var types = fieldNames.Select(f => destinationType.GetMemberType(f)).ToArray(); rows = rows.Skip(1).ToArray(); var items = new List <object>(); foreach (string[] currentRow in rows) { var instance = Activator.CreateInstance(destinationType); for (int column = 0; column < currentRow.Length; column++) { // create instance var value = _parameterConverter.Convert(currentRow[column], types[column]); setters[column](instance, value); } items.Add(instance); } return(_arrayBuilder.BuildArrayOfType(destinationType, items)); }
private object ConvertElement(string x, Type elementType) { if (string.IsNullOrEmpty(x)) { return(null); } return(_parameterConverter.Convert(x, elementType)); }
public object ConvertParamValue(string val, Type destinationType) { var rows = (string[][])new StorEvilTableConverter(_parameterConverter).ConvertParamValue(val, typeof(string[][])); var converted = Activator.CreateInstance(destinationType); foreach (var row in rows) { var name = row[0].Trim(); var propValue = row[1]; var memberType = destinationType.GetMemberType(name); converted.ReflectionSet(name, _parameterConverter.Convert(propValue, memberType)); } return(converted); }
public object ConvertParamValue(string val, Type destinationType) { var t = new ArrayList(); var elementType = destinationType.GetElementType(); var innerElementType = elementType.GetElementType(); var rows = val.Split(new[] { "\r\n" }, StringSplitOptions.None); foreach (var row in rows) { var values = row.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var destRow = new ArrayList(); foreach (var converted in values.Select(t1 => _converter.Convert(t1.Trim(), innerElementType))) { destRow.Add(converted); } t.Add(destRow.ToArray(innerElementType)); } return(t.ToArray(elementType)); }