Пример #1
0
        public NodeSelector Create <T>()
            where T : class
        {
            NodeSelector next = null;

            if (_nextFactory != null)
            {
                next = _nextFactory.Create <T>();
            }

            if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Token <,>))
            {
                Type[] arguments = typeof(T).GetGenericArguments();
                if (arguments[1] != typeof(TValue))
                {
                    throw new ArgumentException("Value type does not match token type");
                }

                Type nodeType = typeof(NotNullNodeSelector <,>).MakeGenericType(arguments);

                var selector = (NodeSelector)Activator.CreateInstance(nodeType, next, _configurator);

                return(selector);
            }

            throw new ArgumentException("Type was not a token type: " + typeof(T).FullName);
        }
Пример #2
0
        public NodeSelector Create <T>()
            where T : class
        {
            NodeSelector next = null;

            if (_nextFactory != null)
            {
                next = _nextFactory.Create <Token <T, TProperty> >();
            }

            if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Token <,>))
            {
                var arguments = typeof(T).GetGenericArguments();

                Type tokenType     = typeof(PropertyNodeSelector <, ,>).MakeGenericType(arguments[0], arguments[1], typeof(TProperty));
                var  tokenSelector = (NodeSelector)Activator.CreateInstance(tokenType, next, _configurator, _propertyInfo);

                return(tokenSelector);
            }

            Type type     = typeof(PropertyNodeSelector <,>).MakeGenericType(typeof(T), typeof(TProperty));
            var  selector = (NodeSelector)Activator.CreateInstance(type, next, _configurator, _propertyInfo);

            return(selector);
        }
Пример #3
0
        public NodeSelector Create <T>()
            where T : class
        {
            NodeSelector next = null;

            if (_nextFactory != null)
            {
                next = _nextFactory.Create <T>();
            }

            var selector = new TypeNodeSelector <T>(next, _configurator);

            return(selector);
        }
        public NodeSelector Create <T>()
            where T : class
        {
            NodeSelector next = null;

            if (_nextFactory != null)
            {
                next = _nextFactory.Create <Token <T, TElement> >();
            }

            Type type     = typeof(ListNodeSelector <,>).MakeGenericType(typeof(T), typeof(TElement));
            var  selector = (NodeSelector)Activator.CreateInstance(type, next, _index);

            return(selector);
        }
Пример #5
0
        public NodeSelector Create <T>()
            where T : class
        {
            NodeSelector next = null;

            if (_nextFactory != null)
            {
                next = _nextFactory.Create <Token <T, Tuple <TElement, int> > >();
            }

            if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Token <,>))
            {
                Type[] arguments = typeof(T).GetGenericArguments();
                if (arguments[1] != typeof(TValue))
                {
                    throw new ArgumentException("Value type does not match token type");
                }

                if (typeof(IList <TElement>).IsAssignableFrom(typeof(TValue)))
                {
                    Type elementType = typeof(TValue).GetGenericArguments()[0];
                    if (elementType != typeof(TElement))
                    {
                        throw new ArgumentException("Element type does not match list element type");
                    }

                    Type nodeType = typeof(ListEachNodeSelector <, ,>).MakeGenericType(arguments[0], arguments[1],
                                                                                       elementType);

                    var selector = (NodeSelector)Activator.CreateInstance(nodeType, next, _configurator);

                    return(selector);
                }

                throw new ArgumentException("Unknown enumerable type: " + typeof(T).GetShortName());
            }

            throw new ArgumentException("Type was not a token type: " + typeof(T).FullName);
        }