Example #1
0
        public void Decorate <T>(T instance)
        {
            PropertyInfo[] properties = instance.GetType().GetProperties();
            foreach (PropertyInfo property in properties)
            {
                Object[] attributes = (Object[])property.GetCustomAttributes(typeof(Attribute), true);
                foreach (Object obj in attributes)
                {
                    PropertyAttribute propertyAttribute = _instantiator.GetInstanceByType <PropertyAttribute>(obj.GetType(), new Object[0]);
                    propertyAttribute.Decorator = this;
                    propertyAttribute.DecorateProperty(instance, property);
                }
            }

            MethodInfo[] methods = instance.GetType().GetMethods();
            foreach (MethodInfo method in methods)
            {
                Object[] attributes = (Object[])method.GetCustomAttributes(typeof(MethodAttribute), true);
                for (int j = attributes.Length - 1; j >= 0; j--)
                {
                    Object          obj             = attributes[j];
                    MethodAttribute methodAttribute = _instantiator.GetInstanceByType <MethodAttribute>(obj.GetType(), new Object[0]);
                    methodAttribute.Decorator = this;
                    methodAttribute.DecorateMethod(instance, method);
                }
            }
        }