コード例 #1
0
        private static void Decorate <T>()
            where T : class, new()
        {
            DecoratorContext context = new DecoratorContext()
            {
                TypeDecoratorInfo = TypeDecoratorInfoFactory.CreateInstance(typeof(T))
            };

            GetDecorators <T>().ForEach(d =>
            {
                Workbook = d.Decorate(Workbook, context);
            });
        }
コード例 #2
0
        /// <summary>
        /// 获取所有的装饰器
        /// </summary>
        /// <returns></returns>
        private static List <IDecorator> GetDecorators <T>()
            where T : class, new()

        {
            List <IDecorator>            decorators        = new List <IDecorator>();
            List <BaseDecorateAttribute> attrs             = new List <BaseDecorateAttribute>();
            TypeDecoratorInfo            typeDecoratorInfo = TypeDecoratorInfoFactory.CreateInstance(typeof(T));

            attrs.AddRange(typeDecoratorInfo.TypeDecoratorAttrs);
            typeDecoratorInfo.PropertyDecoratorInfos.ForEach(a => attrs.AddRange(a.DecoratorAttrs));

            attrs.Distinct(new DecoratorAttributeComparer()).ToList().ForEach
                (a =>
            {
                var decorator = DecoratorFactory.CreateInstance(a.GetType());
                if (decorator != null)
                {
                    decorators.Add(decorator);
                }
            });

            return(decorators);
        }