This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed impromptu-interface in favour of Castle.Core and its DynamicP…
…roxy
- Loading branch information
Showing
8 changed files
with
136 additions
and
126 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
8 changes: 1 addition & 7 deletions
8
src/Microsoft/JSInterop/0.Core/src/GetOrBuildJSFunctionalObjectDelegate.cs
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 |
---|---|---|
@@ -1,10 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Teronis.Microsoft.JSInterop | ||
namespace Teronis.Microsoft.JSInterop | ||
{ | ||
public delegate IJSFunctionalObject GetOrBuildJSFunctionalObjectDelegate(); | ||
} |
This file was deleted.
Oops, something went wrong.
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
57 changes: 57 additions & 0 deletions
57
src/Microsoft/JSInterop/Dynamic/0/src/JSDynamicObjectInterceptor.cs
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,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Castle.DynamicProxy; | ||
using Dynamitey; | ||
using Microsoft.JSInterop; | ||
using DynamiteyDynamic = Dynamitey.Dynamic; | ||
|
||
namespace Teronis.Microsoft.JSInterop.Dynamic | ||
{ | ||
public class JSDynamicObjectInterceptor : IInterceptor | ||
{ | ||
private readonly JSDynamicObjectProxy jsDynamicObjectProxy; | ||
private readonly MethodDictionary methodDictionary; | ||
private readonly IJSFunctionalObject jsFunctionalObject; | ||
|
||
internal JSDynamicObjectInterceptor(JSDynamicObjectProxy jsDynamicObjectProxy, MethodDictionary methodDictionary, IJSFunctionalObject jsFunctionalObject) | ||
{ | ||
this.jsDynamicObjectProxy = jsDynamicObjectProxy ?? throw new ArgumentNullException(nameof(jsDynamicObjectProxy)); | ||
this.methodDictionary = methodDictionary ?? throw new ArgumentNullException(nameof(methodDictionary)); | ||
this.jsFunctionalObject = jsFunctionalObject; | ||
} | ||
|
||
private static string?[] GetPositionalArgumentNames(int numberOfArguments, IReadOnlyList<string> argumentNames) | ||
{ | ||
var numberOfArgumentNames = argumentNames.Count; | ||
|
||
var positionalArgumentNames = new string?[numberOfArguments]; | ||
var currentArgumentPosition = 0; | ||
|
||
for (; currentArgumentPosition < numberOfArguments - numberOfArgumentNames; currentArgumentPosition++) { | ||
positionalArgumentNames[currentArgumentPosition] = null; | ||
} | ||
|
||
foreach (var argumentName in argumentNames) { | ||
positionalArgumentNames[currentArgumentPosition] = argumentName; | ||
currentArgumentPosition++; | ||
} | ||
|
||
return positionalArgumentNames; | ||
} | ||
|
||
public void Intercept(IInvocation invocation) { | ||
var name = invocation.Method.Name; | ||
var arguments = invocation.Arguments ?? new object[0]; | ||
var genericParameterTypes = invocation.GenericArguments; | ||
var positionalArgumentNames = invocation.Method.GetParameters().Select(x => x.Name); | ||
|
||
if (methodDictionary.TryFindMethod(invocation.Method.Name, positionalArgumentNames, out var method)) { | ||
invocation.ReturnValue = method.Invoke(jsFunctionalObject, jsDynamicObjectProxy.JSObjectReference, genericParameterTypes, arguments); | ||
return; // We have our return value set. | ||
} | ||
|
||
invocation.ReturnValue = DynamiteyDynamic.InvokeMember(jsDynamicObjectProxy, InvokeMemberName.Create(name, genericParameterTypes), arguments); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Microsoft/JSInterop/Dynamic/0/src/JSDynamicObjectProxy.cs
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,43 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.JSInterop; | ||
|
||
namespace Teronis.Microsoft.JSInterop.Dynamic | ||
{ | ||
public class JSDynamicObjectProxy : IJSDynamicObject | ||
{ | ||
public IJSObjectReference JSObjectReference => | ||
jsObjectReference; | ||
|
||
private readonly IJSObjectReference jsObjectReference; | ||
private readonly IJSFunctionalObject jsFunctionalObject; | ||
|
||
internal JSDynamicObjectProxy(IJSObjectReference jsObjectReference, IJSFunctionalObject jsFunctionalObject) | ||
{ | ||
this.jsObjectReference = jsObjectReference ?? throw new ArgumentNullException(nameof(jsObjectReference)); | ||
this.jsFunctionalObject = jsFunctionalObject; | ||
} | ||
|
||
public ValueTask<TValue> InvokeAsync<TValue>(string identifier, object?[] arguments) => | ||
jsFunctionalObject.InvokeAsync<TValue>(jsObjectReference, identifier, arguments); | ||
|
||
public ValueTask<TValue> InvokeAsync<TValue>(string identifier, CancellationToken cancellationToken, params object?[] args) => | ||
jsFunctionalObject.InvokeAsync<TValue>(jsObjectReference, identifier, cancellationToken, args); | ||
|
||
public ValueTask<TValue> InvokeAsync<TValue>(string identifier, TimeSpan timeout, params object?[] args) => | ||
jsFunctionalObject.InvokeAsync<TValue>(jsObjectReference, identifier, timeout, args); | ||
|
||
public ValueTask InvokeVoidAsync(string identifier, object?[] args) => | ||
jsFunctionalObject.InvokeVoidAsync(jsObjectReference, identifier, args); | ||
|
||
public ValueTask InvokeVoidAsync(string identifier, CancellationToken cancellationToken, object?[] args) => | ||
jsFunctionalObject.InvokeVoidAsync(jsObjectReference, identifier, cancellationToken, args); | ||
|
||
public ValueTask InvokeVoidAsync(string identifier, TimeSpan timeout, object?[] args) => | ||
jsFunctionalObject.InvokeVoidAsync(jsObjectReference, identifier, timeout, args); | ||
|
||
public ValueTask DisposeAsync() => | ||
jsObjectReference.DisposeAsync(); | ||
} | ||
} |
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