public void TryParseIgnoreCase() => FastEnum.TryParse <TEnum>("ABCDE", true, out var _).Should().BeFalse();
public bool FastEnum_TryParse_IgnoreCase_500() { return(FastEnum.TryParse <IntEnum1>("Type500", true, out _)); }
public bool FastEnum_TryParse_CaseSensitive_500() { return(FastEnum.TryParse <IntEnum1>("Type500", out _)); }
public void Setup() { UniEnum.TryParse <IntEnum1>("Type1", out _); FastEnum.TryParse <IntEnum1>("Type1", out _); }
public static JsonRpcUrl Parse(string packedUrlValue) { if (packedUrlValue == null) { throw new ArgumentNullException(nameof(packedUrlValue)); } string[] parts = packedUrlValue.Split('|'); if (parts.Length != 3 && parts.Length != 4) { throw new FormatException("Packed url value must contain 3 or 4 parts delimited by '|'"); } string url = parts[0]; if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) || uri.Segments.Count() > 1 || uri.Port == 0) { throw new FormatException("First part must be a valid url with the format: scheme://host:port"); } string[] endpointValues = parts[1].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (endpointValues.Length == 0) { throw new FormatException("Second part must contain at least one valid endpoint value delimited by ';'"); } RpcEndpoint endpoint = RpcEndpoint.None; foreach (string endpointValue in endpointValues) { if (FastEnum.TryParse(endpointValue, ignoreCase: true, out RpcEndpoint parsedEndpoint) && (parsedEndpoint == RpcEndpoint.Http || parsedEndpoint == RpcEndpoint.Ws)) { endpoint |= parsedEndpoint; } } if (endpoint == RpcEndpoint.None) { throw new FormatException($"Second part must contain at least one valid endpoint value (http, https, ws, wss)"); } string[] enabledModules = parts[2].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (enabledModules.Length == 0) { throw new FormatException("Third part must contain at least one module delimited by ';'"); } bool isAuthenticated = enabledModules.Any(m => m.ToLower() == "engine"); // Check if authentication disabled for this url if (parts.Length == 4) { if (parts[3] != "no-auth") { throw new FormatException("Fourth part should be \"no-auth\""); } isAuthenticated = false; } JsonRpcUrl result = new (uri.Scheme, uri.Host, uri.Port, endpoint, isAuthenticated, enabledModules); return(result); }
public void TryParse() { FastEnum.TryParse <TEnum>("ABCDE", out var _).Should().BeFalse(); FastEnum.TryParse <TEnum>("", out var _).Should().BeFalse(); }