Example #1
0
    public static bool TryGetCustomClassMapping(IEnumerable <string> sourceParameters, out ICollection <KeyValuePair <string, string> > customMapping, out string errorMessage)
    {
        customMapping = new List <KeyValuePair <string, string> >();

        foreach (var parameter in sourceParameters ?? Enumerable.Empty <string>())
        {
            var parts = parameter.Split(':');
            if (parts.Length != 2)
            {
                errorMessage = "\"classMapping\" value must have format {GraphQlTypeName}:{C#ClassName}. ";
                return(false);
            }

            var cSharpClassName = parts[1];
            if (!CSharpHelper.IsValidIdentifier(cSharpClassName))
            {
                errorMessage = $"\"{cSharpClassName}\" is not valid C# class name. ";
                return(false);
            }

            customMapping.Add(new KeyValuePair <string, string>(parts[0], cSharpClassName));
        }

        errorMessage = null;
        return(true);
    }