当前位置: 首页>>代码示例>>C#>>正文


C# IContainer.ResolveAll方法代码示例

本文整理汇总了C#中IContainer.ResolveAll方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.ResolveAll方法的具体用法?C# IContainer.ResolveAll怎么用?C# IContainer.ResolveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContainer的用法示例。


在下文中一共展示了IContainer.ResolveAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMappedDataSource

        /// <summary>
        /// Gets the data source for the specified mapping.
        /// </summary>
        /// <param name="mapping">The requested mapping.</param>
        /// <param name="container">The container.</param>
        /// <returns>The data source.</returns>
        public static IDataSource GetMappedDataSource(IMapping mapping, IContainer container)
        {
            mapping = Enforce.NotNull(mapping, () => mapping);

            // Depending on the protocol of the mapping, create the appropriate data source. If the
            // protocol is not supported, throw an exception.
            IDataSource dataSource;
            switch (mapping.Protocol)
            {
                case Protocol.File:
                    dataSource = new FileDataSource(container, mapping);
                    break;
                case Protocol.Http:
                    dataSource = new HttpDataSource(container, mapping);
                    break;
                case Protocol.Https:
                    dataSource = new HttpsDataSource(container, mapping);
                    break;
                case Protocol.Ftp:
                    dataSource = new FtpDataSource(container, mapping);
                    break;
                default:
                    throw new ProtocolNotSupportedException(
                        String.Format(CultureInfo.CurrentCulture,
                            "The protocol '{0}' is not supported.", mapping.Protocol));
            }

            // Attach the constraints to the data source.
            foreach (ConstraintBase constraint in mapping.Constraints)
            {
                dataSource.DownloadStarting += constraint.Validate;
            }

            // Attach the add-ins to the data source.
            foreach (var addin in container.ResolveAll<IAddIn>())
            {
                // Wire up simple events.
                dataSource.DownloadStarting += addin.OnDownloadStarting;
                dataSource.DownloadFinished += addin.OnDownloadFinished;

                // Some events require heavy data load. Wire them only if the event is implemented
                // within the add-in.
                if(addin.ImplementsOnDownloadVerifying)
                {
                    dataSource.DownloadVerifying += addin.OnDownloadVerifying;
                }
            }

            // Return the data source to the caller.
            return dataSource;
        }
开发者ID:peterbucher,项目名称:silkveil,代码行数:57,代码来源:DataSourceFactory.cs

示例2: ResolveEnumerable

        /// <summary>
        /// Resolves an enumerable type.
        /// </summary>
        /// <param name="contractType">The contract type.</param>
        /// <param name="container">The container.</param>
        /// <returns>A IEnumerable{TContract} instance with all registered instances.</returns>
        private static IEnumerable ResolveEnumerable(Type contractType, IContainer container)
        {
            Type genericArgument = contractType.GetGenericArguments().FirstOrDefault();

            object[] resolvedInstances = container.ResolveAll(genericArgument).ToArray();

            Type openListType = typeof(List<>);
            Type closedListType = openListType.MakeGenericType(genericArgument);

            var list = (IList)Activator.CreateInstance(closedListType);

            foreach(var instance in resolvedInstances)
            {
                list.Add(instance);
            }

            return list;
        }
开发者ID:AlexZeitler,项目名称:LightCore,代码行数:24,代码来源:EnumerableRegistrationSource.cs

示例3: ResolveArray

 /// <summary>
 /// Resolves an array type.
 /// </summary>
 /// <param name="contractType">The contract type.</param>
 /// <param name="container">The container.</param>
 /// <returns>A TContract[] instance with all registered instances.</returns>
 private static Array ResolveArray(Type contractType, IContainer container)
 {
     Type elementType = contractType.GetElementType();
     object[] resolvedInstances = container.ResolveAll(elementType).ToArray();
     return resolvedInstances;
 }
开发者ID:AlexZeitler,项目名称:LightCore,代码行数:12,代码来源:ArrayRegistrationSource.cs


注:本文中的IContainer.ResolveAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。