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) }); } } }
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 }); }
private static ReflectionException GuardPropertyIsSet(string property) { if (property == null) { return(ReflectionException.NoPropertyAvailable()); } return(null); }
private static ReflectionPropertyResult GuardSource(string property, object source) { if (source == null) { return(new ReflectionPropertyResult { ReflectionException = ReflectionException.NoSourceAvailable(property) }); } return(null); }
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 }); }
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) }); } }
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) }); } }
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) }); } }
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) }); } }
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) }); } }
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) }); } }
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)); }
public object this[string property] { get { return(_backing[property]); } set { throw ReflectionException.SetNotAvailableInForkedModel(property); } }
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); }
private static ReflectionResult SetNameValueCollection(string property, object source, object value) { return(new ReflectionResult { ReflectionException = ReflectionException.SetNotAvailable("NameValueCollection") }); }