Exemple #1
0
        public ActionInfo ResolveAction(Type hubType, string actionName, object[] parameters)
        {
            // Get all methods
            var candidates = ReflectionHelper.GetExportedHubMethods(hubType)
                             .Where(m => m.Name.Equals(actionName, StringComparison.OrdinalIgnoreCase))
                             .Where(m => ParametersAreCompatible(m.GetParameters(), parameters))
                             .ToList();

            switch (candidates.Count)
            {
            case 1:
                var method = candidates.Single();
                var args   = GetParameters(method.GetParameters(), parameters);
                return(new ActionInfo
                {
                    Method = method,
                    Arguments = args
                });

            default:
                break;
            }

            return(null);
        }
 protected virtual IEnumerable <MethodInfo> GetMethods(Type type)
 {
     // Pick the overload with the minimum number of arguments
     return(from method in ReflectionHelper.GetExportedHubMethods(type)
            group method by method.Name into overloads
            let overload = (from overload in overloads
                            orderby overload.GetParameters().Length
                            select overload).FirstOrDefault()
                           select overload);
 }
Exemple #3
0
 /// <summary>
 /// Builds a dictionary of all possible methods on a given hub.
 /// Single entry contains a collection of available overloads for a given method name (key).
 /// This dictionary is being cached afterwards.
 /// </summary>
 /// <param name="hub">Hub to build cache for</param>
 /// <returns>Dictionary of available methods</returns>
 private IDictionary <string, IEnumerable <MethodDescriptor> > BuildMethodCacheFor(HubDescriptor hub)
 {
     return(ReflectionHelper.GetExportedHubMethods(hub.Type)
            .GroupBy(GetMethodName, StringComparer.OrdinalIgnoreCase)
            .ToDictionary(group => group.Key,
                          group => group.Select(oload =>
                                                new MethodDescriptor
     {
         ReturnType = oload.ReturnType,
         Name = group.Key,
         Invoker = oload.Invoke,
         Parameters = oload.GetParameters()
                      .Select(p => new ParameterDescriptor
         {
             Name = p.Name,
             Type = p.ParameterType,
         })
                      .ToList()
     }),
                          StringComparer.OrdinalIgnoreCase));
 }
Exemple #4
0
 /// <summary>
 /// Builds a dictionary of all possible methods on a given hub.
 /// Single entry contains a collection of available overloads for a given method name (key).
 /// This dictionary is being cached afterwards.
 /// </summary>
 /// <param name="hub">Hub to build cache for</param>
 /// <returns>Dictionary of available methods</returns>
 private IDictionary <string, IEnumerable <MethodDescriptor> > BuildMethodCacheFor(HubDescriptor hub)
 {
     return(ReflectionHelper.GetExportedHubMethods(hub.Type)
            .GroupBy(GetMethodName, StringComparer.OrdinalIgnoreCase)
            .ToDictionary(group => group.Key,
                          group => group.Select(oload =>
                                                new MethodDescriptor
     {
         ReturnType = oload.ReturnType,
         Name = group.Key,
         NameSpecified = (GetMethodAttributeName(oload) != null),
         Invoker = oload.Invoke,
         Hub = hub,
         Attributes = oload.GetCustomAttributes(typeof(Attribute), inherit: true).Cast <Attribute>(),
         Parameters = oload.GetParameters()
                      .Select(p => new ParameterDescriptor
         {
             Name = p.Name,
             Type = p.ParameterType,
         })
                      .ToList()
     }),
                          StringComparer.OrdinalIgnoreCase));
 }
Exemple #5
0
 protected virtual IEnumerable <MethodInfo> GetMethods(Type type)
 {
     return(ReflectionHelper.GetExportedHubMethods(type));
 }