Ejemplo n.º 1
0
        public static string Serialize <T, TMessageType>(this MessageSerializer <TMessageType> serde, T message)
            where TMessageType : IMessageContract
        {
            var serializer = serde.Serializer;

            StringBuilder sb = new StringBuilder(256);
            StringWriter  sw = new StringWriter(sb, CultureInfo.InvariantCulture);

            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = serializer.Formatting;
                serializer.Serialize(jsonWriter, message);
            }

            return(sw.ToString());
        }
Ejemplo n.º 2
0
 public static IServiceCollection TryAddMessageSerializer <TMessageType>(this IServiceCollection collectionBuilder, MessageSerializer <TMessageType> serializer)
     where TMessageType : class, IMessageContract
 {
     if (!collectionBuilder.HasMessageSerializer <TMessageType>())
     {
         collectionBuilder.AddSingleton(serializer);
     }
     return(collectionBuilder);
 }
Ejemplo n.º 3
0
 public static TMessageType?DeserializeMessage <TMessageType>(this MessageSerializer <TMessageType> serde, JObject jobject)
     where TMessageType : IMessageContract
 {
     return(jobject.ToObject <TMessageType>(serde.Serializer));
 }
Ejemplo n.º 4
0
 public static TMessageType?DeserializeMessage <TMessageType>(this MessageSerializer <TMessageType> serde, JsonReader reader)
     where TMessageType : IMessageContract
 {
     return(serde.Serializer.Deserialize <TMessageType>(reader));
 }
Ejemplo n.º 5
0
 public static IServiceCollection TryAddMessageSerializer <TMessageType>(this IServiceCollection collectionBuilder)
     where TMessageType : class, IMessageContract
 {
     return(collectionBuilder.TryAddMessageSerializer(MessageSerializer <TMessageType> .CreateDefault()));
 }