Description
The TryParseIdent
method attempts to parse a given identifier string into its constituent parts, which include the organization, package name, version, and a boolean indicating if it is a local package. This method is useful for validating and extracting information from package identifiers in the Sandbox environment.
Usage
To use the TryParseIdent
method, provide the identifier string you wish to parse as the first argument. The method will output a tuple containing the parsed components if successful. The method returns a boolean indicating whether the parsing was successful.
The parsed
parameter is an output parameter that will contain a tuple with the following elements if parsing is successful:
Item1
: The organization name as a string
.
Item2
: The package name as a string
.
Item3
: The version as a Nullable<int>
.
Item4
: A bool
indicating if the package is local.
Example
string ident = "org:package@1";
(bool success, (string org, string package, int? version, bool isLocal) parsed) = (false, (null, null, null, false));
success = Sandbox.Package.TryParseIdent(ident, out parsed);
if (success)
{
Console.WriteLine($"Organization: {parsed.org}");
Console.WriteLine($"Package: {parsed.package}");
Console.WriteLine($"Version: {parsed.version}");
Console.WriteLine($"Is Local: {parsed.isLocal}");
}
else
{
Console.WriteLine("Failed to parse identifier.");
}