private string GetConditionalValue(object cond)
        {
            string ret = "";

            If           ifCond   = cond as If;
            IfDefined    ifDef    = cond as IfDefined;
            IfNotDefined ifNotDef = cond as IfNotDefined;

            if (ifCond != null)
            {
                if (ifCond.In != null)
                {
                    ret = string.Format(IfInFormat, ifCond.Name, ifCond.In);
                }
                else if (ifCond.Value != null)
                {
                    ret = string.Format(IfEqFormat, ifCond.Name, ifCond.Value);
                }
            }
            else if (ifDef != null)
            {
                ret = string.Format(IfDefFormat, ifDef.Name);
            }
            else if (ifNotDef != null)
            {
                ret = string.Format(IfNotDefFormat, ifNotDef.Name);
            }

            return(ret);
        }
        private object AddConditional(object owner, string conditional)
        {
            if (string.IsNullOrEmpty(conditional))
            {
                return(owner);
            }

            object ret = owner;

            if (m_expIfEq.IsMatch(conditional))
            {
                Match m    = m_expIfEq.Match(conditional);
                If    cond = new If();

                cond.Name  = m.Groups[1].Value;
                cond.Value = m.Groups[2].Value;

                (owner.GetType().GetProperty(typeof(List <If>).Name).GetValue(owner, null) as IList).Add(cond);

                ret = cond;
            }
            else if (m_expIfIn.IsMatch(conditional))
            {
                Match m    = m_expIfIn.Match(conditional);
                If    cond = new If();

                cond.Name = m.Groups[1].Value;
                cond.In   = m.Groups[2].Value;

                (owner.GetType().GetProperty(typeof(List <If>).Name).GetValue(owner, null) as IList).Add(cond);

                ret = cond;
            }
            else if (m_expIfDef.IsMatch(conditional))
            {
                Match     m    = m_expIfDef.Match(conditional);
                IfDefined cond = new IfDefined();

                cond.Name = m.Groups[1].Value;

                (owner.GetType().GetProperty(typeof(List <IfDefined>).Name).GetValue(owner, null) as IList).Add(cond);

                ret = cond;
            }
            else if (m_expIfNotDef.IsMatch(conditional))
            {
                Match        m    = m_expIfNotDef.Match(conditional);
                IfNotDefined cond = new IfNotDefined();

                cond.Name = m.Groups[1].Value;

                (owner.GetType().GetProperty(typeof(List <IfNotDefined>).Name).GetValue(owner, null) as IList).Add(cond);

                ret = cond;
            }

            return(ret);
        }
        public string ToString(Operands operands)
        {
            if (Type == TreeExpressionItemType.Always)
            {
                return(PreprocessorExpression.True);
            }
            if (Type == TreeExpressionItemType.Never)
            {
                return(PreprocessorExpression.False);
            }

            var ifDef    = IfDefined.AsBool();
            var ifNotDef = IfNotDefined.AsBool();

            var sb = new StringBuilder();

            if (ifDef != false)
            {
                if (ifNotDef != false)
                {
                    sb.Append("(");
                }

                {
                    if (ifDef != true)
                    {
                        sb.Append("(");
                    }

                    sb.Append("defined(");
                    sb.Append(operands[Index]);
                    sb.Append(")");
                    if (ifDef != true)
                    {
                        sb.Append(" && ");
                        sb.Append(IfDefined.ToString(operands));
                        sb.Append(")");
                    }
                }
                if (ifNotDef != false)
                {
                    sb.Append(" || ");
                    if (ifNotDef != true)
                    {
                        sb.Append("(");
                    }

                    sb.Append("!defined(");
                    sb.Append(operands[Index]);
                    sb.Append(")");
                    if (ifNotDef != true)
                    {
                        sb.Append(" && ");
                        sb.Append(IfNotDefined.ToString(operands));
                        sb.Append(")");
                    }

                    sb.Append(")");
                }
            }
            else
            {
                if (ifNotDef != true)
                {
                    sb.Append("(");
                }

                sb.Append("!defined(");
                sb.Append(operands[Index]);
                sb.Append(")");
                if (ifNotDef != true)
                {
                    sb.Append(" && ");
                    sb.Append(IfNotDefined.ToString(operands));
                    sb.Append(")");
                }
            }

            return(sb.ToString());
        }