Esempio n. 1
0
        /// <summary>
        /// Compress the types on the serializable class.
        /// </summary>
        /// <param name="serializable">The serializable entity.</param>
        /// <param name="state">The <see cref="SerializationState"/>.</param>
        public void CompressTypes(
            SerializableExpression serializable,
            SerializationState state)
        {
            if (KeyCache.Count < 1)
            {
                return;
            }

            var expression = (TSerializable)serializable;

            // single props
            var parameters = KeyCache
                             .Where(entry => !entry.IsCollection)
                             .Select(
                cache =>
                (cache.GetKeys(expression)[0],
                 (Action <string>)(
                     s => cache.SetKeys(expression, new[] { s }))))
                             .ToArray();

            state.CompressTypesForKeys(parameters);

            // lists
            foreach (var parameter in KeyCache.Where(entry => entry.IsCollection))
            {
                var keys = parameter.GetKeys(expression).Select(
                    k => state.CompressTypesforKey(k)).ToArray();
                parameter.SetKeys(expression, keys);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializationRoot"/> class and sets the
 /// <see cref="SerializableExpression"/> property.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <exception cref="ArgumentNullException">Thrown when expression is null.</exception>
 public SerializationRoot(SerializableExpression expression)
 {
     Ensure.NotNull(() => expression);
     Expression = expression;
 }
Esempio n. 3
0
 /// <summary>
 /// Decompress the types on the expression.
 /// </summary>
 /// <param name="serializable">The <see cref="SerializableExpression"/>.</param>
 /// <param name="state">The <see cref="SerializationState"/>.</param>
 void IBaseSerializer.DecompressTypes(SerializableExpression serializable, SerializationState state) =>
 DecompressTypes((TSerializable)serializable, state);
Esempio n. 4
0
 /// <summary>
 /// Explicit implementation.
 /// </summary>
 /// <param name="root">The root expression.</param>
 /// <param name="state">The <see cref="SerializationState"/>.</param>
 /// <returns>The deserialized <see cref="Expression"/>.</returns>
 Expression IBaseSerializer.Deserialize(SerializableExpression root, SerializationState state) =>
 Deserialize((TSerializable)root, state);