コード例 #1
0
        /// <summary>
        /// Continues visitation for the current type using the specified <see cref="SerializedValueView"/>. This will run the next adapter in the sequence, or the default behaviour and return the deserialized value.
        /// </summary>
        public TValue ContinueVisitationWithoutAdapters(SerializedValueView view)
        {
            var value = default(TValue);

            m_Visitor.ReadValueWithoutAdapters(ref value, view.AsUnsafe(), m_IsRoot);
            return(value);
        }
コード例 #2
0
        /// <summary>
        /// Reads the given <see cref="SerializedValue"/> as <typeparamref name="T"/> and returns it. This will run all adapters.
        /// </summary>
        public T DeserializeValue <T>(SerializedValueView view)
        {
            var value = default(T);

            m_Visitor.ReadValue(ref value, view.AsUnsafe());
            return(value);
        }
コード例 #3
0
        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <param name="name">The key of the value to get.</param>
        /// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value.</param>
        /// <returns>true if the <see cref="SerializedObjectView"/> contains an element with the specified key; otherwise, false.</returns>
        public bool TryGetValue(string name, out SerializedValueView value)
        {
            foreach (var m in this)
            {
                if (!m.Name().Equals(name))
                {
                    continue;
                }

                value = m.Value();
                return(true);
            }

            value = default;
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Creates a mutable object from the given immutable serialized value view.
        /// </summary>
        /// <param name="view">Immutable view from which this constructor initializes this instance.</param>
        public JsonObject(SerializedValueView view)
        {
            switch (view.Type)
            {
            case TokenType.Object:
                ChangeType(JsonDataType.Object);
                foreach (var member in view.AsObjectView())
                {
                    this[member.Name().ToString()] = new JsonObject(member.Value());
                }

                break;

            case TokenType.Array:
                ChangeType(JsonDataType.Array);
                foreach (var element in view.AsArrayView())
                {
                    m_ArrayData.Add(new JsonObject(element));
                }

                break;

            case TokenType.String:
                ChangeType(JsonDataType.String);
                m_StringData = view.AsStringView().ToString();
                break;

            case TokenType.Primitive:
                var primitive = view.AsPrimitiveView();
                if (primitive.IsBoolean())
                {
                    ChangeType(JsonDataType.Boolean);
                    m_BooleanData = primitive.AsBoolean();
                }
                else if (primitive.IsIntegral() || primitive.IsDecimal() || primitive.IsInfinity() || primitive.IsNaN())
                {
                    ChangeType(JsonDataType.Number);
                    m_NumberData = primitive.AsDouble();
                }
                // else: null -> remain undefined
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #5
0
        /// <summary>
        /// Reads the next node as an array element.
        /// </summary>
        /// <param name="view">The view of the array element.</param>
        /// <returns>True if the element was successfully read, false otherwise.</returns>
        public bool ReadArrayElement(out SerializedValueView view)
        {
            if (!CheckArrayElement())
            {
                view = default;
                return(false);
            }

            view = ReadInternal(NodeType.Any, m_Parser.TokenParentIndex);

            if (m_Parser.NodeType != NodeType.Any)
            {
                return(true);
            }

            view = default;
            return(false);
        }
コード例 #6
0
 /// <summary>
 /// Continues visitation for the current type using the specified <see cref="SerializedValueView"/>. This will invoke the default behaviour and return the deserialized value..
 /// </summary>
 public void ContinueVisitationWithoutAdapters(ref TValue value, SerializedValueView view)
 {
     m_Visitor.ReadValueWithoutAdapters(ref value, view.AsUnsafe(), m_IsRoot);
 }
コード例 #7
0
 /// <summary>
 /// Reads the next node in the stream, respecting depth/scope.
 /// </summary>
 /// <param name="view">The view at the returned node type.</param>
 /// <param name="node">The node type to stop at.</param>
 /// <returns>The node type the parser stopped at.</returns>
 public NodeType Read(out SerializedValueView view, NodeType node = NodeType.Any)
 {
     view = ReadInternal(node, m_Parser.TokenParentIndex);
     return(m_Parser.NodeType);
 }
コード例 #8
0
 /// <summary>
 /// Advances the reader to the given node type, ignoring depth/scope.
 /// </summary>
 /// <param name="view">The view at the returned node type.</param>
 /// <param name="node">The node type to stop at.</param>
 /// <returns>The node type the parser stopped at.</returns>
 public NodeType Step(out SerializedValueView view, NodeType node = NodeType.Any)
 {
     view = ReadInternal(node, NodeParser.k_IgnoreParent);
     return(m_Parser.NodeType);
 }