コード例 #1
0
        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));
        }
コード例 #2
0
        private object ConvertElement(string x, Type elementType)
        {
            if (string.IsNullOrEmpty(x))
            {
                return(null);
            }

            return(_parameterConverter.Convert(x, elementType));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }