Example #1
0
        /// <summary>
        /// Serializes with the specified serializer
        /// </summary>
        /// <param name="serializerId"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        private SerializationEnvelope SerializeToEnvelope(string serializerId, object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var ser = this.Store.GetAllById <ISerializationUtil>(serializerId).FirstOrDefault();

            Condition.Requires(ser).IsNotNull();

            SerializationEnvelope env = SerializationEnvelope.New(ser, obj);

            return(env);
        }
Example #2
0
        /// <summary>
        /// Serializes with the first serializer that works
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private SerializationEnvelope SerializeToEnvelopeWithFirstApplicable(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var sers = this.Store.GetAll <ISerializationUtil>();

            foreach (var ser in sers)
            {
                try
                {
                    SerializationEnvelope env = SerializationEnvelope.New(ser, obj);
                    return(env);
                }
                catch
                {
                    continue;
                }
            }

            throw new InvalidOperationException("No valid serializers found");
        }