-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed extension methods to match standard, adjusted some extension …
…method locations.
- Loading branch information
Showing
4 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/MassTransit.MessagePack/MassTransit.MessagePack.csproj.DotSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/MassTransit/Internals/Extensions/InternalJsonExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |