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


C# Assembly.SelectMany方法代码示例

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


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

示例1: RegisterHandlers

        public void RegisterHandlers(IIMOwinOptions options, Assembly[] hostAssemblies)
        {
            // memoized
            if (Interlocked.Increment(ref _alreadyRegistered) != 0) return;

            var contractTypes = hostAssemblies
                .SelectMany(x =>
                {
                    try
                    {
                        return x.GetTypes();
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        return ex.Types.Where(t => t != null);
                    }
                })
                .Where(x => typeof (IMOwinBehaviorContract).IsAssignableFrom(x))
                .Where(x => !x.IsAbstract);

            Parallel.ForEach(contractTypes, classType =>
            {
                var className = classType.Name;
                if (classType.GetConstructors().All(x => x.GetParameters().Length != 0))
                {
                    throw new InvalidOperationException(string.Format("Type needs parameterless constructor, class:{0}", classType.FullName));
                }
                // ignore
                if (classType.GetCustomAttribute<IgnoreOperationAttribute>(true) != null) return;

                foreach (var methodInfo in classType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                {
                    // property
                    if (methodInfo.IsSpecialName && (methodInfo.Name.StartsWith("set_") || methodInfo.Name.StartsWith("get_")))
                        continue;

                    // ignore
                    if (methodInfo.GetCustomAttribute<IgnoreOperationAttribute>(true) != null) 
                        continue;

                    var methodName = methodInfo.Name;
                    // ignore default methods
                    if (methodName == "Equals" || methodName == "GetHashCode" || methodName == "GetType" || methodName == "ToString") 
                        continue;

                    // create handler
                    var handler = new OperationHandler(classType, methodInfo);
                    lock (_handlers)
                    {
                        var path = new RequestPath(className, methodName);
                        // 簡単化のため duplicate entry ⇒ fail
                        if (_handlers.ContainsKey(path))
                        {
                            throw new InvalidOperationException(string.Format("same class and method is not allowed, class:{0} method:{1}", className, methodName));
                        }
                        _handlers.Add(path, handler);
                    }
                }
            });
        }
开发者ID:ilovelili,项目名称:IMobile.Owin,代码行数:60,代码来源:IMOwinServer.cs

示例2: RegisterBusinessLogic

        private static void RegisterBusinessLogic(ContainerBuilder builder, Assembly[] assemblies)
        {
            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => !string.IsNullOrWhiteSpace(t.Namespace) && t.Namespace.StartsWith("ReMi.BusinessLogic"))
                .AsImplementedInterfaces()
                .InstancePerDependency()
                .PropertiesAutowired();

            builder.Register<IApiDescriptionBuilder>(
                c => new ApiDescriptionBuilder(
                    assemblies.SelectMany(a => a.GetTypes().Where(t => typeof(ApiController).IsAssignableFrom(t)).Select(x => x)),
                    assemblies.SelectMany(a => a.GetTypes().Where(t => typeof(ICommand).IsAssignableFrom(t) && t.IsClass).Select(x => x))
                    ))
                .PropertiesAutowired()
                .InstancePerDependency();
        }
开发者ID:wongatech,项目名称:remi,代码行数:16,代码来源:DependencyResolverConfig.cs

示例3: RegisterClients

 public static void RegisterClients(Assembly[] assemblyToFindTypes, Action<Type, Type> registerTypeForContainer)
 {
     var allTypes = assemblyToFindTypes.SelectMany(a => a.GetTypes());
     var allServiceClientInterfaces =
         allTypes.Where(x => typeof(IServiceClient).IsAssignableFrom(x) && x.IsInterface && x != typeof(IServiceClient)).ToList();
     foreach (var @interface in allServiceClientInterfaces)
     {
         registerTypeForContainer(@interface, allTypes.Where(x => @interface.IsAssignableFrom(x) && x.IsClass).FirstOrDefault());
     }
 }
开发者ID:benjaminkeeping,项目名称:Restful.Service.Client,代码行数:10,代码来源:Bootstrap.cs

示例4: AddCqrsSpirit

        /// <summary>
        /// Registers CQRS chunks into service container
        /// </summary>
        /// <param name="services">DI container</param>
        /// <param name="assemblies">Assemblies list where is CQRS stuff is placed</param>
        /// <param name="filter">Predicate to filter types you would like to register</param>
        public static IServiceCollection AddCqrsSpirit(this IServiceCollection services, Assembly[] assemblies, Func<Type, bool> filter = null)
        {
            var types = assemblies
                .SelectMany(assembly => assembly.ExportedTypes)
                .Where(t => t.GetTypeInfo().IsPublic);

            if (filter != null)
                types = types.Where(filter);

            return AddCqrsSpirit(services, types.ToArray());
        }
开发者ID:sergeyzwezdin,项目名称:cqs.net,代码行数:17,代码来源:CqrsSpiritExtensions.cs

示例5: SammyApplication

        public SammyApplication(IKernel kernel, Assembly[] assembly)
        {
            _kernel = kernel;
            var types = assembly.SelectMany<Assembly, Type>(a => a.GetTypes()).ToArray();

            // Should this be off some kind of marker (like HttpApplication)?
            _kernel.Register(AllTypes.From(types).BasedOn<SammyController>());

            // This is getting a bit large - how do we initialize this better?
            Routes = RouteCollector.Collect(_kernel.GetAssignableHandlers(typeof(SammyController)).Select(h => h.Service).ToArray());
        }
开发者ID:davidmohara,项目名称:Sammy,代码行数:11,代码来源:SammyApplication.cs

示例6: GetAssemblyTypes

        private static IEnumerable<Type> GetAssemblyTypes(Assembly[] assembliesWithServices)
        {
            var results = new List<Type>();

            try
            {
                results.AddRange(assembliesWithServices.SelectMany(assembly => assembly.GetTypes()));
            }
            catch (Exception)
            {
                // ignored
            }
            return results;
        }
开发者ID:zcsscfc,项目名称:vic_demo,代码行数:14,代码来源:ApiConfig.cs

示例7: GetPublicNoArgExtensionMethods

        public IEnumerable<MethodInfo> GetPublicNoArgExtensionMethods(Assembly[] sourceExtensionMethodSearch)
        {
            if (sourceExtensionMethodSearch == null)
            {
                return new MethodInfo[] { };
            }

            //http://stackoverflow.com/questions/299515/c-sharp-reflection-to-identify-extension-methods
            return sourceExtensionMethodSearch
                .SelectMany(assembly => assembly.GetTypes())
                .Where(type => type.IsSealed && !type.IsGenericType && !type.IsNested)
                .SelectMany(type => type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
                .Where(method => method.IsDefined(typeof(ExtensionAttribute), false))
                .Where(method => method.GetParameters()[0].ParameterType == this.Type);
        }
开发者ID:nikson,项目名称:AutoMapper,代码行数:15,代码来源:TypeInfo.cs

示例8: RegisterAssemblies

        public void RegisterAssemblies(Assembly[] assemblies)
        {
            var searchTarget = typeof(IHandler<>);

            var dict = assemblies.SelectMany(a => a.GetTypes())
                .SelectMany(t => t.GetInterfaces()
                                    .Where(i => i.IsGenericType
                                        && (i.GetGenericTypeDefinition() == searchTarget)
                                        && !i.ContainsGenericParameters),
                            (t, i) => new { Key = i.GetGenericArguments()[0], Value = t })
                .GroupBy(x => x.Key, x => x.Value)
                .ToDictionary(g => g.Key, g => g.ToList());

            _subscription = dict; 
        }
开发者ID:paralect,项目名称:Paralect.Dispatcher,代码行数:15,代码来源:HandlerRegistrator.cs

示例9: Register

 public static void Register(Assembly[] handlerAssemblies, Assembly[] modelAssemblies)
 {
     foreach (
         var route in
             handlerAssemblies.SelectMany(a => a.GetTypes()).Select(GetBaseRouteAttributeFor).SelectMany(
                 routeInfo => routeInfo).OrderByDescending(x => x.Route))
     {
         Debug.WriteLine(string.Format("[OpenRasta.Routing] Registering route '{0}' named '{1}' with handler '{2}'", route.Route, route.Name, route.HandlerType));
         ResourceSpace.Has.ResourcesOfType(route.HandlerType)
             .AtUri(route.Route).Named(route.Name)
             .HandledBy(route.HandlerType)
             .AsJsonDataContract()
             .And.AsXmlDataContract();
     }
     foreach (var type in modelAssemblies.SelectMany(x => x.GetTypes()))
     {
         Debug.WriteLine(string.Format("[OpenRasta.Routing] Registering  type '{0}'", type));
         ResourceSpace.Has.ResourcesOfType(type)
             .WithoutUri
             .AsJsonDataContract()
             .And.AsXmlDataContract();
     }
 }
开发者ID:benjaminkeeping,项目名称:OpenRasta.Routing,代码行数:23,代码来源:Routing.cs

示例10: GetRouteInfo

 public static IEnumerable<RouteInfo> GetRouteInfo(Assembly[] handlerAssemblies)
 {
     return handlerAssemblies.SelectMany(a => a.GetTypes()).Select(GetBaseRouteAttributeFor).SelectMany(
         routeInfo => routeInfo);
 }
开发者ID:benjaminkeeping,项目名称:OpenRasta.Routing,代码行数:5,代码来源:Routing.cs

示例11: RegisterHandler

        // cache all methods
        public IReadOnlyCollection<KeyValuePair<string, OperationInfo>> RegisterHandler(Assembly[] hostAssemblies)
        {
            if (Interlocked.Increment(ref alreadyRegistered) != 0) return new KeyValuePair<string, OperationInfo>[0];

            var contractTypes = hostAssemblies
                .SelectMany(x =>
                {
                    try
                    {
                        return x.GetTypes();
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        return ex.Types.Where(t => t != null);
                    }
                })
                .Where(x => typeof(LightNodeContract).IsAssignableFrom(x))
                .Where(x => !x.IsAbstract);

            Parallel.ForEach(contractTypes, classType =>
            {
                var className = classType.Name;
                if (!classType.GetConstructors().Any(x => x.GetParameters().Length == 0))
                {
                    throw new InvalidOperationException(string.Format("Type needs parameterless constructor, class:{0}", classType.FullName));
                }
                if (classType.GetCustomAttribute<IgnoreOperationAttribute>(true) != null) return; // ignore

                foreach (var methodInfo in classType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (methodInfo.IsSpecialName && (methodInfo.Name.StartsWith("set_") || methodInfo.Name.StartsWith("get_"))) continue; // as property
                    if (methodInfo.GetCustomAttribute<IgnoreOperationAttribute>(true) != null) continue; // ignore

                    var methodName = methodInfo.Name;

                    // ignore default methods
                    if (methodName == "Equals"
                     || methodName == "GetHashCode"
                     || methodName == "GetType"
                     || methodName == "ToString")
                    {
                        continue;
                    }

                    var sw = Stopwatch.StartNew();

                    // create handler
                    var handler = new OperationHandler(options, classType, methodInfo);
                    lock (handlers)
                    {
                        // fail duplicate entry
                        var path = new RequestPath(className, methodName);
                        if (handlers.ContainsKey(path))
                        {
                            throw new InvalidOperationException(string.Format("same class and method is not allowed, class:{0} method:{1}", className, methodName));
                        }
                        handlers.Add(path, handler);
                    }

                    sw.Stop();
                    options.Logger.RegisiterOperation(handler.ClassName, handler.MethodName, sw.Elapsed.TotalMilliseconds);
                }
            });

            // return readonly operation info
            return handlers.Select(x => new KeyValuePair<string, OperationInfo>(x.Key.ToString(), new OperationInfo(x.Value))).ToList().AsReadOnly();
        }
开发者ID:neuecc,项目名称:LightNode,代码行数:68,代码来源:LightNodeServer.cs

示例12: RegisterAssemblyTypes

        private static void RegisterAssemblyTypes(ContainerBuilder builder, Assembly[] vuelingAssemblies)
        {
            var vuelingTypes = vuelingAssemblies.SelectMany(a => a.GetTypes())
                .Where(t => !t.IsInterface && !t.IsAbstract).OrderBy(t => t.Name).ToList();
            var interfacesImplements = new Dictionary<Type, Type>();

            Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract).ToList()
                .ForEach(c => RegisterTypeDependencies(c, vuelingTypes, interfacesImplements));

            interfacesImplements.ToList().ForEach(
                delegate(KeyValuePair<Type, Type> ii)
                {

                    builder.RegisterType(ii.Value).As(ii.Key).AsImplementedInterfaces();

                });
        }
开发者ID:jcgonzalezalzate,项目名称:HerbProject,代码行数:17,代码来源:DIGlobalRegister.cs

示例13: RegisterHandler

        public static void RegisterHandler(Assembly[] hostAssemblies)
        {
            if (Interlocked.Increment(ref alreadyRegistered) != 0) return;

            var contractTypes = hostAssemblies
                .SelectMany(x => x.GetTypes())
                .Where(x => typeof(LightNodeContract).IsAssignableFrom(x));

            Parallel.ForEach(contractTypes, classType =>
            {
                var className = classType.Name;
                foreach (var methodInfo in classType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (methodInfo.IsSpecialName && (methodInfo.Name.StartsWith("set_") || methodInfo.Name.StartsWith("get_"))) continue; // as property

                    var methodName = methodInfo.Name;

                    // ignore default methods
                    if (methodName == "Equals"
                     || methodName == "GetHashCode"
                     || methodName == "GetType"
                     || methodName == "ToString")
                    {
                        continue;
                    }

                    var handler = new OperationHandler();

                    handler.MethodName = methodName;
                    handler.Arguments = methodInfo.GetParameters();
                    handler.ReturnType = methodInfo.ReturnType;

                    foreach (var argument in handler.Arguments)
                    {
                        if (!AllowRequestType.IsAllowType(argument.ParameterType))
                        {
                            throw new InvalidOperationException(string.Format("parameter is not allowed, class:{0} method:{1} paramName:{2} paramType:{3}",
                                className, methodName, argument.Name, argument.ParameterType.FullName));
                        }
                    }

                    // prepare lambda parameters
                    var envArg = Expression.Parameter(typeof(IDictionary<string, object>), "environment");
                    var envBind = Expression.Bind(typeof(LightNodeContract).GetProperty("Environment"), envArg);
                    var args = Expression.Parameter(typeof(object[]), "args");
                    var parameters = methodInfo.GetParameters()
                        .Select((x, i) => Expression.Convert(Expression.ArrayIndex(args, Expression.Constant(i)), x.ParameterType))
                        .ToArray();

                    // Task or Task<T>
                    if (typeof(Task).IsAssignableFrom(handler.ReturnType))
                    {
                        // (object[] args) => new X().M((T1)args[0], (T2)args[1])...
                        var lambda = Expression.Lambda<Func<IDictionary<string, object>, object[], Task>>(
                            Expression.Call(
                                Expression.MemberInit(Expression.New(classType), envBind),
                                methodInfo,
                                parameters),
                            envArg, args);

                        if (handler.ReturnType.IsGenericType && handler.ReturnType.GetGenericTypeDefinition() == typeof(Task<>))
                        {
                            handler.HandlerBodyType = HandlerBodyType.AsyncFunc;
                            handler.MethodAsyncFuncBody = lambda.Compile();

                            lock (taskResultExtractors)
                            {
                                if (!taskResultExtractors.ContainsKey(handler.ReturnType))
                                {
                                    // (object task) => (object)((Task<>).Result)
                                    var taskParameter = Expression.Parameter(typeof(object), "task");
                                    var resultLambda = Expression.Lambda<Func<object, object>>(
                                        Expression.Convert(
                                            Expression.Property(
                                                Expression.Convert(taskParameter, handler.ReturnType),
                                                "Result"),
                                            typeof(object)),
                                        taskParameter);

                                    var compiledResultLambda = resultLambda.Compile();

                                    taskResultExtractors[handler.ReturnType] = compiledResultLambda;
                                }
                            }
                        }
                        else
                        {
                            handler.HandlerBodyType = HandlerBodyType.AsyncAction;
                            handler.MethodAsyncActionBody = lambda.Compile();
                        }
                    }
                    else if (handler.ReturnType == typeof(void)) // of course void
                    {
                        // (object[] args) => { new X().M((T1)args[0], (T2)args[1])... }
                        var lambda = Expression.Lambda<Action<IDictionary<string, object>, object[]>>(
                            Expression.Call(
                                Expression.MemberInit(Expression.New(classType), envBind),
                                methodInfo,
                                parameters),
                            envArg, args);
//.........这里部分代码省略.........
开发者ID:rabitarochan,项目名称:LightNode,代码行数:101,代码来源:LightNodeServer.cs

示例14: SetUpDefaults

        private void SetUpDefaults(Assembly[] assemblies)
        {
            var availableHandlerTypes = FindAvailableHandlerTypes(assemblies).ToList();

            FindSagaIdsFor = GetDefaultFindSagaIdsFor(availableHandlerTypes);

            var streamPersisterType = assemblies.SelectMany(x => x.GetTypes()).FirstOrDefault(x => !x.IsAbstract && typeof(ISagaStreamPersister).IsAssignableFrom(x));

            GetStreamPersister = () =>
                {
                    if (streamPersisterType == null) return null;

                    return Construct(streamPersisterType) as ISagaStreamPersister;
                };

            FindMessageHandler = GetDefaultFindMessageHandler(availableHandlerTypes);

            Construct = GetDefaultConstruct();
        }
开发者ID:UStack,项目名称:USaga,代码行数:19,代码来源:Configuration.cs


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