Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more static JsonRpc.Attach<T> overloads #251

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/StreamJsonRpc/IJsonRpcMessageFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public interface IJsonRpcMessageFormatter
/// <summary>
/// Serializes a <see cref="JsonRpcMessage"/>.
/// </summary>
/// <param name="contentBuffer">The receiver of the serialized bytes.</param>
/// <param name="bufferWriter">The receiver of the serialized bytes.</param>
/// <param name="message">The message to serialize.</param>
void Serialize(IBufferWriter<byte> contentBuffer, JsonRpcMessage message);
void Serialize(IBufferWriter<byte> bufferWriter, JsonRpcMessage message);

/// <summary>
/// Gets a JSON representation for a given message for tracing purposes.
Expand Down
37 changes: 37 additions & 0 deletions src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,43 @@ public static T Attach<T>(Stream sendingStream, Stream receivingStream)
return proxy;
}

/// <summary>
/// Creates a JSON-RPC client proxy that conforms to the specified server interface.
/// </summary>
/// <typeparam name="T">The interface that describes the functions available on the remote end.</typeparam>
/// <param name="handler">The message handler to use.</param>
/// <returns>
/// An instance of the generated proxy.
/// In addition to implementing <typeparamref name="T"/>, it also implements <see cref="IDisposable"/>
/// and should be disposed of to close the connection.
/// </returns>
public static T Attach<T>(IJsonRpcMessageHandler handler)
where T : class
{
return Attach<T>(handler, options: null);
}

/// <summary>
/// Creates a JSON-RPC client proxy that conforms to the specified server interface.
/// </summary>
/// <typeparam name="T">The interface that describes the functions available on the remote end.</typeparam>
/// <param name="handler">The message handler to use.</param>
/// <param name="options">A set of customizations for how the client proxy is wired up. If <c>null</c>, default options will be used.</param>
/// <returns>
/// An instance of the generated proxy.
/// In addition to implementing <typeparamref name="T"/>, it also implements <see cref="IDisposable"/>
/// and should be disposed of to close the connection.
/// </returns>
public static T Attach<T>(IJsonRpcMessageHandler handler, JsonRpcProxyOptions options)
where T : class
{
var proxyType = ProxyGeneration.Get(typeof(T).GetTypeInfo(), disposable: true);
var rpc = new JsonRpc(handler);
T proxy = (T)Activator.CreateInstance(proxyType.AsType(), rpc, options ?? JsonRpcProxyOptions.Default);
rpc.StartListening();
return proxy;
}

/// <summary>
/// Creates a JSON-RPC client proxy that conforms to the specified server interface.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/StreamJsonRpc/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ StreamJsonRpc.HeaderDelimitedMessageHandler.HeaderDelimitedMessageHandler(System
StreamJsonRpc.IJsonRpcMessageFormatter
StreamJsonRpc.IJsonRpcMessageFormatter.Deserialize(System.Buffers.ReadOnlySequence<byte> contentBuffer) -> StreamJsonRpc.Protocol.JsonRpcMessage
StreamJsonRpc.IJsonRpcMessageFormatter.GetJsonText(StreamJsonRpc.Protocol.JsonRpcMessage message) -> object
StreamJsonRpc.IJsonRpcMessageFormatter.Serialize(System.Buffers.IBufferWriter<byte> contentBuffer, StreamJsonRpc.Protocol.JsonRpcMessage message) -> void
StreamJsonRpc.IJsonRpcMessageFormatter.Serialize(System.Buffers.IBufferWriter<byte> bufferWriter, StreamJsonRpc.Protocol.JsonRpcMessage message) -> void
StreamJsonRpc.IJsonRpcMessageHandler
StreamJsonRpc.IJsonRpcMessageHandler.CanRead.get -> bool
StreamJsonRpc.IJsonRpcMessageHandler.CanWrite.get -> bool
Expand Down
2 changes: 2 additions & 0 deletions src/StreamJsonRpc/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static StreamJsonRpc.JsonRpc.Attach<T>(StreamJsonRpc.IJsonRpcMessageHandler handler) -> T
static StreamJsonRpc.JsonRpc.Attach<T>(StreamJsonRpc.IJsonRpcMessageHandler handler, StreamJsonRpc.JsonRpcProxyOptions options) -> T