[asp.net] Ignore JavaScript blocks enclosed in HTML comments
[mono.git] / mcs / class / System.Web / System.Web.Compilation / ConnectionStringsExpressionBuilder.cs
index 8afda494f6e89e27939a275c7a574baf60b80cd5..20169411de189580e3aad9ad0a12584e4a326627 100644 (file)
@@ -28,7 +28,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using System;
 using System.CodeDom;
@@ -38,25 +37,32 @@ using System.Web.UI;
 
 namespace System.Web.Compilation {
 
-       [ExpressionEditor("System.Web.UI.Design.ConnectionStringsExpressionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+       [ExpressionEditor("System.Web.UI.Design.ConnectionStringsExpressionEditor, " + Consts.AssemblySystem_Design)]
        [ExpressionPrefix("ConnectionStrings")]
        public class ConnectionStringsExpressionBuilder : ExpressionBuilder {
 
-               public override object EvaluateExpression (object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
+               public override object EvaluateExpression (object target, BoundPropertyEntry entry,
+                                                          object parsedData, ExpressionBuilderContext context)
                {
                        return GetConnectionString (entry.Expression.Trim());
                }
 
-               public override CodeExpression GetCodeExpression (BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
-               {
-                       throw new NotImplementedException ();
+               public override CodeExpression GetCodeExpression (BoundPropertyEntry entry, object parsedData,
+                                                                 ExpressionBuilderContext context)
+               {                       
+                       Pair connString = parsedData as Pair;
+                       return new CodeMethodInvokeExpression (
+                               new CodeTypeReferenceExpression (typeof (ConnectionStringsExpressionBuilder)),
+                               (bool)connString.Second ? "GetConnectionStringProviderName" : "GetConnectionString",
+                               new CodeExpression [] {new CodePrimitiveExpression (connString.First)}
+                       );
                }
 
                public static string GetConnectionString (string connectionStringName)
                {
                        ConnectionStringSettings conn = WebConfigurationManager.ConnectionStrings [connectionStringName];
                        if (conn == null)
-                               return "";
+                               return String.Empty;
                        else
                                return conn.ConnectionString;
                }
@@ -65,15 +71,29 @@ namespace System.Web.Compilation {
                {
                        ConnectionStringSettings conn = WebConfigurationManager.ConnectionStrings [connectionStringName];
                        if (conn == null)
-                               return "";
+                               return String.Empty;
                        else
                                return conn.ProviderName;
                }
 
-               [MonoTODO]
                public override object ParseExpression (string expression, Type propertyType, ExpressionBuilderContext context)
                {
-                       throw new NotImplementedException ();
+                       bool wantsProviderName = false;
+                       string connStringName = String.Empty;
+
+                       if (!String.IsNullOrEmpty (expression)) {
+                               int subidx = expression.Length;
+                               
+                               if (expression.EndsWith (".providername", StringComparison.InvariantCultureIgnoreCase)) {
+                                       wantsProviderName = true;
+                                       subidx -= 13;
+                               } else if (expression.EndsWith (".connectionstring", StringComparison.InvariantCultureIgnoreCase))
+                                       subidx -= 17;
+
+                               connStringName = expression.Substring (0, subidx);
+                       }
+                       
+                       return new Pair (connStringName, wantsProviderName);
                }
 
                public override bool SupportsEvaluate {
@@ -83,6 +103,6 @@ namespace System.Web.Compilation {
 
 }
 
-#endif
+