Exemplo n.º 1
0
        /// <summary>
        /// Attempts to retrieve the instance of the specified
        /// component type and, if found, stores it in the
        /// componentInstance parameter.
        /// </summary>
        /// <param name="componentRegistry">
        /// The IComponentRegistry instance.
        /// </param>
        /// <param name="componentInstance">
        /// The out parameter in which the found instance will be stored.
        /// </param>
        /// <returns>
        /// True if a registered instance was found, false otherwise.
        /// </returns>
        public static bool TryGet <TComponent>(
            this IComponentRegistry componentRegistry,
            out TComponent componentInstance)
            where TComponent : class
        {
            object componentObject = null;

            componentInstance = null;

            if (componentRegistry.TryGet(typeof(TComponent), out componentObject))
            {
                componentInstance = componentObject as TComponent;
                return(componentInstance != null);
            }

            return(false);
        }