-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MTGOSDK/API] ObjectProvider: Enable lazy instantiation
Defaults to lazy instantiation of dynamic remote objects, deferring instantiation to a later call to ObjectProvider. This implements the same functionality between RemoteProxy and LazyRemoteObject, allowing for multiple lazy initialization schemes to be daisy chained. This cover cases where an object's members would need to be enumerated to bind an interface type, and also where only the object reference is needed.
- Loading branch information
Showing
5 changed files
with
102 additions
and
43 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
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
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
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,46 @@ | ||
/** @file | ||
Copyright (c) 2024, Cory Bennett. All rights reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
**/ | ||
|
||
using MTGOSDK.Core.Remoting.Internal.Reflection; | ||
|
||
|
||
namespace MTGOSDK.Core.Remoting.Internal; | ||
|
||
/// <summary> | ||
/// A wrapper for lazy initializing dynamic remote objects. | ||
/// </summary> | ||
public class LazyRemoteObject : DynamicRemoteObject | ||
{ | ||
public override RemoteHandle __ra => __ctor?.Value?.__ra!; | ||
public override RemoteObject __ro => __ctor?.Value?.__ro!; | ||
public override RemoteType __type => __ctor?.Value?.__type!; | ||
|
||
/// <summary> | ||
/// The lazy object to defer initialization of the remote object. | ||
/// </summary> | ||
private Lazy<dynamic> __ctor = null!; | ||
|
||
/// <summary> | ||
/// Sets the lazy initializer function for the remote object. | ||
/// </summary> | ||
/// <param name="c">The lazy initializer function.</param> | ||
/// <returns>A reference to this function.</returns> | ||
public Func<Func<dynamic>, dynamic> Set(Func<dynamic>? c1) | ||
{ | ||
__ctor = c1 != null ? new(() => c1!.Invoke()) : null!; | ||
return new Func<Func<dynamic>, dynamic>(c => Set(c)); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the lazy object for the remote object. | ||
/// </summary> | ||
/// <param name="c">The lazy object.</param> | ||
/// <returns>A reference to this function.</returns> | ||
public Func<Lazy<dynamic>, dynamic> Set(Lazy<dynamic>? c2) | ||
{ | ||
__ctor = c2!; | ||
return new Func<Lazy<dynamic>, dynamic>(c => Set(c)); | ||
} | ||
} |
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