Skip to content

Commit

Permalink
Renamed extension methods to match standard, adjusted some extension …
Browse files Browse the repository at this point in the history
…method locations.
  • Loading branch information
phatboyg committed Oct 15, 2024
1 parent 41aae8a commit 1c1ec85
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,41 @@

public static class MessagePackConfigurationExtensions
{
public static void UseMessagePack(this IReceiveEndpointConfigurator configurator, bool isDefault = false)
/// <summary>
/// Use the MessagePack serializer as the default serializer for the receive endpoint
/// </summary>
/// <param name="configurator"></param>
/// <param name="isDefault"></param>
public static void UseMessagePackSerializer(this IReceiveEndpointConfigurator configurator, bool isDefault = true)
{
var factory = new MessagePackSerializerFactory();

configurator.AddSerializer(factory, isDefault);
configurator.AddDeserializer(factory, isDefault);
}

public static void UseMessagePack(this IBusFactoryConfigurator configurator, bool isDefault = false)
/// <summary>
/// Use the MessagePack serializer
/// </summary>
/// <param name="configurator"></param>
/// <param name="isDefault"></param>
public static void UseMessagePackSerializer(this IBusFactoryConfigurator configurator, bool isDefault = true)
{
var factory = new MessagePackSerializerFactory();

configurator.AddSerializer(factory, isDefault);
configurator.AddDeserializer(factory, isDefault);
}

/// <summary>
/// Use the MessagePack deserializer, optionally setting it as the default message deserializer if no content type is found.
/// </summary>
/// <param name="configurator"></param>
/// <param name="isDefault"></param>
public static void UseMessagePackDeserializer(this IBusFactoryConfigurator configurator, bool isDefault = false)
{
var factory = new MessagePackSerializerFactory();

configurator.AddDeserializer(factory, isDefault);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=configuration/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
45 changes: 0 additions & 45 deletions src/MassTransit/Internals/Extensions/InternalJsonExtensions.cs

This file was deleted.

42 changes: 42 additions & 0 deletions src/MassTransit/Serialization/SystemTextJsonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#nullable enable
namespace MassTransit.Serialization;

using System;
using System.Text.Json;
using Metadata;


public static class SystemTextJsonExtensions
{
public static T? GetObject<T>(this JsonElement jsonElement, JsonSerializerOptions options)
where T : class
{
if (typeof(T).IsInterface && MessageTypeCache<T>.IsValidMessageType)
{
var messageType = TypeMetadataCache<T>.ImplementationType;

if (jsonElement.Deserialize(messageType, options) is T obj)
return obj;
}

return jsonElement.Deserialize<T>(options);
}

public static T? Transform<T>(this object objectToTransform, JsonSerializerOptions options)
where T : class
{
var jsonElement = JsonSerializer.SerializeToElement(objectToTransform, options);

return jsonElement.GetObject<T>(options);
}

public static object? Transform(this object objectToTransform, Type targetType, JsonSerializerOptions options)
{
var jsonElement = JsonSerializer.SerializeToElement(objectToTransform, options);

if (targetType.IsInterface && MessageTypeCache.IsValidMessageType(targetType))
targetType = TypeMetadataCache.GetImplementationType(targetType);

return jsonElement.Deserialize(targetType, options);
}
}

0 comments on commit 1c1ec85

Please sign in to comment.