The Challenge
It might surprise you, but finding the right .NET method to call can be tricky. Let's look at a simplified example. Imagine you had the following code in your flash movie:
      service.GetUser(1);
   
You'd rightfully think that the following method should be called:
      public User GetUser(int userId){...}
    
The problem is that the 1 passed into AMF.NET actually comes in as a double (1.0). Since a double can't be implicitly cast to an int, the .NET reflection engine won't find a matching function.

Possible Solutions
One solution is to simply tell developers to only use doubles. Of course, that's far from ideal.

Another solution might be to try every permutation possible. No existing function expects a double? Then look for one that expects an int! Of course, this causes an exponential growth - a method with 3 ints/doubles might require 9 reflection hits.

Yet another solution would be to use attributes. A method expecting to be exposed to AMF.NET could be decorated with helper-attributes to help AMF.NET figure when it can and cannot safely convert inputted values. In the end, this might be the solution AMF.NET uses (part of me really thinks it's the right way to go). For now, a different approach is used.

Implementation
The solution currently used by AMF.NET is different than all three solutions described above. The basic idea is to first loop through the methods of the target type and look for a matching name. Once a matching method is found, we see if the parameters match up. However, the parameter matching takes into account (or tries to) the disparity between types.

Here's the logic written out:

    IF we have less or more inputs than parameters
       return false, this can't be a match
    end if
    
    if there are 0 inputs and parameters
       return true, this is a match
    end if

    if NULL is being assigned to an object-type
       go to the next parameter, so far so good
    end if
    
    if NULL is being assigned to a value-type
      return false, this can't be a match
    end if
    
    if we can assign as-is
      go to the next parameter, so far so good
    end if
    
    if the input is a double  
      AND it can be safely converted to an Int32 
      AND the parameter can be assigned an int
         convert the input to an int
         go to the next parameter, so far so good
    end if
    
    if the parameter is an array 
      AND the input can be an array (string[]) 
      AND the parameter can be assigned that type
         convert the input to that array
         go to the next parameter, so far so good
    end if
    
    if the parameter is an enum of type Int32 
      AND the input can be an Int32 then
         convert the input to that enum
         go to the next parameter, so far so good
    end if    
    
The exact code can be seen in the private method IsMethodAMatch() of the Body class.

Overview
overview
data types
› function matching