示例#1
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			return Value;
		}
示例#2
0
		public bool EvaluateStringAsBoolean (EvaluationContext context, string ret)
		{
			if (ret != null) {
				if (ret.Equals ("TRUE", StringComparison.InvariantCultureIgnoreCase))
					return true;
				else if (ret.Equals ("FALSE", StringComparison.InvariantCultureIgnoreCase))
					return false;
			}
			throw new InvalidProjectFileException (this.Location, string.Format ("Condition '{0}' is evaluated as '{1}' and cannot be converted to boolean", context.Source, ret));
		}
示例#3
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			return Left.EvaluateAsString (context) + strings [Operator] + Right.EvaluateAsString (context);
		}
示例#4
0
		public override object EvaluateAsObject (EvaluationContext context)
		{
			return EvaluateAsString (context);
		}
示例#5
0
 public abstract string EvaluateAsString(EvaluationContext context);
示例#6
0
		object DoEvaluateAsObject (EvaluationContext context)
		{
			if (Access.Target == null) {
				return context.EvaluateProperty (Access.Name.Name);
			} else {
				if (this.Access.TargetType == PropertyTargetType.Object) {
					var obj = Access.Target.EvaluateAsObject (context);
					if (obj == null)
						return null;
					if (Access.Arguments != null) {
						var args = Access.Arguments.Select (e => e.EvaluateAsObject (context)).ToArray ();
						var method = FindMethod (obj.GetType (), Access.Name.Name, args);
						if (method == null)
							throw new InvalidProjectFileException (Location, string.Format ("access to undefined method '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
						return method.Invoke (obj, AdjustArgsForCall (method, args));
					} else {
						var prop = obj.GetType ().GetProperty (Access.Name.Name);
						if (prop == null)
							throw new InvalidProjectFileException (Location, string.Format ("access to undefined property '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
						return prop.GetValue (obj, null);
					}
				} else {
					var type = Type.GetType (Access.Target.EvaluateAsString (context));
					if (type == null)
						throw new InvalidProjectFileException (Location, string.Format ("specified type '{0}' was not found", Access.Target.EvaluateAsString (context)));
					if (Access.Arguments != null) {
						var args = Access.Arguments.Select (e => e.EvaluateAsObject (context)).ToArray ();
						var method = FindMethod (type, Access.Name.Name, args);
						if (method == null)
							throw new InvalidProjectFileException (Location, string.Format ("access to undefined static method '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
						return method.Invoke (null, AdjustArgsForCall (method, args));
					} else {
						var prop = type.GetProperty (Access.Name.Name);
						if (prop == null)
							throw new InvalidProjectFileException (Location, string.Format ("access to undefined static property '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
						return prop.GetValue (null, null);
					}
				}
			}
		}
示例#7
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			var ret = EvaluateAsString (context);
			return EvaluateStringAsBoolean (context, ret);
		}
示例#8
0
 public override object EvaluateAsObject(EvaluationContext context)
 {
     return(Value);
 }
示例#9
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     // no negation for string
     return("!" + Negated.EvaluateAsString(context));
 }
示例#10
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     return(Value ? "True" : "False");
 }
示例#11
0
 public override bool EvaluateAsBoolean(EvaluationContext context)
 {
     return(Value);
 }
示例#12
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     return(Left.EvaluateAsString(context) + strings [Operator] + Right.EvaluateAsString(context));
 }
示例#13
0
 public abstract object EvaluateAsObject(EvaluationContext context);
示例#14
0
 public abstract bool EvaluateAsBoolean(EvaluationContext context);
示例#15
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			// no negation for string
			return "!" + Negated.EvaluateAsString (context);
		}
示例#16
0
 public override bool EvaluateAsBoolean(EvaluationContext context)
 {
     return(!Negated.EvaluateAsBoolean(context));
 }
示例#17
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			var ret = EvaluateAsObject (context);
			// FIXME: this "wrapper" is kind of hack, to prevent sequential property references such as $(X)$(Y).
			return ret == null ? context.Evaluator.ReplacementForMissingPropertyAndItem : context.Evaluator.Wrapper + ret.ToString () + context.Evaluator.Wrapper;
		}
示例#18
0
 object DoEvaluateAsObject(EvaluationContext context)
 {
     if (Access.Target == null)
     {
         return(context.EvaluateProperty(Access.Name.Name));
     }
     else
     {
         if (this.Access.TargetType == PropertyTargetType.Object)
         {
             var obj = Access.Target.EvaluateAsObject(context);
             if (obj == null)
             {
                 return(null);
             }
             if (Access.Arguments != null)
             {
                 var args   = Access.Arguments.Select(e => e.EvaluateAsObject(context)).ToArray();
                 var method = FindMethod(obj.GetType(), Access.Name.Name, args);
                 if (method == null)
                 {
                     throw new InvalidProjectFileException(Location, string.Format("access to undefined method '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString(context), Location));
                 }
                 return(method.Invoke(obj, AdjustArgsForCall(method, args)));
             }
             else
             {
                 var prop = obj.GetType().GetProperty(Access.Name.Name);
                 if (prop == null)
                 {
                     throw new InvalidProjectFileException(Location, string.Format("access to undefined property '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString(context), Location));
                 }
                 return(prop.GetValue(obj, null));
             }
         }
         else
         {
             var type = Type.GetType(Access.Target.EvaluateAsString(context));
             if (type == null)
             {
                 throw new InvalidProjectFileException(Location, string.Format("specified type '{0}' was not found", Access.Target.EvaluateAsString(context)));
             }
             if (Access.Arguments != null)
             {
                 var args   = Access.Arguments.Select(e => e.EvaluateAsObject(context)).ToArray();
                 var method = FindMethod(type, Access.Name.Name, args);
                 if (method == null)
                 {
                     throw new InvalidProjectFileException(Location, string.Format("access to undefined static method '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString(context), Location));
                 }
                 return(method.Invoke(null, AdjustArgsForCall(method, args)));
             }
             else
             {
                 var prop = type.GetProperty(Access.Name.Name);
                 if (prop == null)
                 {
                     throw new InvalidProjectFileException(Location, string.Format("access to undefined static property '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString(context), Location));
                 }
                 return(prop.GetValue(null, null));
             }
         }
     }
 }
示例#19
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			return EvaluateStringAsBoolean (context, EvaluateAsString (context));
		}
示例#20
0
 public override bool EvaluateAsBoolean(EvaluationContext context)
 {
     return(EvaluateStringAsBoolean(context, EvaluateAsString(context)));
 }
示例#21
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			return Value.Name;
		}
示例#22
0
        public override bool EvaluateAsBoolean(EvaluationContext context)
        {
            var ret = EvaluateAsString(context);

            return(EvaluateStringAsBoolean(context, ret));
        }
示例#23
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			if (string.Equals (Name.Name, "Exists", StringComparison.OrdinalIgnoreCase)) {
				if (Arguments.Count != 1)
					throw new InvalidProjectFileException (Location, "Function 'Exists' expects 1 argument");
				string val = Arguments.First ().EvaluateAsString (context);
				return Directory.Exists (val) || System.IO.File.Exists (val);
			}
			if (string.Equals (Name.Name, "HasTrailingSlash", StringComparison.OrdinalIgnoreCase)) {
				if (Arguments.Count != 1)
					throw new InvalidProjectFileException (Location, "Function 'HasTrailingSlash' expects 1 argument");
				string val = Arguments.First ().EvaluateAsString (context);
				return val.LastOrDefault () == '\\' || val.LastOrDefault () == '/';
			}
			throw new InvalidProjectFileException (Location, string.Format ("Unsupported function '{0}'", Name));
		}
示例#24
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     return(context.Evaluator.Evaluate(this.Value.Name));
 }
示例#25
0
		public abstract object EvaluateAsObject (EvaluationContext context);
示例#26
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     return(Value.Name);
 }
示例#27
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			switch (Operator) {
			case Operator.EQ:
				return string.Equals (Left.EvaluateAsString (context), Right.EvaluateAsString (context), StringComparison.OrdinalIgnoreCase);
			case Operator.NE:
				return !string.Equals (Left.EvaluateAsString (context), Right.EvaluateAsString (context), StringComparison.OrdinalIgnoreCase);
			case Operator.And:
			case Operator.Or:
				// evaluate first, to detect possible syntax error on right expr.
				var lb = Left.EvaluateAsBoolean (context);
				var rb = Right.EvaluateAsBoolean (context);
				return Operator == Operator.And ? (lb && rb) : (lb || rb);
			}
			// comparison expressions - evaluate comparable first, then compare values.
			var left = Left.EvaluateAsObject (context);
			var right = Right.EvaluateAsObject (context);
			if (!(left is IComparable && right is IComparable))
				throw new InvalidProjectFileException ("expression cannot be evaluated as boolean");
			var result = ((IComparable) left).CompareTo (right);
			switch (Operator) {
			case Operator.GE:
				return result >= 0;
			case Operator.GT:
				return result > 0;
			case Operator.LE:
				return result <= 0;
			case Operator.LT:
				return result < 0;
			}
			throw new InvalidOperationException ();
		}
示例#28
0
 public override bool EvaluateAsBoolean(EvaluationContext context)
 {
     throw new InvalidProjectFileException("raw string literal cannot be evaluated as boolean");
 }
示例#29
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			return Value ? "True" : "False";
		}
示例#30
0
 public override object EvaluateAsObject(EvaluationContext context)
 {
     return(EvaluateAsString(context));
 }
示例#31
0
		public override object EvaluateAsObject (EvaluationContext context)
		{
			return Value;
		}
示例#32
0
 public override string EvaluateAsString(EvaluationContext context)
 {
     throw new NotImplementedException();
 }
示例#33
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			return !Negated.EvaluateAsBoolean (context);
		}
示例#34
0
 public override object EvaluateAsObject(EvaluationContext context)
 {
     throw new NotImplementedException();
 }
示例#35
0
		public override object EvaluateAsObject (EvaluationContext context)
		{
			try {
				return DoEvaluateAsObject (context);
			} catch (TargetInvocationException ex) {
				throw new InvalidProjectFileException ("Access to property caused an error", ex);
			}
		}
		public override string EvaluateAsString (EvaluationContext context)
		{
			return QuoteChar + EvaluateAsStringWithoutQuote (context) + QuoteChar;
		}
示例#37
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			string itemType = Application.Name.Name;
			var items = context.GetItems (itemType);
			if (!items.Any ())
				return context.Evaluator.ReplacementForMissingPropertyAndItem;
			if (Application.Expressions == null)
				return string.Join (";", items.Select (item => context.EvaluateItem (itemType, item)));
			else
				return string.Join (";", items.Select (item => {
					context.ContextItem = item;
					var ret = string.Concat (Application.Expressions.Select (e => e.EvaluateAsString (context)));
					context.ContextItem = null;
					return ret;
					}));
		}
		public string EvaluateAsStringWithoutQuote (EvaluationContext context)
		{
			return string.Concat (Contents.Select (e => e.EvaluateAsString (context)));
		}
示例#39
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			string itemType = this.Access.ItemType != null ? this.Access.ItemType.Name : null;
			string metadataName = Access.Metadata.Name;
			IEnumerable<object> items;
			if (this.Access.ItemType != null)
				items = context.GetItems (itemType);
			else if (context.ContextItem != null)
				items = new Object [] { context.ContextItem };
			else
				items = context.GetAllItems ();
			
			var values = items.Select (i => (i is ProjectItem) ? ((ProjectItem) i).GetMetadataValue (metadataName) : ((ProjectItemInstance) i).GetMetadataValue (metadataName)).Where (s => !string.IsNullOrEmpty (s));
			return string.Join (";", values);
		}
		public override string EvaluateAsString (EvaluationContext context)
		{
			var ret = EvaluateAsObject (context);
			return ret == null ? null : ret.ToString ();
		}
示例#41
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			return context.Evaluator.Evaluate (this.Value.Name);
		}
		public override string EvaluateAsString (EvaluationContext context)
		{
			string itemType = Application.Name.Name;
			var items = context.GetItems (itemType);
			if (!items.Any ())
				return null;
			if (Application.Expressions == null)
				return string.Join (";", items.Select (item => Unwrap (context.EvaluateItem (itemType, item))));
			else
				return string.Join (";", items.Select (item => {
					context.ContextItem = item;
					var ret = Unwrap (string.Concat (Application.Expressions.Select (e => e.EvaluateAsString (context))));
					context.ContextItem = null;
					return ret;
				}));
		}
示例#43
0
		public override bool EvaluateAsBoolean (EvaluationContext context)
		{
			throw new InvalidProjectFileException ("raw string literal cannot be evaluated as boolean");
		}
示例#44
0
		public abstract string EvaluateAsString (EvaluationContext context);
示例#45
0
		public override string EvaluateAsString (EvaluationContext context)
		{
			throw new NotImplementedException ();
		}
示例#46
0
		public abstract bool EvaluateAsBoolean (EvaluationContext context);
示例#47
0
		public override object EvaluateAsObject (EvaluationContext context)
		{
			throw new NotImplementedException ();
		}
        public override string EvaluateAsString(EvaluationContext context)
        {
            var ret = EvaluateAsObject(context);

            return(ret == null ? null : ret.ToString());
        }