Exemplo n.º 1
0
        static RuleElementRegistry()
        {
            var actionTypes =
                typeof(RuleElementRegistry).Assembly
                .GetTypes()
                .Where(x => typeof(RuleAction).IsAssignableFrom(x))
                .Where(x => x.GetCustomAttribute <RuleActionAttribute>() != null)
                .Where(x => x.GetCustomAttribute <RuleActionHandlerAttribute>() != null)
                .ToList();

            foreach (var actionType in actionTypes)
            {
                var name = actionType.Name;

                if (name.EndsWith(Suffix, StringComparison.Ordinal))
                {
                    name = name.Substring(0, name.Length - Suffix.Length);
                }

                var metadata = actionType.GetCustomAttribute <RuleActionAttribute>();

                ActionTypes[name] =
                    new RuleElement
                {
                    Type        = actionType,
                    Display     = metadata.Display,
                    Description = metadata.Description,
                    IconColor   = metadata.IconColor,
                    IconImage   = metadata.IconImage,
                    ReadMore    = metadata.ReadMore
                };

                ActionHandlerTypes.Add(actionType.GetCustomAttribute <RuleActionHandlerAttribute>().HandlerType);
            }
        }
Exemplo n.º 2
0
        static RuleElementRegistry()
        {
            var actionTypes =
                typeof(RuleElementRegistry).Assembly
                .GetTypes()
                .Where(x => typeof(RuleAction).IsAssignableFrom(x))
                .Where(x => x.GetCustomAttribute <RuleActionAttribute>() != null)
                .Where(x => x.GetCustomAttribute <RuleActionHandlerAttribute>() != null)
                .ToList();

            foreach (var actionType in actionTypes)
            {
                var name = GetActionName(actionType);

                var metadata = actionType.GetCustomAttribute <RuleActionAttribute>();

                ActionTypes[name] =
                    new RuleElement
                {
                    Type        = actionType,
                    Display     = metadata.Display,
                    Description = metadata.Description,
                    IconColor   = metadata.IconColor,
                    IconImage   = metadata.IconImage,
                    ReadMore    = metadata.ReadMore
                };

                ActionHandlerTypes.Add(actionType.GetCustomAttribute <RuleActionHandlerAttribute>().HandlerType);
            }
        }