src/Microsoft.VisualStudio.ProjectSystem.Managed/Composition/EnumerableExtensions.cs
/// <summary>
/// Enumerates a sequence of extensions, omitting any extensions that throw MEF exceptions.
/// </summary>
/// <typeparam name="T">The type of extension.</typeparam>
/// <param name="extensions">The collection of extensions.</param>
/// <param name="onlyCreatedValues">
/// <c>true</c> to only enumerate extensions from Lazy's that have previously been created.
/// This is useful in Dispose methods to avoid MEF ObjectDisposedExceptions from accidentally
/// creating values during a container disposal.
/// </param>
/// <returns>The safely constructed sequence of extensions.</returns>
Enumerates a sequence of extensions, omitting any extensions that throw MEF exceptions.
Enumerates a sequence of extensions omitting any extensions that throw MEF exceptions .
internal static IEnumerable<T> ExtensionValues<T>(this IEnumerable<Lazy<T>> extensions, bool onlyCreatedValues = false)
        {
            Requires.NotNull(extensions, nameof(extensions));
            var traceErrorMessage = "Roslyn project system extension rejected due to exception: {0}";
            foreach (var extension in extensions)
            {
                T value;
                try
                {
                    if (onlyCreatedValues && !extension.IsValueCreated)
                    {
                        continue;
                    }
                    value = extension.Value;
                }
                catch (CompositionContractMismatchException ex)
                {
                    TraceUtilities.TraceError(traceErrorMessage, ex);
                    continue;
                }
                catch (CompositionException ex)
                {
                    TraceUtilities.TraceError(traceErrorMessage, ex);
                    continue;
                }
                yield return value;
            }
        }
internal static IEnumerable < T > ExtensionValues < T > ( this IEnumerable < Lazy < T > > extensions , bool onlyCreatedValues = false ) { Requires . NotNull ( extensions , nameof ( extensions ) ) ; var traceErrorMessage = " " ; foreach ( var extension in extensions ) { T value ; try { if ( onlyCreatedValues && ! extension . IsValueCreated ) { continue ; } value = extension . Value ; } catch ( CompositionContractMismatchException ex ) { TraceUtilities . TraceError ( traceErrorMessage , ex ) ; continue ; } catch ( CompositionException ex ) { TraceUtilities . TraceError ( traceErrorMessage , ex ) ; continue ; } yield return value ; } }
Enumerates a sequence of extensions, omitting any extensions that throw MEF exceptions.
Enumerates a sequence of extensions omitting any extensions that throw MEF exceptions .
The safely constructed sequence of extensions.
The safely constructed sequence of extensions .
IEnumerable<Lazy<T>>
this
onlyCreatedValues
bool
None
extensions
The collection of extensions.
The collection of extensions .
typeparam
The type of extension.
The type of extension .