/// <summary> /// Same as GradeAllMethods, but for ctors and static methods /// </summary> /// <param name="staticCreateMethods"></param> /// <param name="publicCtors"></param> /// <param name="propertiesToCheck"></param> /// <param name="howDefined"></param> /// <returns></returns> public IEnumerable <MethodCtorMatch> GradeAllCtorsAndStaticMethods(MethodInfo[] staticCreateMethods, ConstructorInfo[] publicCtors, List <PropertyInfo> propertiesToCheck, HowTheyWereAskedFor howDefined) { var result = staticCreateMethods.Select(method => new MethodCtorMatch(method, new ParametersMatch(method.GetParameters(), propertiesToCheck, InternalPropertyMatch), howDefined)).ToList(); result.AddRange(publicCtors.Select(method => new MethodCtorMatch(method, new ParametersMatch(method.GetParameters(), propertiesToCheck, InternalPropertyMatch), howDefined))); return(result.OrderByDescending(x => x.PropertiesMatch.MatchedPropertiesInOrder.Count)); }
public MethodCtorMatch(dynamic methodOrCtor, ParametersMatch propertiesMatch, HowTheyWereAskedFor howDefined) { Method = methodOrCtor as MethodInfo; if (Method != null) { Name = Method.Name; } Constructor = methodOrCtor as ConstructorInfo; if (Constructor != null) { Name = DecodedNameTypes.Ctor.ToString(); } PropertiesMatch = propertiesMatch ?? throw new ArgumentNullException(nameof(propertiesMatch)); HowDefined = howDefined; }
/// <summary> /// This takes a set of methods and grades them as to whether they can be called by the parameters in the DTO. /// This allows extra parameters to be in the DTO for other purposes, and still fit /// </summary> /// <param name="methods"></param> /// <param name="propertiesToCheck"></param> /// <param name="howDefined"></param> /// <returns>It returns a collection of MethodCtorMatch, with the best scores first, with secondary sort order with longest number of params first</returns> public IEnumerable <MethodCtorMatch> GradeAllMethods(MethodInfo[] methods, List <PropertyInfo> propertiesToCheck, HowTheyWereAskedFor howDefined) { var result = methods.Select(method => new MethodCtorMatch(method, new ParametersMatch(method.GetParameters(), propertiesToCheck, InternalPropertyMatch), howDefined)); return(result.OrderByDescending(x => x.PropertiesMatch.MatchedPropertiesInOrder.Count)); }