/// <devdoc> /// Moves to the next element. This returns false if we are at the end or are otherwise unable /// to move. /// </devdoc> bool IEnumerator.MoveNext() { currentName = null; string fileName = null; // If we've already cached this guy once, use the cached data. // if (cachedNames != null && current < cachedNames.Count - 1) { current++; currentName = (AssemblyName)cachedNames[current]; Debug.Assert(currentName != null, "cache is bunk."); return(true); } // We normally only will loop through this while once. The only time we will // go through it more than once is when we discover a file, and that file is an // invalid assembly. while (fileName == null || currentName == null /* SBurke -- workaround for CLR bug # VSWhidbey 211103, but it might be worth leaving in here anyway */) { if (name == null) { // No specific name, so match all components. Note that this is really slow -- VS takes forever // to calculate this. // if (componentEnum == null) { NativeMethods.ThrowOnFailure(enumFactory.GetComponents(null, (int)CompEnum.CompEnumType_COMPlus, 0, out componentEnum)); selector = new VSCOMPONENTSELECTORDATA[1]; selector[0] = new VSCOMPONENTSELECTORDATA(); selector[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORDATA)); } uint fetched; NativeMethods.ThrowOnFailure(componentEnum.Next(1, selector, out fetched)); if (fetched == 0) { return(false); } Debug.Assert(selector[0].type == VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus, "Asked for CLR components but didn't get 'em."); fileName = selector[0].bstrFile; } else { // We were given a specific name to match. Do a path based reference on sdk paths and // then match files within that path. // if (componentEnum == null) { NativeMethods.ThrowOnFailure(enumFactory.GetComponents(null, (int)CompEnum.CompEnumType_AssemblyPaths, 0, out componentEnum)); selector = new VSCOMPONENTSELECTORDATA[1]; selector[0] = new VSCOMPONENTSELECTORDATA(); selector[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORDATA)); } while (true) { uint fetched; NativeMethods.ThrowOnFailure(componentEnum.Next(1, selector, out fetched)); if (fetched == 0) { return(false); } Debug.Assert(selector[0].type == VSCOMPONENTTYPE.VSCOMPONENTTYPE_Path, "Asked for sdk paths but didn't get 'em."); string assemblyPath = Path.Combine(selector[0].bstrFile, name); if (File.Exists(assemblyPath)) { fileName = assemblyPath; break; } } } Debug.Assert(fileName != null, "We should have always retrieved a file name here."); try { currentName = AssemblyName.GetAssemblyName(fileName); } catch (FileLoadException) { // This file is invalid. Null the name so we continue our loop. fileName = null; } catch (BadImageFormatException) { // This file is invalid. Null the name so we continue our loop. fileName = null; } } // Store this assembly name in our cache, because they're quite expensive to get. // if (cachedNames == null) { cachedNames = new ArrayList(); } cachedNames.Add(currentName); current++; return(true); }
/// <devdoc> /// Moves to the next element. This returns false if we are at the end or are otherwise unable /// to move. /// </devdoc> bool IEnumerator.MoveNext() { currentName = null; string fileName = null; // If we've already cached this guy once, use the cached data. // if (cachedNames != null && current < cachedNames.Count - 1) { current++; currentName = (AssemblyName)cachedNames[current]; Debug.Assert(currentName != null, "cache is bunk."); return(true); } if (name == null) { // No specific name, so match all components. Note that this is really slow -- VS takes forever // to calculate this. // if (componentEnum == null) { enumFactory.GetComponents(null, CompEnumType.CompEnumType_COMPlus, false, out componentEnum); selector = new _VSCOMPONENTSELECTORDATA[1]; selector[0] = new _VSCOMPONENTSELECTORDATA(); selector[0].dwSize = (uint)Marshal.SizeOf(typeof(_VSCOMPONENTSELECTORDATA)); } uint fetched; int hr = componentEnum.Next(1, selector, out fetched); if (hr != 0) { return(false); } Debug.Assert(selector[0].type == __VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus, "Asked for CLR components but didn't get 'em."); fileName = selector[0].bstrFile; } else { // We were given a specific name to match. Do a path based reference on sdk paths and // then match files within that path. // if (componentEnum == null) { enumFactory.GetComponents(null, CompEnumType.CompEnumType_AssemblyPaths, false, out componentEnum); selector = new _VSCOMPONENTSELECTORDATA[1]; selector[0] = new _VSCOMPONENTSELECTORDATA(); selector[0].dwSize = (uint)Marshal.SizeOf(typeof(_VSCOMPONENTSELECTORDATA)); } while (true) { uint fetched; int hr = componentEnum.Next(1, selector, out fetched); if (hr != 0) { return(false); } Debug.Assert(selector[0].type == __VSCOMPONENTTYPE.VSCOMPONENTTYPE_Path, "Asked for sdk paths but didn't get 'em."); string assemblyPath = Path.Combine(selector[0].bstrFile, name); if (File.Exists(assemblyPath)) { fileName = assemblyPath; break; } } } Debug.Assert(fileName != null, "We should have always retrieved a file name here."); currentName = AssemblyName.GetAssemblyName(fileName); // Store this assembly name in our cache, because they're quite expensive to get. // if (cachedNames == null) { cachedNames = new ArrayList(); } cachedNames.Add(currentName); current++; return(true); }