Ejemplo n.º 1
0
        /// <summary>
        /// Registers a label target for serialization.
        /// This method can only be used during serialization.
        /// </summary>
        /// <param name="target">Target label.</param>
        /// <param name="types">type space to lookup label types.</param>
        /// <returns>Label registration JSON representation.</returns>
        public Json.Expression RegisterLabel(LabelTarget target, TypeSpace types)
        {
            if (!_serializationLabelIds.TryGetValue(target, out int id))
            {
                id = _serializationLabelIds.Count;

                var type = types.Register(target.Type).ToJson();
                _serializationLabels[target]   = new LabelRegistration(target, type);
                _serializationLabelIds[target] = id;
            }

            return(Json.Expression.Number(id.ToString(CultureInfo.InvariantCulture)));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the JSON representation of the frame.
 /// </summary>
 /// <param name="types">Type space to register parameter types in.</param>
 /// <returns>JSON representation of the frame.</returns>
 public Json.Expression ToJson(TypeSpace types)
 {
     //
     // Note: keep in sync with DeserializationFrame::.ctor code.
     //
     return(Json.Expression.Array(
                from p in _parameters
                select(Json.Expression) Json.Expression.Object(
                    new Dictionary <string, Json.Expression>
     {
         { "Name", Json.Expression.String(_mapping[p]) },
         { "FriendlyName", Json.Expression.String(p.Name) },
         { "Type", types.Register(p.Type).ToJson() }
     })
                ));
 }