예제 #1
0
        /// <summary>
        /// Attempts to parse the specified value as document identity.
        /// Expects input to be in the format <c>NAME@VERSION</c> where <c>NAME</c> is a valid <see cref="DocumentName"/> and <c>VERSION</c> is a valid <see cref="NuGetVersion"/>.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <param name="identity">When successful, contains a reference to the created <see cref="DocumentIdentity"/> instance.</param>
        /// <returns>
        /// Returns <c>true</c> is <paramref name="value"/> was successfully parsed.
        /// Otherwise returns <c>false</c>.
        /// </returns>
        /// <seealso cref="ToString"/>
        public static bool TryParse(string value, [NotNullWhen(true)] out DocumentIdentity?identity)
        {
            identity = default;

            if (String.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            var fragments = value.Split('@');

            if (fragments.Length != 2)
            {
                return(false);
            }

            var idString      = fragments[0];
            var versionString = fragments[1];

            if (!NuGetVersion.TryParse(versionString, out var version))
            {
                return(false);
            }

            if (!DocumentName.TryCreate(idString, out var id))
            {
                return(false);
            }

            identity = new DocumentIdentity(id, version);
            return(true);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="SameVersionDocumentReference"/>.
 /// </summary>
 /// <param name="name">The referenced name.</param>
 public SameVersionDocumentReference(DocumentName name)
 {
     Name = name ?? throw new ArgumentNullException(nameof(name));
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="DocumentIdentity"/>.
 /// </summary>
 /// <param name="name">The document's name.</param>
 /// <param name="version">The document's version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="version"/> is <c>null</c>.</exception>
 public DocumentIdentity(DocumentName name, NuGetVersion version)
 {
     Name    = name ?? throw new ArgumentNullException(nameof(name));
     Version = version ?? throw new ArgumentNullException(nameof(version));
 }
예제 #4
0
 /// <summary>
 /// Gets a a new <see cref="DocumentIdentity"/> with the specified name and the current instance's version
 /// </summary>
 public DocumentIdentity WithName(DocumentName name) => new DocumentIdentity(name, Version);