Skip to content

Add new createProxy method on PrxHelper #2128

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

Merged
merged 3 commits into from
May 8, 2024
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
11 changes: 9 additions & 2 deletions cpp/src/slice2cs/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3709,7 +3709,14 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)

_out << sp << nl << "#endregion"; // Asynchronous Task operations

_out << sp << nl << "#region Checked and unchecked cast operations";
_out << sp << nl << "#region Factory operations";

_out << sp << nl << "public static " << name << "Prx createProxy(" << getUnqualified("Ice.Communicator", ns)
<< " communicator, string proxyString) =>";
_out.inc();
_out << nl << "uncheckedCast(" << getUnqualified("Ice.ObjectPrxHelper", ns)
<< ".createProxy(communicator, proxyString));";
_out.dec();

_out << sp << nl << "public static " << name << "Prx checkedCast(" << getUnqualified("Ice.ObjectPrx", ns)
<< " b, global::System.Collections.Generic.Dictionary<string, string> ctx = null)";
Expand Down Expand Up @@ -3791,7 +3798,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)

_out << sp << nl << "public static string ice_staticId() => \"" << scoped << "\";";

_out << sp << nl << "#endregion"; // Checked and unchecked cast operations
_out << sp << nl << "#endregion"; // Factory operations

_out << sp << nl << "#region Marshaling support";

Expand Down
10 changes: 10 additions & 0 deletions csharp/src/Ice/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,16 @@ private struct StreamCacheEntry
public class ObjectPrxHelper : ObjectPrxHelperBase
{
/// <summary>
/// Creates a new proxy that implements <see cref="ObjectPrx" />
/// <summary>
/// <param name="communicator">The communicator of the new proxy.</param>
/// <param name="proxyString">The string representation of the proxy.</param>
/// <returns>The new proxy.</returns>
/// <exception name="ProxyParseException">Thrown when <paramref name="proxyString" /> is not a valid proxy string.
/// </exception>
public static ObjectPrx createProxy(Communicator communicator, string proxyString) =>
communicator.stringToProxy(proxyString);

/// Casts a proxy to {@link ObjectPrx}. This call contacts
/// the server and throws an Ice run-time exception if the target
/// object does not exist or the server cannot be reached.
Expand Down
17 changes: 6 additions & 11 deletions csharp/test/Ice/ami/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,12 @@ private void
public static async Task allTestsAsync(global::Test.TestHelper helper, bool collocated)
{
Ice.Communicator communicator = helper.communicator();

string sref = "test:" + helper.getTestEndpoint(0);
Ice.ObjectPrx obj = communicator.stringToProxy(sref);
test(obj != null);
var p = Test.TestIntfPrxHelper.createProxy(communicator, sref);

Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj);
sref = "testController:" + helper.getTestEndpoint(1);
obj = communicator.stringToProxy(sref);
test(obj != null);

Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj);
var testController = Test.TestIntfControllerPrxHelper.createProxy(communicator, sref);

var output = helper.getWriter();

Expand Down Expand Up @@ -222,8 +218,7 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll
var initData = new InitializationData();
initData.properties = communicator.getProperties().ice_clone_();
Communicator ic = helper.initialize(initData);
ObjectPrx o = ic.stringToProxy(p.ToString());
Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o);
Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.createProxy(ic, p.ToString());
ic.destroy();

try
Expand Down Expand Up @@ -926,8 +921,8 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll
output.Write("testing result struct... ");
output.Flush();
{
var q = Test.Outer.Inner.TestIntfPrxHelper.uncheckedCast(
communicator.stringToProxy("test2:" + helper.getTestEndpoint(0)));
var q = Test.Outer.Inner.TestIntfPrxHelper.createProxy(
communicator, "test2:" + helper.getTestEndpoint(0));
var r = await q.opAsync(1);
test(r.returnValue == 1);
test(r.j == 1);
Expand Down
5 changes: 2 additions & 3 deletions csharp/test/Ice/operations/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public class AllTests : global::Test.AllTests
var output = helper.getWriter();
output.Flush();
string rf = "test:" + helper.getTestEndpoint(0);
Ice.ObjectPrx baseProxy = communicator.stringToProxy(rf);
var cl = Test.MyClassPrxHelper.checkedCast(baseProxy);
var derivedProxy = Test.MyDerivedClassPrxHelper.checkedCast(cl);
var cl = Test.MyClassPrxHelper.createProxy(communicator, rf);
var derivedProxy = Test.MyDerivedClassPrxHelper.uncheckedCast(cl);

output.Write("testing twoway operations... ");
output.Flush();
Expand Down
3 changes: 1 addition & 2 deletions csharp/test/Ice/operations/Twoways.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,8 +1442,7 @@ internal static void twoways(global::Test.TestHelper helper, Test.MyClassPrx p)
ctx["two"] = "TWO";
ctx["three"] = "THREE";

var p3 = Test.MyClassPrxHelper.uncheckedCast(
ic.stringToProxy("test:" + helper.getTestEndpoint(0)));
var p3 = Test.MyClassPrxHelper.createProxy(ic, "test:" + helper.getTestEndpoint(0));

ic.getImplicitContext().setContext(ctx);
test(Ice.CollectionComparer.Equals(ic.getImplicitContext().getContext(), ctx));
Expand Down
3 changes: 1 addition & 2 deletions csharp/test/Ice/operations/TwowaysAMI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,7 @@ internal static async Task twowaysAMI(global::Test.TestHelper helper, Test.MyCla
["three"] = "THREE"
};

var p3 =
Test.MyClassPrxHelper.uncheckedCast(ic.stringToProxy("test:" + helper.getTestEndpoint(0)));
var p3 = Test.MyClassPrxHelper.createProxy(ic, "test:" + helper.getTestEndpoint(0));

ic.getImplicitContext().setContext(ctx);
test(CollectionComparer.Equals(ic.getImplicitContext().getContext(), ctx));
Expand Down