當前位置: 首頁>>代碼示例>>C#>>正文


C# Expressions.EvaluationContext類代碼示例

本文整理匯總了C#中Microsoft.Build.Internal.Expressions.EvaluationContext的典型用法代碼示例。如果您正苦於以下問題:C# EvaluationContext類的具體用法?C# EvaluationContext怎麽用?C# EvaluationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EvaluationContext類屬於Microsoft.Build.Internal.Expressions命名空間,在下文中一共展示了EvaluationContext類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EvaluateAsBoolean

		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));
		}
開發者ID:GirlD,項目名稱:mono,代碼行數:16,代碼來源:ExpressionEvaluator.cs

示例2: EvaluateAsStringWithoutQuote

		public string EvaluateAsStringWithoutQuote (EvaluationContext context)
		{
			return string.Concat (Contents.Select (e => e.EvaluateAsString (context)));
		}
開發者ID:KonajuGames,項目名稱:SharpLang,代碼行數:4,代碼來源:ExpressionEvaluator.cs

示例3: EvaluateAsString

		public override string EvaluateAsString (EvaluationContext context)
		{
			return Value.Name;
		}
開發者ID:GirlD,項目名稱:mono,代碼行數:4,代碼來源:ExpressionEvaluator.cs

示例4: EvaluateAsObject

		public override object EvaluateAsObject (EvaluationContext context)
		{
			return EvaluateAsString (context);
		}
開發者ID:GirlD,項目名稱:mono,代碼行數:4,代碼來源:ExpressionEvaluator.cs

示例5: EvaluateStringAsBoolean

		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));
		}
開發者ID:GirlD,項目名稱:mono,代碼行數:10,代碼來源:ExpressionEvaluator.cs

示例6: DoEvaluateAsObject

		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);
					}
				}
			}
		}
開發者ID:GirlD,項目名稱:mono,代碼行數:40,代碼來源:ExpressionEvaluator.cs

示例7: EvaluateAsString

		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;
				}));
		}
開發者ID:ming871,項目名稱:NoahGameFrame,代碼行數:16,代碼來源:ExpressionEvaluator.cs

示例8: EvaluateAsString

		public override string EvaluateAsString (EvaluationContext context)
		{
			return QuoteChar + EvaluateAsStringWithoutQuote (context) + QuoteChar;
		}
開發者ID:KonajuGames,項目名稱:SharpLang,代碼行數:4,代碼來源:ExpressionEvaluator.cs


注:本文中的Microsoft.Build.Internal.Expressions.EvaluationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。