Skip to content

Commit

Permalink
Use generics to clean up the class heirarchy a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Oct 5, 2023
1 parent a6a8e64 commit 4608c91
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal class InstrumentedChannel : InstrumentedCommunicationObject, IChannel
internal class InstrumentedChannel<T> : InstrumentedCommunicationObject<T>, IChannel
where T : IChannel
{
public InstrumentedChannel(IChannel inner)
public InstrumentedChannel(T inner)
: base(inner)
{
}

protected new IChannel Inner { get => (IChannel)base.Inner; }

T IChannel.GetProperty<T>()
where T : class
TProperty IChannel.GetProperty<TProperty>()
where TProperty : class
{
return this.Inner.GetProperty<T>();
return this.Inner.GetProperty<TProperty>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal class InstrumentedChannelFactory<TChannel> : InstrumentedChannelFactoryBase, IChannelFactory<TChannel>
internal sealed class InstrumentedChannelFactory<TChannel> : InstrumentedChannelFactoryBase<IChannelFactory<TChannel>>, IChannelFactory<TChannel>
{
private CustomBinding binding;
private readonly CustomBinding binding;

public InstrumentedChannelFactory(IChannelFactory<TChannel> inner, CustomBinding binding)
: base(inner)
{
this.binding = binding;
}

private new IChannelFactory<TChannel> Inner => (IChannelFactory<TChannel>)base.Inner;

TChannel IChannelFactory<TChannel>.CreateChannel(EndpointAddress to, Uri via)
{
return this.WrapChannel(this.Inner.CreateChannel(to, via));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal class InstrumentedChannelFactoryBase : InstrumentedCommunicationObject, IChannelFactory
internal class InstrumentedChannelFactoryBase<T> : InstrumentedCommunicationObject<T>, IChannelFactory
where T : IChannelFactory
{
public InstrumentedChannelFactoryBase(IChannelFactory inner)
public InstrumentedChannelFactoryBase(T inner)
: base(inner)
{
}

protected new IChannelFactory Inner { get => (IChannelFactory)base.Inner; }

T IChannelFactory.GetProperty<T>()
where T : class
TProperty IChannelFactory.GetProperty<TProperty>()
where TProperty : class
{
return this.Inner.GetProperty<T>();
return this.Inner.GetProperty<TProperty>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal class InstrumentedCommunicationObject : ICommunicationObject
internal class InstrumentedCommunicationObject<T> : ICommunicationObject
where T : ICommunicationObject
{
public InstrumentedCommunicationObject(ICommunicationObject inner)
public InstrumentedCommunicationObject(T inner)
{
this.Inner = inner;
}
Expand All @@ -41,7 +42,7 @@ CommunicationState ICommunicationObject.State
get { return this.Inner.State; }
}

protected ICommunicationObject Inner { get; }
protected T Inner { get; }

void ICommunicationObject.Abort()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal sealed class InstrumentedDuplexChannel : InstrumentedChannel, IDuplexSessionChannel
internal sealed class InstrumentedDuplexChannel : InstrumentedChannel<IDuplexChannel>, IDuplexSessionChannel
{
private readonly TimeSpan telemetryTimeout;

Expand All @@ -39,8 +39,6 @@ public InstrumentedDuplexChannel(IDuplexChannel inner, TimeSpan telemetryTimeout

public IDuplexSession Session => ((IDuplexSessionChannel)this.Inner).Session;

private new IDuplexChannel Inner => (IDuplexChannel)base.Inner;

public void Send(Message message)
{
this.SendInternal(message, this.telemetryTimeout, _ => this.Inner.Send(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

internal sealed class InstrumentedRequestChannel : InstrumentedChannel, IRequestSessionChannel
internal sealed class InstrumentedRequestChannel : InstrumentedChannel<IRequestChannel>, IRequestSessionChannel
{
public InstrumentedRequestChannel(IRequestChannel inner)
: base(inner)
Expand All @@ -34,8 +34,6 @@ public InstrumentedRequestChannel(IRequestChannel inner)

IOutputSession ISessionChannel<IOutputSession>.Session => ((ISessionChannel<IOutputSession>)this.Inner).Session;

private new IRequestChannel Inner => (IRequestChannel)base.Inner;

Message IRequestChannel.Request(Message message)
{
var telemetryState = ClientChannelInstrumentation.BeforeSendRequest(message, ((IRequestChannel)this).RemoteAddress?.Uri);
Expand Down

0 comments on commit 4608c91

Please sign in to comment.