I am working on a C# project which basically works on commands to perform certain operations. It uses CommandLineParser library to parse all these commands and respective argument.
As per the new business requirement, I need to parse an URL which contains verb and parameters.
Is there any built-in/easy way to parse URL in CommandLineParser library, that will avoid writing custom logic which I explained in below approach?
Here is my approach to solve this challenge:
Covert URL to command, then using CommandLine parser assign values to option properties.
e.g.
URL:
https://localhost:9000/Open?appId=123&appName=paint&uId=511a3434-37e0-4600-ab09-65728ac4d8fe
Implementation:
Custom logic to covert url to command
open -appId 123 -name paint -uid 511a3434-37e0-4600-ab09-65728ac4d8feThen pass it to
parser.ParseArgumentsHere is the class structure
[Verb("open", HelpText = "Open an application")] public class OpenOptions { [Option("id", "appId", Required = false, HelpText = "Application Id")] public int ApplicationId{ get; set; } [Option("name", "appName", Required = false, HelpText = "Application Name")] public string ApplicationName{ get; set; } [Option("uId", "userId", Required = true, HelpText = "User Id")] public Guid UserId{ get; set; } }

Uriclass that is mentioned here.decimal.Parse? It's just as unrelated to URLs. You can parse URL arguments though. So what is the question? Why CommandLineParser specifically?Is there any built-in/easy way to parse URL in CommandLineParser library?If it is not there then that is ok. I have already written a code which converts url to command. Below answers also explain the same. My intension behind asking this question was to not break existing infrastructure of parsing command and just do some tweaks to support URL parsing as well. I don't think I will ever ask how to parse url usingdecimal.Parse