示例#1
0
        private static ReflectionResult GetEnumerable(string property, object source)
        {
            var sourceAsEnumerable = (IEnumerable)source;
            int index = -1;

            if (!int.TryParse(property, out index))
            {
                return(new ReflectionResult
                {
                    ReflectionException = ReflectionException.NumberIndexerExepected(source.GetType(), property)
                });
            }
            IEnumerator enumerator = sourceAsEnumerable.GetEnumerator();
            int         i          = 0;

            do
            {
                if (!enumerator.MoveNext())
                {
                    return(new ReflectionResult
                    {
                        ReflectionException = ReflectionException.IndexOutOfBounds(source.GetType(), index)
                    });
                }
                i++;
            } while (i <= index);
            return(new ReflectionResult {
                Result = enumerator.Current
            });
        }
示例#2
0
        private static ReflectionResult SetList(string property, object source, object value)
        {
            var sourceAsList = (IList)source;

            if (property.Equals("add"))
            {
                sourceAsList.Add(value);
                return(new ReflectionResult());
            }
            else
            {
                int index = int.Parse(property);
                try
                {
                    sourceAsList[index] = value;
                    return(new ReflectionResult());
                }
                catch (ArgumentOutOfRangeException)
                {
                    return(new ReflectionResult
                    {
                        ReflectionException = ReflectionException.IndexOutOfBounds(source.GetType(), index)
                    });
                }
            }
        }
示例#3
0
        private static ReflectionResult SetArray(string property, object source, object value)
        {
            var sourceAsArray = (Array)source;
            int index         = int.Parse(property);

            try
            {
                sourceAsArray.SetValue(value, index);
                return(new ReflectionResult());
            }
            catch (IndexOutOfRangeException)
            {
                return(new ReflectionResult {
                    ReflectionException = ReflectionException.IndexOutOfBounds(source.GetType(), index)
                });
            }
        }
示例#4
0
        private static ReflectionResult GetList(string property, object source)
        {
            var sourceAsList = (IList)source;
            int index        = int.Parse(property);

            try
            {
                return(new ReflectionResult {
                    Result = sourceAsList[index]
                });
            }
            catch (ArgumentOutOfRangeException)
            {
                return(new ReflectionResult
                {
                    ReflectionException = ReflectionException.IndexOutOfBounds(source.GetType(), index)
                });
            }
        }