in src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/CallMethodAction.cs [169:222]
private void UpdateMethodDescriptors()
{
this._methodDescriptors.Clear();
this._cachedMethodDescriptor = null;
if (string.IsNullOrEmpty(this.MethodName) || this._targetObjectType == null)
{
return;
}
// Find all public methods that match the given name and have either no parameters,
// or two parameters where the first is of type Object.
foreach (MethodInfo method in this._targetObjectType.GetRuntimeMethods())
{
if (string.Equals(method.Name, this.MethodName, StringComparison.Ordinal)
&& method.ReturnType == typeof(void)
&& method.IsPublic)
{
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0)
{
// There can be only one parameterless method of the given name.
this._cachedMethodDescriptor = new MethodDescriptor(method, parameters);
}
else if (parameters.Length == 2 && parameters[0].ParameterType == typeof(object))
{
this._methodDescriptors.Add(new MethodDescriptor(method, parameters));
}
}
}
// We didn't find a parameterless method, so we want to find a method that accepts null
// as a second parameter, but if we have more than one of these it is ambigious which
// we should call, so we do nothing.
if (this._cachedMethodDescriptor == null)
{
foreach (MethodDescriptor method in this._methodDescriptors)
{
TypeInfo typeInfo = method.SecondParameterTypeInfo;
if (!typeInfo.IsValueType || (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
if (this._cachedMethodDescriptor != null)
{
this._cachedMethodDescriptor = null;
return;
}
else
{
this._cachedMethodDescriptor = method;
}
}
}
}
}