Ejemplo n.º 1
0
        /// <summary>
        ///     Reveals any hidden members using the given property name and revealing convention.
        /// </summary>
        /// <param name="name">
        ///     The property name.
        /// </param>
        /// <param name="convention">
        ///     The convention.
        /// </param>
        /// <returns>
        ///     The name of the hidden member.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///     <paramref name="name" /> is null or empty.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="convention" /> is null.
        /// </exception>
        protected virtual string Reveal(string name, IRevealConvention convention)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("name");
            }

            if (convention == null)
            {
                throw new ArgumentNullException("convention");
            }

            if (name.Contains("."))
            {
                string[] splits = name.Split('.');

                string temp = string.Empty;

                for (int i = 0; i < splits.Length - 1; i++)
                {
                    temp += splits[i] + ".";
                }

                return(temp + convention.RevealFrom(splits[splits.Length - 1]));
            }

            return(convention.RevealFrom(name));
        }
Ejemplo n.º 2
0
 public new IFetchBuilder <IDummyQuery3> Fetch
 (
     Expression <Func <UserEntity, object> > expression,
     Expression <Func <object> > alias  = null,
     IRevealConvention revealConvention = null
 )
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Sets the default <see cref="IRevealConvention" /> instance (<seealso cref="DefaultConvention" />).
        /// </summary>
        /// <param name="convention">
        ///     The <see cref="IRevealConvention" /> instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="convention" /> is null.
        /// </exception>
        public static void SetDefaultConvention(IRevealConvention convention)
        {
            if (convention == null)
            {
                throw new ArgumentNullException("convention");
            }

            DefaultConvention = convention;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Sets the default <see cref="IRevealConvention" /> instance (<seealso cref="DefaultConvention" />) using
        ///     the specified convention.
        /// </summary>
        /// <param name="convention">
        ///     The convention.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="convention" /> is null.
        /// </exception>
        public static void SetDefaultConvention(Func <string, string> convention)
        {
            if (convention == null)
            {
                throw new ArgumentNullException("convention");
            }

            DefaultConvention = new CustomConvention(convention);
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public virtual string Reveal
 (
     Expression <Func <TEntity> > alias,
     Expression <Func <TEntity, object> > expression,
     IRevealConvention convention
 )
 {
     return(Reveal <TEntity>(alias, expression, convention));
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RevealerBase" /> class.
        /// </summary>
        /// <param name="convention">
        ///     The <see cref="IRevealConvention" /> instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="convention" /> is null.
        /// </exception>
        protected RevealerBase(IRevealConvention convention)
        {
            if (convention == null)
            {
                throw new ArgumentNullException("convention");
            }

            RevealConvention = convention;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Reveals any hidden members using the provided expression and revealing convention.
        /// </summary>
        /// <param name="expression">
        ///     The expression.
        /// </param>
        /// <param name="convention">
        ///     The revealing convention.
        /// </param>
        /// <typeparam name="TEntity">
        ///     The <see cref="System.Type" /> of the entity.
        /// </typeparam>
        /// <returns>
        ///     The hidden member name.
        /// </returns>
        public static string ByConvention <TEntity>
        (
            Expression <Func <TEntity, object> > expression,
            IRevealConvention convention
        )
        {
            IRevealer revealer = new Revealer(convention);

            return(revealer.Reveal(expression));
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public virtual string Reveal(Expression <Func <object> > expression, IRevealConvention convention)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            string property = ExpressionHelper.GetPropertyName(expression.Body);

            return(Reveal(property, convention));
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public IFilterableQuery <TSource> Join <TAlias>
        (
            Expression <Func <TSource, object> > projection,
            Expression <Func <TAlias> > alias,
            IRevealConvention revealConvention
        )
        {
            _joinBuilder.Join(projection, alias, revealConvention);

            return(_query);
        }
Ejemplo n.º 10
0
        public void SetDefaultConventionThrowsIfConventionIsNull()
        {
            IRevealConvention c = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.That(() => Reveal.SetDefaultConvention(c), Throws.InstanceOf <ArgumentNullException>());

            Func <string, string> d = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.That(() => Reveal.SetDefaultConvention(d), Throws.InstanceOf <ArgumentNullException>());
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        public IFilterableQuery <T> Join <TAlias>
        (
            Expression <Func <T, object> > projection,
            Expression <Func <TAlias> > alias,
            IRevealConvention revealConvention
        )
        {
            var temp = _rebaser.RebaseTo <TSource, object>(projection);

            _joinBuilder.Join(temp, alias, revealConvention);

            return(_query);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public virtual IFetchBuilder <TQuery> Fetch
        (
            Expression <Func <TSource, object> > expression,
            Expression <Func <object> > alias  = null,
            IRevealConvention revealConvention = null
        )
        {
            if (revealConvention == null)
            {
                revealConvention = Reveal.DefaultConvention ?? new CustomConvention(x => x);
            }

            string path = Reveal.ByConvention(expression, revealConvention);

            string aliasValue = alias != null
                ? ExpressionHelper.GetPropertyName(alias)
                : path;

            return(FetchCore(path, aliasValue));
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        public virtual string Reveal <TEntity>
        (
            Expression <Func <TEntity> > alias,
            Expression <Func <TEntity, object> > expression,
            IRevealConvention convention
        )
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            string property = ExpressionHelper.GetPropertyName(expression);

            string aliasName = ExpressionHelper.GetPropertyName(alias);

            return(Reveal(aliasName + "." + property, convention));
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Revealer" /> class.
 /// </summary>
 /// <param name="convention">
 ///     The <see cref="IRevealConvention" /> convention.
 /// </param>
 public Revealer(IRevealConvention convention)
     : base(convention)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 ///     Creates a new <see cref="IRevealer" /> instance using the specified <see cref="IRevealConvention" />
 ///     instance.
 /// </summary>
 /// <param name="convention">
 ///     The <see cref="IRevealConvention" /> instance.
 /// </param>
 /// <returns>
 ///     The created <see cref="IRevealer" /> instance.
 /// </returns>
 public static IRevealer CreateRevealer(IRevealConvention convention)
 {
     return(new Revealer(convention));
 }
Ejemplo n.º 16
0
 /// <summary>
 ///     Creates a new <see cref="IRevealer{TEntity}" /> instance using the specified
 ///     <see cref="IRevealConvention" /> instance.
 /// </summary>
 /// <param name="convention">
 ///     The <see cref="IRevealConvention" /> instance.
 /// </param>
 /// <typeparam name="TEntity">
 ///     The <see cref="System.Type" /> of the entity.
 /// </typeparam>
 /// <returns>
 ///     The created <see cref="IRevealer{TEntity}" /> instance.
 /// </returns>
 public static IRevealer <TEntity> CreateRevealer <TEntity>(IRevealConvention convention)
 {
     return(new Revealer <TEntity>(convention));
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Removes the default <see cref="IRevealConvention" /> instance (<seealso cref="DefaultConvention" />).
 /// </summary>
 public static void ClearDefaultConvention()
 {
     DefaultConvention = null;
 }