Example #1
0
        public bool TrySerialize(object input, ISerializerContext context)
        {
            if (input is IList)
            {
                DefaultSerializerContext innerContext = new DefaultSerializerContext(context.InputType.GetGenericArguments()[0], context.Output);
                return(inner.TrySerialize(input, innerContext));
            }

            return(inner.TrySerialize(input, context));
        }
        private bool TrySerializeEnvelope(object input, ISerializerContext context, out object body, out DefaultSerializerContext innerContext)
        {
            Envelope envelope = input as Envelope;

            if (envelope != null)
            {
                innerContext = new DefaultSerializerContext(envelope.Body.GetType(), context.Output);
                foreach (string key in context.Metadata.Keys)
                {
                    innerContext.Metadata.Add(key, context.Metadata.Get <object>(key));
                }

                body = envelope.Body;
                innerContext.AddEnvelopeMetadata(envelope.Metadata);
                return(true);
            }

            body         = null;
            innerContext = null;
            return(false);
        }
Example #3
0
 /// <summary>
 /// Sets 'Metadata' to the metadata of the <paramref name="context"/>.
 /// </summary>
 /// <param name="context">The context which metadata to extend.</param>
 /// <param name="value">The vale of the 'Metadata'.</param>
 /// <returns><paramref name="envolope"/>(for fluency).</returns>
 public static ISerializerContext AddEnvelopeMetadata(this DefaultSerializerContext context, IReadOnlyKeyValueCollection value)
 {
     Ensure.NotNull(context, "context");
     context.Metadata.Add("EnvelopeMetadata", value);
     return(context);
 }