Ejemplo n.º 1
0
        private bool IsSameType(Type parameterType, PlaywrightType playwrightParameterType)
        {
            var types = playwrightParameterType.Union.Any() ? playwrightParameterType.Union : new[] { playwrightParameterType };

            foreach (var type in types.Where(t => t.Name != "null"))
            {
                string paramName         = type.Name;
                var    baseParameterType = GetBaseType(parameterType);

                if (type.Templates.Any())
                {
                    paramName += "<" + string.Join(",", type.Templates.Select(t => t.Name)) + ">";
                }

                if (paramName.StartsWith("\""))
                {
                    return(baseParameterType.IsEnum || (baseParameterType.GenericTypeArguments.Length > 0 && baseParameterType.GenericTypeArguments[0].IsEnum));
                }

                if (paramName.StartsWith("function", StringComparison.OrdinalIgnoreCase))
                {
                    return(typeof(MulticastDelegate).IsAssignableFrom(baseParameterType));
                }

                if (paramName switch
                {
                    "string" => baseParameterType == typeof(string) || baseParameterType.IsEnum,
                    "int" => baseParameterType == typeof(int) || baseParameterType == typeof(int?),
                    "float" => baseParameterType == typeof(int) || baseParameterType == typeof(decimal) || baseParameterType == typeof(int?) || baseParameterType == typeof(decimal?),
                    "Array<string>" => (parameterType.IsArray || parameterType == typeof(IEnumerable)) && (baseParameterType == typeof(string) || baseParameterType.IsEnum),
                    "boolean" => baseParameterType == typeof(bool) || baseParameterType == typeof(bool?),
                    "Object" =>
                    baseParameterType == typeof(Dictionary <string, string>) ||
                    baseParameterType == typeof(Dictionary <string, object>) ||
                    baseParameterType.IsInterface ||
                    baseParameterType.IsClass,
                    "Object<string,union>" => baseParameterType == typeof(Dictionary <string, string>) || baseParameterType == typeof(Dictionary <string, object>),
                    "Object<string,string>" => baseParameterType == typeof(Dictionary <string, string>),
                    "Dictionary" => baseParameterType == typeof(Dictionary <string, string>) || baseParameterType == typeof(Dictionary <string, object>),
                    "RegExp" => baseParameterType == typeof(Regex),
                    "EvaluationArgument" => baseParameterType == typeof(object),
                    "ElementHandle" => baseParameterType.Name == "IElementHandle",
                    "Buffer" => baseParameterType == typeof(string) || baseParameterType == typeof(byte[]),
                    "path" => baseParameterType == typeof(string),
                    "Serializable" => true,
                    _ => baseParameterType.Name == "I" + paramName || baseParameterType.Name == paramName || baseParameterType.GetInterfaces().FirstOrDefault()?.Name == "I" + paramName,
                })
Ejemplo n.º 2
0
 private MethodInfo GetBestMethodOverload(Type playwrightSharpType, string methodName, string paramName, PlaywrightType type)
 => playwrightSharpType.GetMethods().FirstOrDefault(m =>
                                                    m.Name == methodName &
                                                    m.GetParameters().Any(p => IsParameterNameMatch(p.Name, paramName) && IsSameType(p.ParameterType, type)));