Exemplo n.º 1
0
        public NdfValueWrapper GetValueFromQuery(string query)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(query, out rest);

            if (!string.IsNullOrEmpty(next))
            {
                NdfMap nextMap = GetMap(next);
                switch (nextMap.Type)
                {
                case NdfType.ObjectReference:
                    NdfObjectReference reference = nextMap.Value as NdfObjectReference;
                    return(reference.Instance.GetValueFromQuery(rest));

                case NdfType.MapList:
                    NdfMapList mapList = nextMap.Value as NdfMapList;
                    return(mapList.GetValueFromQuery(rest));

                case NdfType.List:
                    NdfCollection list = nextMap.Value as NdfCollection;
                    return(list.GetValueFromQuery(rest));    // TODO

                default:
                    return(nextMap);
                }
            }

            throw (new Exception("Something went wrong with this path: " + query != string.Empty ? query : "empty path"));
        }
        public NdfValueWrapper GetValueFromQuery(string query)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(query, out rest);

            long index = -1;

            if (long.TryParse(next, out index)) // can be  a list of map so we need to find a way to use "next" as a key and (even worst, sometimes a long is a key map)
            {
                NdfValueWrapper val = this.InnerList[(int)index].Value;

                switch (val.Type)
                {
                case NdfType.ObjectReference:
                    NdfObjectReference reference = val as NdfObjectReference;
                    return(reference.Instance.GetValueFromQuery(rest));

                case NdfType.MapList:
                    NdfMapList mapList = val as NdfMapList;
                    return(mapList.GetValueFromQuery(rest));

                case NdfType.List:
                    NdfCollection list = val as NdfCollection;
                    return(list.GetValueFromQuery(rest));

                case NdfType.Map:
                    NdfMap map = val as NdfMap;
                    return((map.Value as MapValueHolder).Value);


                default:
                    return(val);
                }
            }
            else
            {
                // do a list from the maps of the inner list
                List <CollectionItemValueHolder> maps = _innerList.FindAll(x => x.Value.Type == NdfType.Map);
                try
                {
                    NdfValueWrapper selectedmap = maps.Find(x => (x.Value as NdfMap).Key.Value.ToString() == next).Value; // wat

                    NdfMap         mapVal    = selectedmap as NdfMap;
                    MapValueHolder valholder = mapVal.Value as MapValueHolder;

                    return(valholder.Value);
                }
                catch { }
            }

            throw (new Exception("Something went wrong with this path: " + query != string.Empty ? query : "empty path"));
        }