Beispiel #1
0
        public override bool Equals(object obj)
        {
            if (!(obj is EmbeddedList))
            {
                foreach (var jsonValue in _values)
                {
                    if (jsonValue.Equals(obj))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            EmbeddedList compareList = obj as EmbeddedList;

            foreach (var compareValue in compareList._values)
            {
                foreach (var jsonValue in _values)
                {
                    if (compareValue.Equals(jsonValue))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
 public void AddRange(EmbeddedList list)
 {
     IJsonValue[] values = (IJsonValue[])list.Value;
     foreach (var jsonValue in values)
     {
         Add(jsonValue);
     }
 }
Beispiel #3
0
        public bool Evaluate(out IJsonValue value, IJSONDocument document)
        {
            value = null;
            if (document == null)
            {
                return(false);
            }

            if (!document.Contains(_name))
            {
                return(false);
            }

            IJsonValue outValue;

            outValue = value = JsonWrapper.Wrap(document[_name]);

            if (_childAttribute == null && _indecies == null && value.DataType != FieldDataType.Array)
            {
                return(true);
            }

            if (outValue.DataType != FieldDataType.Array &&
                outValue.DataType != FieldDataType.Object)
            {
                value = null;
                return(false);
            }

            if (_indecies != null)
            {
                foreach (int index in _indecies)
                {
                    if (outValue.DataType != FieldDataType.Array)
                    {
                        value = null;
                        return(false);
                    }

                    var values = ((IJsonValue[])((ArrayJsonValue)outValue).WrapedValue);

                    if (values.Length - 1 < index)
                    {
                        return(false);
                    }

                    outValue = value = values[index];
                }
            }

            if (_childAttribute == null && value.DataType != FieldDataType.Array)
            {
                return(true);
            }

            if (outValue.DataType == FieldDataType.Object)
            {
                return(_childAttribute.Evaluate(out value, (IJSONDocument)outValue.Value));
            }

            EmbeddedList embededValues = new EmbeddedList();

            var arrayValues = ((IJsonValue[])((ArrayJsonValue)outValue).WrapedValue);

            foreach (var arrayValue in arrayValues)
            {
                IJsonValue embededValue;

                if (arrayValue.DataType == FieldDataType.Object)
                {
                    if (_childAttribute == null)
                    {
                        if (value.DataType == FieldDataType.Array)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    //else
                    //{
                    //    return false;
                    //}

                    if (_childAttribute.Evaluate(out embededValue, (IJSONDocument)arrayValue.Value))
                    {
                        if (outValue is EmbeddedList)
                        {
                            embededValues.AddRange(embededValue as EmbeddedList);
                        }
                        else
                        {
                            embededValues.Add(embededValue);
                        }
                    }
                }
                //else if(arrayValue.DataType != FieldDataType.Array)
                else
                {
                    embededValues.Add(arrayValue);
                }
            }

            value = embededValues;
            return(true);
        }