Exemplo n.º 1
0
        public bool TryGetValueFromQuery(string propertyPath, out NdfValueWrapper value)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(propertyPath, out rest);

            if (!string.IsNullOrEmpty(next))
            {
                NdfMap nextMap;
                if (TryGetMap(next, out nextMap))
                {
                    switch (nextMap.Type)
                    {
                    case NdfType.ObjectReference:
                        NdfObjectReference reference = nextMap.Value as NdfObjectReference;
                        return(reference.Instance.TryGetValueFromQuery(rest, out value));

                    case NdfType.MapList:
                        NdfMapList mapList = nextMap.Value as NdfMapList;
                        return(mapList.TryGetValueFromQuery(rest, out value));

                    case NdfType.List:
                        NdfCollection list = nextMap.Value as NdfCollection;
                        return(list.TryGetValueFromQuery(rest, out value));

                    case Types.NdfType.Unknown:
                        break;

                    case Types.NdfType.Unset:
                        break;

                    default:
                        value = nextMap;
                        return(true);
                    }
                }
            }
            value = null;
            return(false);
        }
Exemplo n.º 2
0
        public bool TryGetValueFromQuery(string query, out NdfValueWrapper value)
        {
            NdfValueWrapper val = (this.Value as MapValueHolder).Value;

            switch (val.Type)
            {
            case NdfType.ObjectReference:
                NdfObjectReference reference = val as NdfObjectReference;
                return(reference.Instance.TryGetValueFromQuery(query, out value));

            case NdfType.MapList:
                NdfMapList mapList = val as NdfMapList;
                return(mapList.TryGetValueFromQuery(query, out value));

            case NdfType.List:
                NdfCollection list = val as NdfCollection;
                return(list.TryGetValueFromQuery(query, out value));

            case NdfType.Map:
                NdfMap map = val as NdfMap;
                return(map.TryGetValueFromQuery(query, out value));

            case Types.NdfType.Unknown:
                break;

            case Types.NdfType.Unset:
                break;

            default:
                value = val;
                return(true);
            }


            value = null;
            return(false);
            //throw (new Exception("Something went wrong with this path: " + propertyPath != string.Empty ? propertyPath : "empty path"));
        }
        public bool TryGetValueFromQuery(string query, out NdfValueWrapper value)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(query, out rest);

            // verify next is in the from "[ i ]"
            bool isIndex = false;

            string[] parts = next.Split(new string[] { "[", "]" }, StringSplitOptions.None);
            if (parts.Length == 3)
            {
                isIndex = true;
            }

            long index = -1;

            if (isIndex && long.TryParse(parts[1], out index))
            {
                NdfValueWrapper val = null;

                try { val = this.InnerList[(int)index].Value; }
                catch { value = null; return(false); }

                switch (val.Type)
                {
                case NdfType.ObjectReference:
                    NdfObjectReference reference = val as NdfObjectReference;
                    return(reference.Instance.TryGetValueFromQuery(rest, out value));

                case NdfType.MapList:
                    NdfMapList mapList = val as NdfMapList;
                    return(mapList.TryGetValueFromQuery(rest, out value));

                case NdfType.List:
                    NdfCollection list = val as NdfCollection;
                    return(list.TryGetValueFromQuery(rest, out value));

                case NdfType.Map:
                    NdfMap map = val as NdfMap;
                    return(map.TryGetValueFromQuery(rest, out value));

                case Types.NdfType.Unknown:
                    break;

                case Types.NdfType.Unset:
                    break;

                default:
                    value = val;
                    return(true);
                }
            }
            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;

                    NdfValueWrapper val = valholder.Value;

                    switch (val.Type)
                    {
                    case NdfType.ObjectReference:
                        NdfObjectReference reference = val as NdfObjectReference;
                        return(reference.Instance.TryGetValueFromQuery(rest, out value));

                    case NdfType.MapList:
                        NdfMapList mapList = val as NdfMapList;
                        return(mapList.TryGetValueFromQuery(rest, out value));

                    case NdfType.List:
                        NdfCollection list = val as NdfCollection;
                        return(list.TryGetValueFromQuery(rest, out value));

                    case NdfType.Map:
                        NdfMap map = val as NdfMap;
                        return(map.TryGetValueFromQuery(rest, out value));

                    case Types.NdfType.Unknown:
                        break;

                    case Types.NdfType.Unset:
                        break;

                    default:
                        value = val;
                        return(true);
                    }
                }
                catch { value = null; return(false); }
            }


            value = null;
            return(false);
            //throw (new Exception("Something went wrong with this path: " + propertyPath != string.Empty ? propertyPath : "empty path"));
        }