當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。