Beispiel #1
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)
                    });
                }
            }
        }
Beispiel #2
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
            });
        }
Beispiel #3
0
 private static ReflectionException GuardPropertyIsSet(string property)
 {
     if (property == null)
     {
         return(ReflectionException.NoPropertyAvailable());
     }
     return(null);
 }
Beispiel #4
0
 private static ReflectionPropertyResult GuardSource(string property, object source)
 {
     if (source == null)
     {
         return(new ReflectionPropertyResult {
             ReflectionException = ReflectionException.NoSourceAvailable(property)
         });
     }
     return(null);
 }
Beispiel #5
0
        private static PropertyInfoResult InternalAcquirePropertyInfo(string property, Type type, object source = null)
        {
            PropertyInfo info = type.GetProperty(property);

            if (info == null)
            {
                return(new PropertyInfoResult
                {
                    ReflectionException = ReflectionException.PropertyNotFound(property, type, source)
                });
            }
            return(new PropertyInfoResult {
                PropertyInfo = info
            });
        }
Beispiel #6
0
 private static ReflectionResult GetNameValueCollection(string property, object source)
 {
     try
     {
         var sourceAsList = (NameValueCollection)source;
         return(new ReflectionResult {
             Result = sourceAsList[property]
         });
     }
     catch (KeyNotFoundException e)
     {
         return(new ReflectionResult
         {
             ReflectionException = ReflectionException.KeyNotFound(property)
         });
     }
 }
Beispiel #7
0
 private static ReflectionResult GetLookUpDictionary(string property, object source)
 {
     try
     {
         var sourceAsList = (IDictionary <string, object>)source;
         return(new ReflectionResult {
             Result = sourceAsList[property]
         });
     }
     catch (KeyNotFoundException e)
     {
         return(new ReflectionResult
         {
             ReflectionException = ReflectionException.KeyNotFound(property)
         });
     }
 }
Beispiel #8
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)
                });
            }
        }
Beispiel #9
0
 private static ReflectionResult GetJObject(string property, object source)
 {
     try
     {
         var json = (JObject)source;
         return(new ReflectionResult {
             Result = json[property]
         });
     }
     catch (KeyNotFoundException e)
     {
         return(new ReflectionResult
         {
             ReflectionException = ReflectionException.KeyNotFound(property)
         });
     }
 }
Beispiel #10
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)
                });
            }
        }
Beispiel #11
0
 private static ReflectionResult GetDictionary(string property, object source)
 {
     try
     {
         var sourceAsList = (IDictionary)source;
         var result       = new ReflectionResult {
             Result = sourceAsList[property]
         };
         if (result.Result == null)
         {
             result.Full = sourceAsList.Contains(property);
         }
         return(result);
     }
     catch (KeyNotFoundException e)
     {
         return(new ReflectionResult
         {
             ReflectionException = ReflectionException.KeyNotFound(property)
         });
     }
 }
Beispiel #12
0
        private static ReflectionResult GetIndexer(string property, object source)
        {
            var result = GetSimple(property, source);

            if (result.ReflectionException == null)
            {
                return(result);
            }
            try
            {
                var sourceAsList = (IHaveIndexer)source;
                return(new ReflectionResult {
                    Result = sourceAsList[property]
                });
            }
            catch (KeyNotFoundException e)
            {
                return(new ReflectionResult
                {
                    ReflectionException = ReflectionException.KeyNotFound(property)
                });
            }
        }
 public static ReflectionExceptionWithContext DecorateWithContext(ReflectionException re, ParseContext context)
 {
     return(ReflectionExceptionWithContext.MakePartial(new ReflectionExceptionWithContext(re.Message, re)).Decorate(context));
 }
Beispiel #14
0
 public object this[string property]
 {
     get { return(_backing[property]); }
     set { throw ReflectionException.SetNotAvailableInForkedModel(property); }
 }
Beispiel #15
0
 private static ReflectionResult SetEnumerable(string property, object source, object value)
 {
     return(new ReflectionResult {
         ReflectionException = ReflectionException.SetNotAvailable("Enumerable")
     });
 }
 public static ReflectionExceptionWithContext DecorateWithContext(ReflectionException re, ParseContext context)
 {
     return ReflectionExceptionWithContext.MakePartial(new ReflectionExceptionWithContext(re.Message)).Decorate(context);
 }
Beispiel #17
0
 private static ReflectionResult SetNameValueCollection(string property, object source, object value)
 {
     return(new ReflectionResult {
         ReflectionException = ReflectionException.SetNotAvailable("NameValueCollection")
     });
 }