No announcement yet.


  • Filter
  • Time
  • Show
Clear All
new posts


    Hi guys, I see that MethodInfo.MakeGenericMethod() is not implemented in Bridge. I also found an issue in github on this topic ( Will it be available sometimes?

    The thing is, I refactored a Dependency Injection framework to work with Bridge and this is the last missing piece for me. Here's an example of what I need to achieve, is there any alternative solution available on "making generic methods" ?

    private static MethodInfo GetMethod(Type sourceType, BindingFlags bindingFlags, string methodName, Type[] genericTypes, Type[] parameterTypes)
        List<MethodInfo> methods = sourceType.GetMethods(bindingFlags)  
            .Where(mi => string.Equals(methodName, mi.Name, StringComparison.Ordinal))                    
            .Where(mi => mi.ContainsGenericParameters)                    
            .Where(mi => mi.GetGenericArguments().Length == genericTypes.Length)                    
            .Where(mi => mi.GetParameters().Length == parameterTypes.Length)                    
            .Select( mi => mi.MakeGenericMethod(genericTypes))                    
            .Where(mi => mi.GetParameters().Select(pi => pi.ParameterType).SequenceEqual(parameterTypes))                    
        var methods = validMethods.ToList();            
        if (methods.Count > 1)            
            throw new AmbiguousMatchException();            
        return methods.FirstOrDefault();        
    Thanks a lot,
    Last edited by Patrik; 2019-06-06 @ 10:17 AM.

    Hello @Parik! Thanks for the follow-up, I've added a comment to the issue pointing you also want it.

    By the way, was it you who upvoted the issue in github? That'd help us decide which feature should be worked on next (many votes = more likely). Of course, it depends on how feasible it is.

    Also the context you provided helps a lot so we know what we're developing for. A deck (versus dotnetfiddle or test case also helps, so that we imbue that test case in our unit testing project and ensure the feature continues working.

    So if you're willing to help more, expand the code block you provided into an actual test code (with, maybe, a Console.WriteLine showing what you expect), then we can assess having it work in Deck.


      Originally posted by fabricio.murta View Post
      By the way, was it you who upvoted the issue in github?
      I was who upvoted that issue. My use case was a bit complicated, I was trying to compile a serialization library for Bridge and I partially achieved it except for some features like MakeGenericMethod, but end up removing all the workarounds (#if BRIDGE_NET) in my code since this is a relatively complex code using pointers among other complicated constructions and I wasn't happy with the result.


        A pull-request for this feature has just been added. Once a review and final testing are complete the featue will be included in the next release of Bridge.

        You can track the status of this feature at:

        Hope this helps.


          Sounds good :)

          What about MethodInfo.Invoke method? I found out that there are 2 overloads:

          [Template("Bridge.Reflection.midel({this}, {obj})({*arguments})", "Bridge.Reflection.midel({this}, {obj}).apply(null, {arguments:array})")]
          public extern object Invoke(object obj, params object[] arguments);

          [Template("Bridge.Reflection.midel({this}, {obj}, {typeArguments})({*arguments})", "Bridge.Reflection.midel({this}, {obj}, {typeArguments}).apply(null, {arguments:array})")]
          public extern object Invoke(object obj, Type[] typeArguments, params object[] arguments);
          And I was able to get my code working using the second one.

          I mean, in mscorlib none of Invoke method overloads hase parameter similar to
          Type[] typeArguments
          From what I understood, simply calling this overload of Invoke method works for generic methods and provides us another way of specifying generic parameters, without need to use MakeGenericMethod.

          Can you confirm my assumption? Did you provide it as workaround for unsupported MakeGenericMethod feature?


            Hello @Patrik!

            Not sure about the Invoke method overloads you're talking about, but the feature you asked here has been implemented and is going to make it to the next Bridge release. Currently that would be 17.9.0.

            I don't think the overload you mentioned in your last post was provided as a workaround for the lack of MethodInfo.MakeGenericMethod, but if I understand it well, you won't need this nonstandard path if the implementation is in place, right?..

            Anyway, if with the next Bridge release, you still need to use that overload, please open a new thread, so we can discuss it. Does that sound alright for you?


              Sounds right, loking forward for release ;)