public static Property Parse(Type type, string binding, PropertyAccess access) { Property prop = new Property(binding); prop.BindTo(type, access); return(prop); }
public static Property Parse( Type type, string binding, PropertyAccess access ) { Property prop = new Property( binding ); prop.BindTo( type, access ); return prop; }
public static ObjectConditional ParseDirect( Mobile from, string[] args, int offset, int size ) { if ( args == null || size == 0 ) return ObjectConditional.Empty; int index = 0; Type objectType = ScriptCompiler.FindTypeByName( args[offset + index], true ); if ( objectType == null ) throw new Exception( String.Format( "No type with that name ({0}) was found.", args[offset + index] ) ); ++index; List<ICondition[]> conditions = new List<ICondition[]>(); List<ICondition> current = new List<ICondition>(); current.Add( TypeCondition.Default ); while ( index < size ) { string cur = args[offset + index]; bool inverse = false; if ( Insensitive.Equals( cur, "not" ) || cur == "!" ) { inverse = true; ++index; if ( index >= size ) throw new Exception( "Improperly formatted object conditional." ); } else if ( Insensitive.Equals( cur, "or" ) || cur == "||" ) { if ( current.Count > 1 ) { conditions.Add( current.ToArray() ); current.Clear(); current.Add( TypeCondition.Default ); } ++index; continue; } string binding = args[offset + index]; index++; if ( index >= size ) throw new Exception( "Improperly formatted object conditional." ); string oper = args[offset + index]; index++; if ( index >= size ) throw new Exception( "Improperly formatted object conditional." ); string val = args[offset + index]; index++; Property prop = new Property( binding ); prop.BindTo( objectType, PropertyAccess.Read ); prop.CheckAccess( from ); ICondition condition = null; switch ( oper ) { #region Equality case "=": case "==": case "is": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Equal, val ); break; case "!=": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.NotEqual, val ); break; #endregion #region Relational case ">": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Greater, val ); break; case "<": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Lesser, val ); break; case ">=": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.GreaterEqual, val ); break; case "<=": condition = new ComparisonCondition( prop, inverse, ComparisonOperator.LesserEqual, val ); break; #endregion #region Strings case "==~": case "~==": case "=~": case "~=": case "is~": case "~is": condition = new StringCondition( prop, inverse, StringOperator.Equal, val, true ); break; case "!=~": case "~!=": condition = new StringCondition( prop, inverse, StringOperator.NotEqual, val, true ); break; case "starts": condition = new StringCondition( prop, inverse, StringOperator.StartsWith, val, false ); break; case "starts~": case "~starts": condition = new StringCondition( prop, inverse, StringOperator.StartsWith, val, true ); break; case "ends": condition = new StringCondition( prop, inverse, StringOperator.EndsWith, val, false ); break; case "ends~": case "~ends": condition = new StringCondition( prop, inverse, StringOperator.EndsWith, val, true ); break; case "contains": condition = new StringCondition( prop, inverse, StringOperator.Contains, val, false ); break; case "contains~": case "~contains": condition = new StringCondition( prop, inverse, StringOperator.Contains, val, true ); break; #endregion } if ( condition == null ) throw new InvalidOperationException( String.Format( "Unrecognized operator (\"{0}\").", oper ) ); current.Add( condition ); } conditions.Add( current.ToArray() ); return new ObjectConditional( objectType, conditions.ToArray() ); }