[xbuild] Expression.ParseAs<T> - new method
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / Expression.cs
index a37942e5553a0e59232878d5ad1bf0a753c961a8..0d7ad2fa5984896fe57d3b622bc8b6ceefddab82 100644 (file)
@@ -33,6 +33,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.Text;
 using System.Text.RegularExpressions;
+using Mono.XBuild.Utilities;
 
 namespace Microsoft.Build.BuildEngine {
 
@@ -65,6 +66,20 @@ namespace Microsoft.Build.BuildEngine {
                        this.expressionCollection = new ExpressionCollection ();
                }
 
+               public static T ParseAs<T> (string expression, ParseOptions options, Project project)
+               {
+                       Expression expr = new Expression ();
+                       expr.Parse (expression, options);
+                       return (T)expr.ConvertTo (project, typeof (T));
+               }
+
+               public static T ParseAs<T> (string expression, ParseOptions options, Project project, ExpressionOptions exprOptions)
+               {
+                       Expression expr = new Expression ();
+                       expr.Parse (expression, options);
+                       return (T)expr.ConvertTo (project, typeof (T), exprOptions);
+               }
+
                // Split: Split on ';'
                //         Eg. Property values don't need to be split
                //
@@ -78,7 +93,6 @@ namespace Microsoft.Build.BuildEngine {
                        bool allowItems = (options & ParseOptions.AllowItems) == ParseOptions.AllowItems;
                        bool allowMd = (options & ParseOptions.AllowMetadata) == ParseOptions.AllowMetadata;
 
-                       expression = expression.Replace ('/', Path.DirectorySeparatorChar);
                        expression = expression.Replace ('\\', Path.DirectorySeparatorChar);
                
                        string [] parts;
@@ -132,7 +146,7 @@ namespace Microsoft.Build.BuildEngine {
                        for (int i = 0; i < lists.Count; i++) {
                                foreach (object o in lists [i]) {
                                        if (o is string)
-                                               expressionCollection.Add (Utilities.Unescape ((string) o));
+                                               expressionCollection.Add (MSBuildUtils.Unescape ((string) o));
                                        else if (!allowItems && o is ItemReference)
                                                expressionCollection.Add (((ItemReference) o).OriginalString);
                                        else if (!allowMd && o is MetadataReference) {