|
6 | 6 | export module DotNet { |
7 | 7 | export type JsonReviver = ((key: any, value: any) => any); |
8 | 8 | const jsonRevivers: JsonReviver[] = []; |
9 | | - export type JsonReplacer = ((key: any, value: any) => any); |
10 | | - const jsonReplacers: JsonReplacer[] = []; |
11 | 9 |
|
12 | 10 | const jsObjectIdKey = "__jsObjectId"; |
13 | 11 | const dotNetObjectRefKey = "__dotNetObject"; |
| 12 | + const dotNetElementRefKey = "__internalId"; |
14 | 13 | const byteArrayRefKey = "__byte[]"; |
15 | 14 | const dotNetStreamRefKey = "__dotNetStream"; |
16 | 15 | const jsStreamReferenceLengthKey = "__jsStreamReferenceLength"; |
@@ -120,14 +119,6 @@ export module DotNet { |
120 | 119 | jsonRevivers.push(reviver); |
121 | 120 | } |
122 | 121 |
|
123 | | - /** |
124 | | - * Adds a JSON replacer callback that will be used when serializing arguments sent to .NET. |
125 | | - * @param replacer The replacer to add. |
126 | | - */ |
127 | | - export function attachReplacer(replacer: JsonReplacer) { |
128 | | - jsonReplacers.push(replacer); |
129 | | -} |
130 | | - |
131 | 122 | /** |
132 | 123 | * Invokes the specified .NET public method synchronously. Not all hosting scenarios support |
133 | 124 | * synchronous invocation, so if possible use invokeMethodAsync instead. |
@@ -817,22 +808,30 @@ export module DotNet { |
817 | 808 | return result; |
818 | 809 | } |
819 | 810 |
|
| 811 | + function getCaptureIdFromElement(element: Element): string | null { |
| 812 | + for (let i = 0; i < element.attributes.length; i++) { |
| 813 | + const attr = element.attributes[i]; |
| 814 | + if (attr.name.startsWith('_bl_')) { |
| 815 | + return attr.name.substring(4); |
| 816 | + } |
| 817 | + } |
| 818 | + return null; |
| 819 | +} |
| 820 | + |
820 | 821 | function argReplacer(key: string, value: any) { |
821 | | - const processedValue = jsonReplacers.reduce( |
822 | | - (currentValue, replacer) => replacer(key, currentValue), |
823 | | - value |
824 | | - ); |
825 | | - |
826 | | - if (processedValue instanceof DotNetObject) { |
827 | | - return processedValue.serializeAsArg(); |
828 | | - } else if (processedValue instanceof Uint8Array) { |
| 822 | + if (value instanceof Element) { |
| 823 | + return { [dotNetElementRefKey]: getCaptureIdFromElement(value) }; |
| 824 | + } |
| 825 | + if (value instanceof DotNetObject) { |
| 826 | + return value.serializeAsArg(); |
| 827 | + } else if (value instanceof Uint8Array) { |
829 | 828 | const dotNetCallDispatcher = currentCallDispatcher!.getDotNetCallDispatcher(); |
830 | | - dotNetCallDispatcher!.sendByteArray(nextByteArrayIndex, processedValue); |
| 829 | + dotNetCallDispatcher!.sendByteArray(nextByteArrayIndex, value); |
831 | 830 | const jsonValue = { [byteArrayRefKey]: nextByteArrayIndex }; |
832 | 831 | nextByteArrayIndex++; |
833 | 832 | return jsonValue; |
834 | 833 | } |
835 | 834 |
|
836 | | - return processedValue; |
| 835 | + return value; |
837 | 836 | } |
838 | 837 | } |
0 commit comments