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


C# Castle.ToList方法代码示例

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


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

示例1: SelectInterceptors

        public Castle.DynamicProxy.IInterceptor[] SelectInterceptors(Type type, MethodInfo method, Castle.DynamicProxy.IInterceptor[] interceptors)
        {
            //var attributes = method.GetCustomAttributes<Intercept2Attribute>();
            //if (type.IsClass)
            //    attributes = type.GetMethod(method.Name).GetCustomAttributes<Intercept2Attribute>();

            var allCustomAttributes = method.GetCustomAttributes()
                                            .Concat(type.GetMethod(method.Name).GetCustomAttributes())
                                            .Concat(type.GetCustomAttributes())
                                            .ToList();

            var allInterceptorAttributes = allCustomAttributes.Where(attr => attr.GetType() == typeof(Intercept2Attribute));

            var allInterceptors = allCustomAttributes
                                                .Where(attr => typeof(BaseInterceptAttribute).IsAssignableFrom(attr.GetType()));

            List<Type> addedInterceptorTypes = interceptors.Select(i => i.GetType()).ToList();
            List<Castle.DynamicProxy.IInterceptor> outInterceptors = interceptors.ToList();

            foreach (var attribute in allInterceptorAttributes)
            {
                var interceptorTypes = (attribute as Intercept2Attribute).InterceptorTypes;
                foreach (var interceptorType in interceptorTypes)
                {
                    var interceptor = interceptors.FirstOrDefault(i => i.GetType() == interceptorType);
                    if (interceptor == null)
                        interceptor = Activator.CreateInstance(interceptorType) as IInterceptor;
                    if (!addedInterceptorTypes.Contains(interceptorType))
                    {
                        addedInterceptorTypes.Add(interceptorType);
                        outInterceptors.Add(interceptor);
                    }
                }
            }

            foreach (var interceptor in allInterceptors)
            {
                var interceptAttribute = (interceptor as BaseInterceptAttribute);

                var interceptorType = interceptAttribute.InterceptType;

                if (interceptAttribute.Enabled)
                {
                    var addInterceptor = interceptors.FirstOrDefault(i => i.GetType() == interceptorType);
                    if (addInterceptor == null)
                        addInterceptor = Activator.CreateInstance(interceptorType) as IInterceptor;
                    if (!addedInterceptorTypes.Contains(interceptorType))
                    {
                        addedInterceptorTypes.Add(interceptorType);
                        outInterceptors.Add(addInterceptor);
                    }
                }
            }

            return outInterceptors.ToArray();
        }
开发者ID:cielqian,项目名称:CFramework,代码行数:56,代码来源:InterceptorSelector.cs


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