public object GetTargetObject() { try { var stripped = ReflectionMethods.StripIndexer(TargetName); return(ParentType.GetRuntimeProperty(stripped).GetValue(ParentObject)); } catch (Exception) { return(null); } }
private static GetObjectResult GetObject(object parent, string propertyName, string inputName, bool includeStatics) { var result = new GetObjectResult { PropertyName = propertyName, Input = parent, InputName = inputName }; var isEnumerable = ReflectionMethods.EnumerablePattern.IsMatch(propertyName); var stripped = ReflectionMethods.StripIndexer(propertyName); var propInfo = parent .GetType() .GetPublicProperties(includeStatics) .FirstOrDefault(p => ReflectionMethods.NameMatch(p, stripped)); var propVal = propInfo?.GetValue(parent); if (isEnumerable) { result.Property = propVal; var index = ReflectionMethods.GetIndexerValue(propertyName); if (index == null) { return(null); } var item = ReflectionMethods.GetItem(propVal, index.Value); if (item == null) { return(null); } result.Leaf = item; } else { result.Property = parent; result.Leaf = propVal; } result.PropertyInfo = result.Input.GetType().GetProperty(stripped); return(result); }