public ObjectConditional( Type type, PropertyCondition[][] conditions )
 {
     m_Type = type;
     m_Conditions = conditions;
 }
        public static ObjectConditional Parse( Mobile from, ref string[] args )
        {
            string[] conditionArgs = null;

            for ( int i = 0; i < args.Length; ++i )
            {
                if ( Insensitive.Equals( args[i], "where" ) )
                {
                    string[] origArgs = args;

                    args = new string[i];

                    for ( int j = 0; j < args.Length; ++j )
                        args[j] = origArgs[j];

                    conditionArgs = new string[origArgs.Length - i - 1];

                    for ( int j = 0; j < conditionArgs.Length; ++j )
                        conditionArgs[j] = origArgs[i + j + 1];

                    break;
                }
            }

            if ( conditionArgs == null || conditionArgs.Length == 0 )
                return ObjectConditional.Empty;

            int index = 0;

            Type type = ScriptCompiler.FindTypeByName( conditionArgs[index++], true );

            if ( type == null )
                throw new Exception( String.Format( "No type with that name ({0}) was found.", conditionArgs[0] ) );

            PropertyInfo[] props = type.GetProperties();

            ArrayList allConditions = new ArrayList();
            ArrayList currentConditions = null;

            while ( index < conditionArgs.Length )
            {
                string cur = conditionArgs[index];

                bool logicalNot = false;

                if ( Insensitive.Equals( cur, "not" ) || cur == "!" )
                {
                    logicalNot = true;
                    ++index;

                    if ( index >= conditionArgs.Length )
                        throw new Exception( "Improperly formatted object conditional." );
                }
                else if ( Insensitive.Equals( cur, "or" ) || cur == "||" )
                {
                    if ( currentConditions != null )
                    {
                        allConditions.Add( currentConditions );
                        currentConditions = null;
                    }

                    ++index;

                    continue;
                }

                string prop = conditionArgs[index++];

                if ( index >= conditionArgs.Length )
                    throw new Exception( "Improperly formatted object conditional." );

                string oper = conditionArgs[index++];

                if ( index >= conditionArgs.Length )
                    throw new Exception( "Improperly formatted object conditional." );

                string arg = conditionArgs[index++];

                if ( currentConditions == null )
                    currentConditions = new ArrayList();

                currentConditions.Add( new PropertyCondition( from, type, props, prop, oper, arg, logicalNot ) );
            }

            if ( currentConditions != null )
                allConditions.Add( currentConditions );

            PropertyCondition[][] conditions = new PropertyCondition[allConditions.Count][];

            for ( int i = 0; i < conditions.Length; ++i )
                conditions[i] = (PropertyCondition[])(((ArrayList)allConditions[i]).ToArray( typeof( PropertyCondition ) ));

            return new ObjectConditional( type, conditions );
        }
        public static ObjectConditional Parse(Mobile from, ref string[] args)
        {
            string[] conditionArgs = null;

            for (int i = 0; i < args.Length; ++i)
            {
                if (Insensitive.Equals(args[i], "where"))
                {
                    string[] origArgs = args;

                    args = new string[i];

                    for (int j = 0; j < args.Length; ++j)
                    {
                        args[j] = origArgs[j];
                    }

                    conditionArgs = new string[origArgs.Length - i - 1];

                    for (int j = 0; j < conditionArgs.Length; ++j)
                    {
                        conditionArgs[j] = origArgs[i + j + 1];
                    }

                    break;
                }
            }

            if (conditionArgs == null || conditionArgs.Length == 0)
            {
                return(ObjectConditional.Empty);
            }

            int index = 0;

            Type type = ScriptCompiler.FindTypeByName(conditionArgs[index++], true);

            if (type == null)
            {
                throw new Exception(String.Format("No type with that name ({0}) was found.", conditionArgs[0]));
            }

            PropertyInfo[] props = type.GetProperties();

            ArrayList allConditions     = new ArrayList();
            ArrayList currentConditions = null;

            while (index < conditionArgs.Length)
            {
                string cur = conditionArgs[index];

                bool logicalNot = false;

                if (Insensitive.Equals(cur, "not") || cur == "!")
                {
                    logicalNot = true;
                    ++index;

                    if (index >= conditionArgs.Length)
                    {
                        throw new Exception("Improperly formatted object conditional.");
                    }
                }
                else if (Insensitive.Equals(cur, "or") || cur == "||")
                {
                    if (currentConditions != null)
                    {
                        allConditions.Add(currentConditions);
                        currentConditions = null;
                    }

                    ++index;

                    continue;
                }

                string prop = conditionArgs[index++];

                if (index >= conditionArgs.Length)
                {
                    throw new Exception("Improperly formatted object conditional.");
                }

                string oper = conditionArgs[index++];

                if (index >= conditionArgs.Length)
                {
                    throw new Exception("Improperly formatted object conditional.");
                }

                string arg = conditionArgs[index++];

                if (currentConditions == null)
                {
                    currentConditions = new ArrayList();
                }

                currentConditions.Add(new PropertyCondition(from, type, props, prop, oper, arg, logicalNot));
            }

            if (currentConditions != null)
            {
                allConditions.Add(currentConditions);
            }

            PropertyCondition[][] conditions = new PropertyCondition[allConditions.Count][];

            for (int i = 0; i < conditions.Length; ++i)
            {
                conditions[i] = (PropertyCondition[])(((ArrayList)allConditions[i]).ToArray(typeof(PropertyCondition)));
            }

            return(new ObjectConditional(type, conditions));
        }