Exemple #1
0
        public object Do(PropertyInfo info, string tableValue)
        {
            var tableValueNoBrackets = ListHelper.NoBrackets(tableValue);

            var tableValueEntries = CsvHelper.Split(tableValueNoBrackets);

            // This will allow PlainLists to work.
            Type innerType = typeof(object);

            if (info.PropertyType.IsGenericType)
            {
                innerType = info.PropertyType.GetGenericArguments()[0];
            }

            // Custom List to Return
            Type  customList = typeof(List <>).MakeGenericType(innerType);
            IList objectList = (IList)Activator.CreateInstance(customList);

            var propertyInfo = InstantProperty.FromType(innerType);

            foreach (var tableValueEntry in tableValueEntries)
            {
                var item = Translator.Translate(propertyInfo, tableValueEntry);

                objectList.Add(item);
            }

            return(objectList);
        }
        public object Do(PropertyInfo info, string tableValue)
        {
            var tableValueNoBrackets = ListHelper.NoBrackets(tableValue);

            var tableValueEntries = CsvHelper.Split(tableValueNoBrackets);

            var numEntries = tableValueEntries.Count;
            var baseType   = info.PropertyType.GetElementType();

            var array = Array.CreateInstance(baseType, numEntries);

            var propertyInfo = InstantProperty.FromType(baseType);

            for (int i = 0; i < numEntries; i++)
            {
                var expectedValue = Translator.Translate(propertyInfo, tableValueEntries[i]);
                array.SetValue(expectedValue, i);
            }

            return(array);
        }