Ejemplo n.º 1
0
        /// <summary>
        /// Removes all occurrences of the specified Durian <paramref name="package"/> from the container.
        /// </summary>
        /// <returns><see langword="true"/> if any <see cref="DurianPackage"/>s has been successfully removed, <see langword="false"/> otherwise.</returns>
        /// <param name="package"><see cref="DurianPackage"/> to remove all occurrences of.</param>
        public bool RemoveAll(DurianPackage package)
        {
            List <int> duplicates = new(Count);

            for (int i = 0; i < Count; i++)
            {
                if (_enums[i] == package)
                {
                    duplicates.Add(i);
                }
            }

            if (duplicates.Count == 0)
            {
                return(false);
            }

            for (int i = duplicates.Count - 1; i > -1; i++)
            {
                int dup = duplicates[i];

                _references.RemoveAt(dup);
                _enums.RemoveAt(dup);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a collection of <see cref="PackageReference"/>s into an array of <see cref="DurianPackage"/>s.
        /// </summary>
        /// <param name="references">A collection of <see cref="PackageReference"/>s to convert.</param>
        /// <exception cref="ArgumentNullException"><paramref name="references"/> is <see langword="null"/>.</exception>
        /// <exception cref="InvalidOperationException">Null <see cref="PackageReference"/> detected.</exception>
        public static DurianPackage[] ToEnums(IEnumerable <PackageReference> references)
        {
            if (references is null)
            {
                throw new ArgumentNullException(nameof(references));
            }

            PackageReference[] array = references.ToArray();

            if (array.Length == 0)
            {
                return(Array.Empty <DurianPackage>());
            }

            DurianPackage[] enums = new DurianPackage[array.Length];

            for (int i = 0; i < enums.Length; i++)
            {
                PackageReference?reference = array[i];

                if (reference is null)
                {
                    throw new InvalidOperationException($"Null package reference at index: {i}");
                }

                enums[i] = reference.EnumValue;
            }

            return(enums);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a collection of <see cref="PackageIdentity"/>s into an array of <see cref="DurianPackage"/>s.
        /// </summary>
        /// <param name="packages">A collection of <see cref="PackageIdentity"/>s to convert.</param>
        /// <exception cref="ArgumentNullException"><paramref name="packages"/> is <see langword="null"/>.</exception>
        /// <exception cref="InvalidOperationException">Null <see cref="PackageIdentity"/> detected.</exception>
        public static DurianPackage[] ToEnums(IEnumerable <PackageIdentity> packages)
        {
            if (packages is null)
            {
                throw new ArgumentNullException(nameof(packages));
            }

            PackageIdentity[] array = packages.ToArray();

            if (array.Length == 0)
            {
                return(Array.Empty <DurianPackage>());
            }

            DurianPackage[] enums = new DurianPackage[array.Length];

            for (int i = 0; i < enums.Length; i++)
            {
                PackageIdentity?identity = array[i];

                if (identity is null)
                {
                    throw new InvalidOperationException($"Null package identity at index: {i}");
                }

                enums[i] = identity.EnumValue;
            }

            return(enums);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Throws an <see cref="InvalidOperationException"/> if the specified <paramref name="package"/> is not a valid <see cref="DurianPackage"/> value.
 /// </summary>
 /// <param name="package"><see cref="DurianPackage"/> to ensure that is valid.</param>
 /// <exception cref="InvalidOperationException">Unknown <see cref="DurianPackage"/> value: <paramref name="package"/>.</exception>
 public static void EnsureIsValidPackageEnum(DurianPackage package)
 {
     if (!GlobalInfo.IsValidPackageValue(package))
     {
         throw new InvalidOperationException($"Unknown {nameof(DurianPackage)} value: {package}!");
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines whether the specified <paramref name="assembly"/> references the provided <paramref name="package"/>.
        /// </summary>
        /// <param name="assembly"><see cref="Assembly"/> to check if contains a reference to the provided <paramref name="package"/>.</param>
        /// <param name="package"><see cref="DurianPackage"/> representing a Durian package to check for.</param>
        /// <exception cref="ArgumentNullException"><paramref name="assembly"/> is <see langword="null"/>.</exception>
        /// <exception cref="InvalidOperationException">Unknown <see cref="DurianPackage"/> value detected.</exception>
        public static bool HasReference(this Assembly assembly, DurianPackage package)
        {
            if (assembly is null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(HasReference_Internal(assembly, package));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified <paramref name="compilation"/> references the provided <paramref name="package"/>.
        /// </summary>
        /// <param name="compilation"><see cref="Compilation"/> to check if contains a reference to the provided <paramref name="package"/>.</param>
        /// <param name="package"><see cref="DurianPackage"/> representing a Durian package to check for.</param>
        /// <exception cref="ArgumentNullException"><paramref name="compilation"/> is <see langword="null"/>.</exception>
        /// <exception cref="InvalidOperationException">Unknown <see cref="DurianPackage"/> value detected.</exception>
        public static bool HasReference(this Compilation compilation, DurianPackage package)
        {
            if (compilation is null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }

            return(HasReference_Internal(compilation, package));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageDefinitionAttribute"/> class.
 /// </summary>
 /// <param name="package">Target <see cref="DurianPackage"/>.</param>
 /// <param name="type">Target <see cref="PackageType"/>.</param>
 /// <param name="version">Version of the module.</param>
 /// <param name="modules"><see cref="DurianModule"/>s this package is part of.</param>
 public PackageDefinitionAttribute(DurianPackage package, PackageType type, string version, params DurianModule[]?modules)
 {
     Modules = modules ?? new DurianModule[1] {
         DurianModule.None
     };
     Package = package;
     Type    = type;
     Version = version;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Includes the specified <paramref name="package"/> in the container.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to include.</param>
        /// <exception cref="ArgumentException"><paramref name="package"/> is not a valid <see cref="DurianPackage"/> value.</exception>
        public void Include(DurianPackage package)
        {
            if (!GlobalInfo.IsValidPackageValue(package))
            {
                throw new ArgumentException($"Value '{package}' is not a valid {nameof(DurianPackage)} value!", nameof(package));
            }

            _enums.Add(package);
            _references.Add(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageReference"/> class.
        /// </summary>
        /// <param name="package">The package this <see cref="PackageReference"/> references.</param>
        /// <exception cref="ArgumentNullException"><paramref name="package"/> is <see langword="null"/>.</exception>
        public PackageReference(PackageIdentity package)
        {
            if (package is null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            _package  = package;
            EnumValue = package.EnumValue;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Includes the specified <paramref name="package"/> in the container unless it is already included.
        /// </summary>
        /// <returns><see langword="true"/> if the <paramref name="package"/> has been successfully included, <see langword="false"/> otherwise.</returns>
        /// <param name="package"><see cref="DurianPackage"/> to include.</param>
        /// <exception cref="ArgumentException"><paramref name="package"/> is not a valid <see cref="DurianPackage"/> value.</exception>
        public bool TryInclude(DurianPackage package)
        {
            if (!Contains(package))
            {
                Include(package);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 11
0
        internal PackageIdentity(DurianPackage enumValue, string version, PackageType type, DurianModule[]?modules)
        {
            EnumValue = enumValue;
            Name      = PackageToString(enumValue);
            Version   = version;
            Type      = type;

            if (modules is null || modules.Length == 0)
            {
                _modules = ImmutableArray.Create <ModuleReference>();
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns the first <see cref="PackageReference"/> that references the specified <paramref name="package"/>.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to get the <see cref="PackageIdentity"/> for.</param>
        public PackageReference?GetReference(DurianPackage package)
        {
            for (int i = 0; i < Count; i++)
            {
                if (_enums[i] == package)
                {
                    PackageReference reference = GetReference(i);
                    return(reference);
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Removes first occurrence of the specified <paramref name="package"/> from the container.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to remove.</param>
        /// <returns><see langword="true"/> if the <paramref name="package"/> has been successfully removed, <see langword="false"/> otherwise.</returns>
        public bool Remove(DurianPackage package)
        {
            int index = _enums.IndexOf(package);

            if (index == -1)
            {
                return(false);
            }

            _enums.RemoveAt(index);
            _references.RemoveAt(index);

            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns a collection of all <see cref="PackageReference"/>s that point to the specified <paramref name="package"/>.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to get the <see cref="PackageReference"/>s for.</param>
        public IEnumerable <PackageReference> GetAllReferences(DurianPackage package)
        {
            List <PackageReference> packages = new(Count);

            for (int i = 0; i < Count; i++)
            {
                if (_enums[i] == package)
                {
                    PackageReference reference = GetReference(i);

                    packages.Add(reference);
                }
            }

            return(packages);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns all elements in the container as values of <see cref="DurianPackage"/>.
        /// </summary>
        public DurianPackage[] AsEnums()
        {
            if (Count == 0)
            {
                return(Array.Empty <DurianPackage>());
            }

            DurianPackage[] array = new DurianPackage[Count];

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = _enums[i];
            }

            return(array);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns a new instance of <see cref="PackageIdentity"/> corresponding with the specified <see cref="DurianPackage"/>.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to get the <see cref="PackageIdentity"/> of.</param>
        /// <exception cref="InvalidOperationException">Unknown <see cref="DurianPackage"/> value detected.</exception>
        public static PackageIdentity GetPackage(DurianPackage package)
        {
            return(package switch
            {
                DurianPackage.Main => PackageRepository.Main,
                DurianPackage.AnalysisServices => PackageRepository.AnalysisServices,
                DurianPackage.Core => PackageRepository.Core,
                DurianPackage.CoreAnalyzer => PackageRepository.CoreAnalyzer,
                DurianPackage.DefaultParam => PackageRepository.DefaultParam,
                DurianPackage.TestServices => PackageRepository.TestServices,

                //DurianPackage.EnumServices => PackageRepository.EnumServices,
                DurianPackage.Info => PackageRepository.Info,
                DurianPackage.FriendClass => PackageRepository.FriendClass,
                DurianPackage.InterfaceTargets => PackageRepository.InterfaceTargets,
                DurianPackage.Manager => PackageRepository.Manager,
                _ => throw new InvalidOperationException($"Unknown {nameof(DurianPackage)} value: {package}!")
            });
Ejemplo n.º 17
0
        /// <summary>
        /// Removes first occurrence of the specified <paramref name="package"/> from the container.
        /// </summary>
        /// <param name="package"><see cref="DurianPackage"/> to remove.</param>
        /// <param name="reference">Reference to a package that was removed from the container.</param>
        /// <returns><see langword="true"/> if the <paramref name="package"/> has been successfully removed, <see langword="false"/> otherwise.</returns>
        public bool Remove(DurianPackage package, [NotNullWhen(true)] out PackageReference?reference)
        {
            int index = _enums.IndexOf(package);

            if (index == -1)
            {
                reference = null;
                return(false);
            }

            PackageReference?r = _references[index] ?? new PackageReference(package);

            _enums.RemoveAt(index);
            _references.RemoveAt(index);

            reference = r;

            return(true);
        }
Ejemplo n.º 18
0
        private static bool HasReference_Internal(AssemblyIdentity[] assemblies, DurianPackage package)
        {
            string packageName = PackageToString(package);

            return(HasReference_Internal(assemblies, packageName));
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageReference"/> class.
 /// </summary>
 /// <param name="package">The package this <see cref="PackageReference"/> references.</param>
 /// <exception cref="InvalidOperationException">Unknown <see cref="DurianPackage"/> value detected.</exception>
 public PackageReference(DurianPackage package)
 {
     PackageIdentity.EnsureIsValidPackageEnum(package);
     EnumValue = package;
     _package  = null;
 }
Ejemplo n.º 20
0
        private static bool HasReference_Internal(Compilation compilation, DurianPackage package)
        {
            string packageName = PackageToString(package);

            return(HasReference_Internal(compilation, packageName));
        }
Ejemplo n.º 21
0
 internal PackageReference(DurianPackage package, ModuleIdentity onAllocate)
 {
     EnumValue   = package;
     _onAllocate = onAllocate;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Determines whether the specified <paramref name="package"/> is a valid <see cref="DurianPackage"/> value.
 /// </summary>
 /// <param name="package"><see cref="DurianPackage"/> to check.</param>
 public static bool IsValidPackageValue(DurianPackage package)
 {
     return(package >= PackageMin && package <= PackageMax);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Determines whether the specified <paramref name="package"/> is included withing this instance.
 /// </summary>
 /// <param name="package"><see cref="DurianPackage"/> to check.</param>
 public bool Contains(DurianPackage package)
 {
     return(_enums.Contains(package));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Attempts to return <see cref="PackageIdentity"/> that represents the specified <paramref name="package"/>.
        /// </summary>
        /// <returns><see langword="true"/> if an appropriate <see cref="PackageIdentity"/> has been found, <see langword="false"/> otherwise.</returns>
        /// <param name="package"><see cref="DurianPackage"/> to get the <see cref="PackageIdentity"/> for.</param>
        /// <param name="identity"><see cref="PackageIdentity"/> that represents the specified <paramref name="package"/>.</param>
        public bool TryGetPackage(DurianPackage package, [NotNullWhen(true)] out PackageIdentity?identity)
        {
            identity = GetPackage(package);

            return(identity is not null);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Attempts to return <see cref="PackageReference"/> that refers to the specified <paramref name="package"/>.
        /// </summary>
        /// <returns><see langword="true"/> if an appropriate <see cref="PackageReference"/> has been found, <see langword="false"/> otherwise.</returns>
        /// <param name="package"><see cref="DurianPackage"/> to get the <see cref="PackageReference"/> for.</param>
        /// <param name="reference"><see cref="PackageReference"/> that represents the specified <paramref name="package"/>.</param>
        public bool TryGetReference(DurianPackage package, [NotNullWhen(true)] out PackageReference?reference)
        {
            reference = GetReference(package);

            return(reference is not null);
        }