/// <summary>
        /// Adds a truthy check for a specific type to determine if the value can be considered 'Truthy'
        /// </summary>
        /// <typeparam name="T">The type to evaluate</typeparam>
        /// <param name="expr">How to evaluate the value</param>
        /// <returns>The builder for chaining calls</returns>
        public CompilerSettingsBuilder AddTruthyCheck <T>(Expression <Func <T, bool> > expr)
        {
            if (TruthyChecks.TryGetValue(typeof(T), out var check))
            {
                check.Add(expr);
            }
            else
            {
                TruthyChecks.Add(typeof(T), new List <LambdaExpression>()
                {
                    expr
                });
            }

            return(this);
        }
Example #2
0
        /// <summary>
        /// Adds a truthy check
        /// </summary>
        /// <param name="truthyCheck">A truthy check</param>
        /// <returns>The <see cref="RendererSettingsBuilder"/> for chaining</returns>
        /// <typeparam name="T">The type the truthy check is for</typeparam>
        public RendererSettingsBuilder AddTruthyCheck <T>(Func <T, bool> truthyCheck)
        {
            if (TruthyChecks.TryGetValue(typeof(T), out var check))
            {
                TruthyChecks[typeof(T)].Add(CastFunc);
            }
            else
            {
                TruthyChecks.Add(typeof(T), new List <Func <object, bool> >()
                {
                    CastFunc
                });
            }

            return(this);

            bool CastFunc(object obj) => truthyCheck((T)obj);
        }
Example #3
0
 /// <summary>
 /// Adds a truthy check
 /// </summary>
 /// <param name="truthyCheck">A truthy check</param>
 /// <returns>The <see cref="RendererSettingsBuilder"/> for chaining</returns>
 public RendererSettingsBuilder AddTruthyCheck(Func <object, bool?> truthyCheck)
 {
     TruthyChecks.Add(truthyCheck);
     return(this);
 }