From d86ef1c8286f761b58e434e67998fb75ece00f60 Mon Sep 17 00:00:00 2001 From: Xappy Date: Fri, 1 Nov 2024 12:01:32 +0200 Subject: [PATCH] [DRO] Optimize cast to byte[] --- src/RemoteNET/DynamicRemoteObject.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/RemoteNET/DynamicRemoteObject.cs b/src/RemoteNET/DynamicRemoteObject.cs index 44790954..2300a14f 100644 --- a/src/RemoteNET/DynamicRemoteObject.cs +++ b/src/RemoteNET/DynamicRemoteObject.cs @@ -544,10 +544,20 @@ private static T[] __cast_to_array(DynamicRemoteObject dro) array[i] = dyn[i]; return array; } + private static byte[] __cast_to_byte_array(DynamicRemoteObject dro) + { + // Invoke remote Convert.ToBase64String(byte[]) + Type ConvertType = dro.__ra.GetRemoteType(typeof(Convert)); + MethodInfo toBase64 = ConvertType.GetMethods().Single(mi => mi.Name == nameof(Convert.ToBase64String) && mi.GetParameters().Length == 1); + + string base64 = toBase64.Invoke(null, new object[] { dro }) as string; + + return Convert.FromBase64String(base64); + } #pragma warning restore IDE1006 // Naming Styles public static implicit operator bool[](DynamicRemoteObject dro) => __cast_to_array(dro); - public static implicit operator byte[](DynamicRemoteObject dro) => __cast_to_array(dro); + public static implicit operator byte[](DynamicRemoteObject dro) => __cast_to_byte_array(dro); public static implicit operator char[](DynamicRemoteObject dro) => __cast_to_array(dro); public static implicit operator short[](DynamicRemoteObject dro) => __cast_to_array(dro); public static implicit operator ushort[](DynamicRemoteObject dro) => __cast_to_array(dro);