/// <summary> /// Return value from path going from this object /// </summary> /// <param name="propertyPath"> Path formated like <ObjectReference>.<ListProperty>.<ListIndex>.<PropertyName> </param> /// <returns></returns> public NdfValueWrapper GetValueFromQuery(string query) { string rest = string.Empty; string next = NdfQueryReader.ParseNextStep(query, out rest); if (!string.IsNullOrEmpty(next)) { NdfPropertyValue nextproperty = GetProperty(next); if (nextproperty == null) { switch (nextproperty.Type) { case Types.NdfType.ObjectReference: NdfObjectReference reference = nextproperty.Value as NdfObjectReference; return reference.Instance.GetValueFromQuery(rest); case Types.NdfType.MapList: NdfMapList mapList = nextproperty.Value as NdfMapList; return mapList.GetValueFromQuery(rest); case Types.NdfType.List: NdfCollection list = nextproperty.Value as NdfCollection; return list.GetValueFromQuery(rest); default: return nextproperty.Value; } } } throw(new Exception("Something went wrong with this path: " + query != string.Empty ? query:"Empty Path")); }
/// <summary> /// Return true if it succeded getting a property from the query and output it. /// </summary> /// <param name="query"></param> /// <param name="value"></param> /// <returns></returns> public bool TryGetValueFromQuery(string query, out NdfValueWrapper value) { string rest = string.Empty; string next = NdfQueryReader.ParseNextStep(query, out rest); if(!string.IsNullOrEmpty(next)) { NdfPropertyValue nextproperty; if (TryGetProperty(next, out nextproperty)) { switch (nextproperty.Type) { case Types.NdfType.ObjectReference: NdfObjectReference reference = nextproperty.Value as NdfObjectReference; if (string.IsNullOrEmpty(rest)) { value = reference; return true; } return reference.Instance.TryGetValueFromQuery(rest, out value); case Types.NdfType.MapList: NdfMapList mapList = nextproperty.Value as NdfMapList; if (string.IsNullOrEmpty(rest)) { value = mapList; return true; } return mapList.TryGetValueFromQuery(rest, out value); case Types.NdfType.List: NdfCollection list = nextproperty.Value as NdfCollection; if (string.IsNullOrEmpty(rest)) { value = list; return true; } return list.TryGetValueFromQuery(rest, out value); case Types.NdfType.Unknown : break; case Types.NdfType.Unset: break; default: value = nextproperty.Value; return true; } } } value = null; return false; }