private static PropertyPathInfo GetPropertyPathInfoRecursive(Type targetType, List <string> splitPropertyPath) { if (splitPropertyPath.Count == 0) { return(null); } FieldInfo fieldInfo = GetField(targetType, splitPropertyPath[0]); if (fieldInfo == null) { return(null); } if (splitPropertyPath.Count > 2 && splitPropertyPath[1] == "Array") { string index = new string(splitPropertyPath[2].Where(char.IsDigit).ToArray()); if (splitPropertyPath[2].Replace(index, "") == "data[]") { splitPropertyPath.RemoveRange(0, 3); PropertyPathInfo nextInfo = GetPropertyPathInfoRecursive(fieldInfo.FieldType.GetCollectionType(), splitPropertyPath); return(new PropertyPathInfo(fieldInfo, nextInfo, Convert.ToInt32(index))); } } splitPropertyPath.RemoveAt(0); return(new PropertyPathInfo(fieldInfo, GetPropertyPathInfoRecursive(fieldInfo.FieldType, splitPropertyPath))); }
public override string ToString() { if (_propertyPath != null) { return(_propertyPath); } StringBuilder builder = new StringBuilder(); PropertyPathInfo current = this; do { builder.Append($"{current.FieldInfo.Name}"); if (current.Index.HasValue) { builder.Append($"[{current.Index}]"); } current = current.Next; if (current == null) { break; } builder.Append("."); }while (true); _propertyPath = builder.ToString(); return(_propertyPath); }
internal PropertyPathInfo(FieldInfo fieldInfo, PropertyPathInfo next, int?index = null) { _propertyPath = null; FieldInfo = fieldInfo; Next = next; Index = index; }
public object GetScope([NotNull] Object context) { PropertyPathInfo propertyPathInfo = this; return(GetScopeInternal(ref propertyPathInfo, context)); }