Example #1
0
        public override AssemblyIdentity ResolvePartialName(
            string displayName,
            out string location,
            ImmutableArray <ProcessorArchitecture> architectureFilter,
            CultureInfo preferredCulture)
        {
            if (displayName == null)
            {
                throw new ArgumentNullException(nameof(displayName));
            }

            location = null;
            FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName);
            if (nameObject == null)
            {
                return(null);
            }

            var    candidates  = GetAssemblyObjects(nameObject, architectureFilter);
            string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null;

            var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName);

            if (bestMatch == null)
            {
                return(null);
            }

            location = GetAssemblyLocation(bestMatch);
            return(FusionAssemblyIdentity.ToAssemblyIdentity(bestMatch));
        }
        /// <summary>
        /// Looks up specified partial assembly name in the GAC and returns the best matching full assembly name/>.
        /// </summary>
        /// <param name="displayName">The display name of an assembly</param>
        /// <param name="location">Full path name of the resolved assembly</param>
        /// <param name="architectureFilter">The optional processor architecture</param>
        /// <param name="preferredCulture">The optional preferred culture information</param>
        /// <returns>An assembly identity or null, if <paramref name="displayName"/> can't be resolved.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="displayName"/> is null.</exception>
        public static unsafe string ResolvePartialName(
            string displayName,
            out string location,
            ProcessorArchitecture[] architectureFilter = null,
            CultureInfo preferredCulture = null)
        {
            if (displayName == null)
            {
                throw new ArgumentNullException("displayName");
            }

            location = null;
            FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName);
            if (nameObject == null)
            {
                return(null);
            }

            var    candidates  = GetAssemblyObjects(nameObject, architectureFilter);
            string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null;

            var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName);

            if (bestMatch == null)
            {
                return(null);
            }

            string fullName = FusionAssemblyIdentity.GetDisplayName(bestMatch, FusionAssemblyIdentity.ASM_DISPLAYF.FULL);

            fixed(char *p = new char[MAX_PATH])
            {
                ASSEMBLY_INFO info = new ASSEMBLY_INFO
                {
                    cbAssemblyInfo            = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO)),
                    pszCurrentAssemblyPathBuf = p,
                    cchBuf = (uint)MAX_PATH
                };

                IAssemblyCache assemblyCacheObject;

                CreateAssemblyCache(out assemblyCacheObject, 0);
                assemblyCacheObject.QueryAssemblyInfo(0, fullName, ref info);
                Debug.Assert(info.pszCurrentAssemblyPathBuf != null);
                Debug.Assert(info.pszCurrentAssemblyPathBuf[info.cchBuf - 1] == '\0');

                var result = Marshal.PtrToStringUni((IntPtr)info.pszCurrentAssemblyPathBuf, (int)info.cchBuf - 1);

                Debug.Assert(result.IndexOf('\0') == -1);
                location = result;
            }

            return(fullName);
        }
Example #3
0
 public override IEnumerable <AssemblyIdentity> GetAssemblyIdentities(
     AssemblyName partialName,
     ImmutableArray <ProcessorArchitecture> architectureFilter =
     default(ImmutableArray <ProcessorArchitecture>)
     )
 {
     return(GetAssemblyIdentities(
                FusionAssemblyIdentity.ToAssemblyNameObject(partialName),
                architectureFilter
                ));
 }
Example #4
0
        /// <summary>
        /// Enumerates assemblies in the GAC returning those that match given partial name and
        /// architecture.
        /// </summary>
        /// <param name="partialName">The optional partial name.</param>
        /// <param name="architectureFilter">The optional architecture filter.</param>
        public static IEnumerable <AssemblyIdentity> GetAssemblyIdentities(string partialName = null, ImmutableArray <ProcessorArchitecture> architectureFilter = default(ImmutableArray <ProcessorArchitecture>))
        {
            FusionAssemblyIdentity.IAssemblyName nameObj;
            if (partialName != null)
            {
                nameObj = FusionAssemblyIdentity.ToAssemblyNameObject(partialName);
                if (nameObj == null)
                {
                    return(SpecializedCollections.EmptyEnumerable <AssemblyIdentity>());
                }
            }
            else
            {
                nameObj = null;
            }

            return(GetAssemblyIdentities(nameObj, architectureFilter));
        }
Example #5
0
        /// <summary>
        /// Enumerates assemblies in the GAC returning those that match given partial name and
        /// architecture.
        /// </summary>
        /// <param name="partialName">The optional partial name.</param>
        /// <param name="architectureFilter">The optional architecture filter.</param>
        public static IEnumerable <AssemblyIdentity> GetAssemblyIdentities(string partialName = null, Func <ProcessorArchitecture, bool> architectureFilter = null)
        {
            FusionAssemblyIdentity.IAssemblyName nameObj;
            if (partialName != null)
            {
                nameObj = FusionAssemblyIdentity.ToAssemblyNameObject(partialName);
                if (nameObj == null)
                {
                    return(Enumerable.Empty <AssemblyIdentity>());
                }
            }
            else
            {
                nameObj = null;
            }

            return(GetAssemblyIdentities(nameObj, architectureFilter));
        }
        private static AssemblyIdentity ResolvePartialName(
            string displayName,
            Func <ProcessorArchitecture, bool> architectureFilter,
            CultureInfo preferredCulture,
            out string location,
            bool resolveLocation)
        {
            if (displayName == null)
            {
                throw new ArgumentNullException("displayName");
            }

            location = null;
            FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName);
            if (nameObject == null)
            {
                return(null);
            }

            var    candidates  = GetAssemblyObjects(nameObject, architectureFilter);
            string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null;

            var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName);

            if (bestMatch == null)
            {
                return(null);
            }

            if (resolveLocation)
            {
                location = GetAssemblyLocation(bestMatch);
            }

            return(null);
            //return FusionAssemblyIdentity.ToAssemblyIdentity(bestMatch);
        }
Example #7
0
 /// <summary>
 /// Enumerates assemblies in the GAC returning those that match given partial name and
 /// architecture.
 /// </summary>
 /// <param name="partialName">Optional partial name.</param>
 /// <param name="architectureFilter">Optional architecture filter.</param>
 public static IEnumerable <AssemblyIdentity> GetAssemblyIdentities(AssemblyName partialName, Func <ProcessorArchitecture, bool> architectureFilter = null)
 {
     return(GetAssemblyIdentities(FusionAssemblyIdentity.ToAssemblyNameObject(partialName), architectureFilter));
 }