Exemplo n.º 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)
                    });
                }
            }
        }
Exemplo n.º 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
            });
        }
Exemplo n.º 3
0
 private static ReflectionException GuardPropertyIsSet(string property)
 {
     if (property == null)
     {
         return(ReflectionException.NoPropertyAvailable());
     }
     return(null);
 }
Exemplo n.º 4
0
 private static ReflectionPropertyResult GuardSource(string property, object source)
 {
     if (source == null)
     {
         return(new ReflectionPropertyResult {
             ReflectionException = ReflectionException.NoSourceAvailable(property)
         });
     }
     return(null);
 }
Exemplo n.º 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
            });
        }
Exemplo n.º 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)
         });
     }
 }
Exemplo n.º 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)
         });
     }
 }
Exemplo n.º 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)
                });
            }
        }
Exemplo n.º 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)
         });
     }
 }
Exemplo n.º 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)
                });
            }
        }
Exemplo n.º 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)
         });
     }
 }
Exemplo n.º 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)
                });
            }
        }
Exemplo n.º 13
0
 public static ReflectionExceptionWithContext DecorateWithContext(ReflectionException re, ParseContext context)
 {
     return(ReflectionExceptionWithContext.MakePartial(new ReflectionExceptionWithContext(re.Message, re)).Decorate(context));
 }
Exemplo n.º 14
0
 public object this[string property]
 {
     get { return(_backing[property]); }
     set { throw ReflectionException.SetNotAvailableInForkedModel(property); }
 }
Exemplo n.º 15
0
 private static ReflectionResult SetEnumerable(string property, object source, object value)
 {
     return(new ReflectionResult {
         ReflectionException = ReflectionException.SetNotAvailable("Enumerable")
     });
 }
Exemplo n.º 16
0
 public static ReflectionExceptionWithContext DecorateWithContext(ReflectionException re, ParseContext context)
 {
     return ReflectionExceptionWithContext.MakePartial(new ReflectionExceptionWithContext(re.Message)).Decorate(context);
 }
Exemplo n.º 17
0
 private static ReflectionResult SetNameValueCollection(string property, object source, object value)
 {
     return(new ReflectionResult {
         ReflectionException = ReflectionException.SetNotAvailable("NameValueCollection")
     });
 }