Ejemplo n.º 1
0
        /// <summary>
        /// Returns a <see cref="UniversalPackageDependency"/> instance parsed from the specified string.
        /// </summary>
        /// <param name="s">String containing the text to parse.</param>
        /// <returns>Parsed <see cref="UniversalPackageDependency"/> instance.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is null or empty.</exception>
        public static UniversalPackageDependency Parse(string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                throw new ArgumentNullException(nameof(s));
            }

            var parts = s.Split(new[] { ':' }, 3, StringSplitOptions.None);

            if (parts.Length == 1)
            {
                var n = ExtractGroup(parts[0]);
                return(new UniversalPackageDependency(n));
            }

            if (parts.Length == 2)
            {
                if (parts[1] == "*")
                {
                    var n = ExtractGroup(parts[0]);
                    return(new UniversalPackageDependency(n));
                }

                var v = UniversalPackageVersion.TryParse(parts[1]);
                if (v != null)
                {
                    var n = ExtractGroup(parts[0]);
                    return(new UniversalPackageDependency(n, v));
                }

                return(new UniversalPackageDependency(parts[0], parts[1]));
            }
            else
            {
                if (parts[2] == "*")
                {
                    return(new UniversalPackageDependency(parts[0], parts[1]));
                }
                else
                {
                    return(new UniversalPackageDependency(parts[0], parts[1], UniversalPackageVersion.Parse(parts[2])));
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniversalPackageDependency"/> class.
 /// </summary>
 /// <param name="group">The package group.</param>
 /// <param name="name">The package name.</param>
 /// <param name="version">The required version; null indicates any version.</param>
 /// <exception cref="ArgumentNullException"><paramref name="name"/> is null or empty.</exception>
 public UniversalPackageDependency(string group, string name, UniversalPackageVersion version)
     : this(new UniversalPackageId(group, name), version)
 {
     this.FullName = new UniversalPackageId(group, name);
     this.Version  = version;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniversalPackageDependency"/> class.
 /// </summary>
 /// <param name="id">The full identifier of the package.</param>
 /// <param name="version">The required version; null indicates any version.</param>
 /// <exception cref="ArgumentNullException"><paramref name="id"/> is null.</exception>
 public UniversalPackageDependency(UniversalPackageId id, UniversalPackageVersion version)
 {
     this.FullName = id ?? throw new ArgumentNullException(nameof(id));
     this.Version  = version;
 }