dimanche 29 mars 2020

Convert method ReturnType to dynamic in runtime

I have some methods with custom attribute with different return types. And I need to convert this method to delegate with dynamic return type (or boxed object). How can I do that?
This is my code:

        foreach (var m in methods)
        {
            var attr = (T)m.GetCustomAttribute(typeof(T));
..
            else
            {
                var d = (ServerCallbackHandler)Delegate.CreateDelegate(typeof(ServerCallbackHandler), null, m);
                if (typeof(T) == typeof(CEFRequestAttribute))
                    Bridge.Instance.OnCEFRequest(name, d);
                else Bridge.Instance.OnClientRequest(name, d);
            }
        }

and some method with bool ReturnType.
Here it is my delegate:

public delegate dynamic ServerCallbackHandler(Player sender, NetworkMessage message, dynamic data);

With this code I have an error: Cannot bind to the target method because its signature is not compatible with that of the delegate type.





Aucun commentaire:

Enregistrer un commentaire