System.UriParser.IsKnownScheme C# (CSharp) Method

IsKnownScheme() public static method

public static IsKnownScheme ( string schemeName ) : bool
schemeName string
return bool
        public static bool IsKnownScheme(string schemeName)
        {
            if (schemeName == null)
                throw new ArgumentNullException(nameof(schemeName));

            if (!Uri.CheckSchemeName(schemeName))
                throw new ArgumentOutOfRangeException(nameof(schemeName));

            UriParser syntax = UriParser.GetSyntax(schemeName.ToLowerInvariant());
            return syntax != null && syntax.NotAny(UriSyntaxFlags.V1_UnknownUri);
        }
    }

Usage Example

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(scheme);
            // note: mailto and news use ':', not "://", as their delimiter
            if (UriParser.IsKnownScheme(scheme))
            {
                builder.Append(Uri.GetSchemeDelimiter(scheme));
            }
            else
            {
                builder.Append(host.Length > 0 ? Uri.SchemeDelimiter : ":");
            }

            if (username != String.Empty)
            {
                builder.Append(username);
                if (password != String.Empty)
                {
                    builder.Append(":" + password);
                }
                builder.Append('@');
            }

            if (host.Length > 0)
            {
                builder.Append(host);
                if (port > 0)
                {
                    builder.Append(":" + port);
                }
            }

            if (path != String.Empty &&
                builder [builder.Length - 1] != '/' &&
                path.Length > 0 && path [0] != '/' &&
                host.Length > 0)
            {
                builder.Append('/');
            }
            builder.Append(path);
            builder.Append(query);
            builder.Append(fragment);

            return(builder.ToString());
        }