public static void RefreshParsers()
        {
            var supportedSignatures = new[]
            {
                MethodSignature.FromDelegate <SearchExpressionParserHandler>(),
                MethodSignature.FromDelegate <SearchExpressionParserHandlerStringView>(),
                MethodSignature.FromDelegate <SearchExpressionParserWithContextHandler>(),
                MethodSignature.FromDelegate <SearchExpressionParserWithStructHandler>()
            };

            parsers = ReflectionUtils.LoadAllMethodsWithAttribute <SearchExpressionParserAttribute, SearchExpressionParser>(
                (mi, attribute, handler) =>
            {
                if (handler is SearchExpressionParserWithStructHandler handlerWithStruct)
                {
                    return(new SearchExpressionParser(attribute.name, attribute.priority, handlerWithStruct));
                }
                if (handler is SearchExpressionParserWithContextHandler handlerWithContext)
                {
                    return(new SearchExpressionParser(attribute.name, attribute.priority, args => handlerWithContext(args.text.ToString(), args.context)));
                }
                if (handler is SearchExpressionParserHandlerStringView handlerStringView)
                {
                    return(new SearchExpressionParser(attribute.name, attribute.priority, (args) => handlerStringView(args.text)));
                }
                if (handler is SearchExpressionParserHandler handlerNoContext)
                {
                    return(new SearchExpressionParser(attribute.name, attribute.priority, (args) => handlerNoContext(args.text.ToString())));
                }
                throw new CustomAttributeFormatException($"Invalid parser handler {attribute.name} using {mi.DeclaringType.FullName}.{mi.Name}");
            },
                supportedSignatures, ReflectionUtils.AttributeLoaderBehavior.DoNotThrowOnValidation).ToList();
            parsers.Sort((a, b) => a.priority.CompareTo(b.priority));
        }
        private static void RefreshSelectors()
        {
            Func <MethodInfo, SearchSelectorAttribute, Delegate, SearchSelector> generator = (mi, attribute, handler) =>
            {
                if (handler is SearchSelectorHandler handlerWithStruct)
                {
                    return(new SearchSelector(attribute, handlerWithStruct));
                }
                if (handler is SearchSelectorHandler1 handler1)
                {
                    return(new SearchSelector(attribute, args => handler1(args.current)));
                }
                if (handler is SearchSelectorHandler2 handler2)
                {
                    return(new SearchSelector(attribute, args => handler2(args.current)));
                }
                throw new CustomAttributeFormatException($"Invalid selector handler {mi.DeclaringType.FullName}.{mi.Name}");
            };

            var supportedSignatures = new[]
            {
                MethodSignature.FromDelegate <SearchSelectorHandler>(),
                MethodSignature.FromDelegate <SearchSelectorHandler1>(),
                MethodSignature.FromDelegate <SearchSelectorHandler2>()
            };

            selectors = ReflectionUtils.LoadAllMethodsWithAttribute(generator, supportedSignatures)
                        .Where(s => s.valid)
                        .OrderBy(s => s.priority)
                        .OrderBy(s => string.IsNullOrEmpty(s.provider))
                        .ToList();
        }
Пример #3
0
        internal static void RefreshSelectors()
        {
            Func <MethodInfo, SearchSelectorAttribute, Delegate, SearchSelector> generator = (mi, attribute, handler) =>
            {
                var descAttr = mi.GetAttribute <System.ComponentModel.DescriptionAttribute>();
                if (handler is SearchSelectorHandler handlerWithStruct)
                {
                    return(new SearchSelector(attribute, handlerWithStruct, descAttr?.Description));
                }
                if (handler is SearchSelectorHandler1 handler1)
                {
                    return(new SearchSelector(attribute, args => handler1(args.current), descAttr?.Description));
                }
                if (handler is SearchSelectorHandler2 handler2)
                {
                    return(new SearchSelector(attribute, args => handler2(args.current), descAttr?.Description));
                }
                throw new CustomAttributeFormatException($"Invalid selector handler {mi.DeclaringType.FullName}.{mi.Name}");
            };

            var supportedSignatures = new[]
            {
                MethodSignature.FromDelegate <SearchSelectorHandler>(),
                MethodSignature.FromDelegate <SearchSelectorHandler1>(),
                MethodSignature.FromDelegate <SearchSelectorHandler2>()
            };

            selectors = ReflectionUtils.LoadAllMethodsWithAttribute(generator, supportedSignatures, ReflectionUtils.AttributeLoaderBehavior.DoNotThrowOnValidation)
                        .Where(s => s.valid)
                        .OrderBy(s => s.priority)
                        .OrderBy(s => string.IsNullOrEmpty(s.provider))
                        .ToList();
        }
Пример #4
0
        internal static void RefreshObjectSelectors()
        {
            var validators = ReflectionUtils.LoadAllMethodsWithAttribute <AdvancedObjectSelectorValidatorAttribute, AdvancedObjectSelectorValidator>(
                (loaded, mi, attribute, handler) =>
                LoadAdvancedObjectSelectorAttribute <AdvancedObjectSelectorValidatorAttribute, AdvancedObjectSelectorValidator, AdvancedObjectSelectorValidatorHandler>(
                    loaded, mi, attribute, handler, "Advanced Object Selector Validator", (a, h) => GenerateAdvancedObjectSelectorValidatorWrapper(a, h)),
                MethodSignature.FromDelegate <AdvancedObjectSelectorValidatorHandler>(), ReflectionUtils.AttributeLoaderBehavior.DoNotThrowOnValidation).ToDictionary(validator => validator.id.GetHashCode());

            ObjectSelectors = ReflectionUtils.LoadAllMethodsWithAttribute <AdvancedObjectSelectorAttribute, AdvancedObjectSelector>(
                (loaded, mi, attribute, handler) =>
                LoadAdvancedObjectSelectorAttribute <AdvancedObjectSelectorAttribute, AdvancedObjectSelector, AdvancedObjectSelectorHandler>(
                    loaded, mi, attribute, handler, "Advanced Object Selector", (a, h) => GenerateAdvancedObjectSelectorWrapper(validators, a, h)),
                MethodSignature.FromDelegate <AdvancedObjectSelectorHandler>(), ReflectionUtils.AttributeLoaderBehavior.DoNotThrowOnValidation).ToList();
        }
Пример #5
0
        static SearchColumnProvider()
        {
            Func <MethodInfo, SearchColumnProviderAttribute, Delegate, SearchColumnProvider> generator = (mi, attribute, handler) =>
            {
                if (handler is SearchColumnProviderHandler handlerWithStruct)
                {
                    return(new SearchColumnProvider(attribute.provider, handlerWithStruct));
                }
                throw new CustomAttributeFormatException($"Invalid search column provider handler {mi.DeclaringType.FullName}.{mi.Name}");
            };

            var supportedSignatures = new[] { MethodSignature.FromDelegate <SearchColumnProviderHandler>() };

            providers = ReflectionUtils.LoadAllMethodsWithAttribute(generator, supportedSignatures).ToList();
        }
Пример #6
0
        public static void RefreshSerializers()
        {
            s_Serializers.Clear();
            s_Deserializers.Clear();

            var serializers = ReflectionUtils.LoadAllMethodsWithAttribute <PropertyDatabaseSerializerAttribute, PropertyDatabaseSerializer>((info, attribute, handler) =>
            {
                if (handler is PropertySerializerHandler psh)
                {
                    return(new PropertyDatabaseSerializer(attribute.type, psh));
                }
                throw new Exception($"Invalid {nameof(PropertyDatabaseSerializerAttribute)} handler.");
            }, MethodSignature.FromDelegate <PropertySerializerHandler>());

            var deserializers = ReflectionUtils.LoadAllMethodsWithAttribute <PropertyDatabaseDeserializerAttribute, PropertyDatabaseDeserializer>((info, attribute, handler) =>
            {
                if (handler is PropertyDeserializerHandler psh)
                {
                    return(new PropertyDatabaseDeserializer(attribute.type, psh));
                }
                throw new Exception($"Invalid {nameof(PropertyDatabaseDeserializerAttribute)} handler.");
            }, MethodSignature.FromDelegate <PropertyDeserializerHandler>());

            foreach (var propertySerializer in serializers)
            {
                if (s_Serializers.ContainsKey(propertySerializer.type))
                {
                    continue;
                }
                s_Serializers.Add(propertySerializer.type, propertySerializer);
            }

            foreach (var propertyDeserializer in deserializers)
            {
                if (s_Deserializers.ContainsKey(propertyDeserializer.type))
                {
                    continue;
                }
                s_Deserializers.Add(propertyDeserializer.type, propertyDeserializer);
            }
        }