Skip to content

Commit

Permalink
(#123) Tabs to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pardahlman committed Feb 17, 2018
1 parent 0527922 commit 94a6fd9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
26 changes: 13 additions & 13 deletions src/RawRabbit.Enrichers.ZeroFormatter/ZeroFormatterPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace RawRabbit.Enrichers.ZeroFormatter
{
public static class ZeroFormatterPlugin
{
/// <summary>
/// Replaces the default serializer with ZeroFormatter.
/// </summary>
public static IClientBuilder UseZeroFormatter(this IClientBuilder builder)
{
builder.Register(
pipe: p => { },
ioc: di => di.AddSingleton<ISerializer, ZeroFormatterSerializerWorker>());
return builder;
}
}
public static class ZeroFormatterPlugin
{
/// <summary>
/// Replaces the default serializer with ZeroFormatter.
/// </summary>
public static IClientBuilder UseZeroFormatter(this IClientBuilder builder)
{
builder.Register(
pipe: p => { },
ioc: di => di.AddSingleton<ISerializer, ZeroFormatterSerializerWorker>());
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@

namespace RawRabbit.Enrichers.ZeroFormatter
{
internal class ZeroFormatterSerializerWorker : ISerializer
{
public string ContentType => "application/x-zeroformatter";
private readonly MethodInfo _deserializeType;
private readonly MethodInfo _serializeType;
internal class ZeroFormatterSerializerWorker : ISerializer
{
public string ContentType => "application/x-zeroformatter";
private readonly MethodInfo _deserializeType;
private readonly MethodInfo _serializeType;

public ZeroFormatterSerializerWorker()
{
_deserializeType = typeof(ZeroFormatterSerializer)
.GetMethod(nameof(ZeroFormatterSerializer.Deserialize), new[] { typeof(byte[]) });
_serializeType = typeof(ZeroFormatterSerializer)
.GetMethods()
.FirstOrDefault(s => s.Name == nameof(ZeroFormatterSerializer.Serialize) && s.ReturnType == typeof(byte[]));
}
public ZeroFormatterSerializerWorker()
{
_deserializeType = typeof(ZeroFormatterSerializer)
.GetMethod(nameof(ZeroFormatterSerializer.Deserialize), new[] { typeof(byte[]) });
_serializeType = typeof(ZeroFormatterSerializer)
.GetMethods()
.FirstOrDefault(s => s.Name == nameof(ZeroFormatterSerializer.Serialize) && s.ReturnType == typeof(byte[]));
}

public byte[] Serialize(object obj)
{
if (obj == null)
throw new ArgumentNullException();
public byte[] Serialize(object obj)
{
if (obj == null)
throw new ArgumentNullException();

return (byte[])_serializeType
.MakeGenericMethod(obj.GetType())
.Invoke(null, new[] { obj });
}
return (byte[])_serializeType
.MakeGenericMethod(obj.GetType())
.Invoke(null, new[] { obj });
}

public object Deserialize(Type type, byte[] bytes)
{
return _deserializeType.MakeGenericMethod(type)
.Invoke(null, new object[] { bytes });
}
public object Deserialize(Type type, byte[] bytes)
{
return _deserializeType.MakeGenericMethod(type)
.Invoke(null, new object[] { bytes });
}

public TType Deserialize<TType>(byte[] bytes)
{
return ZeroFormatterSerializer.Deserialize<TType>(bytes);
}
}
public TType Deserialize<TType>(byte[] bytes)
{
return ZeroFormatterSerializer.Deserialize<TType>(bytes);
}
}
}

0 comments on commit 94a6fd9

Please sign in to comment.