Przeglądaj źródła

Check IsWritablePropertyOrField before generating code for assignment statement and DataBind event.

svn path=/trunk/mcs/; revision=61826
Andrew Skiba 19 lat temu
rodzic
commit
1d80fed29a

+ 6 - 0
mcs/class/System.Web/ChangeLog

@@ -1,3 +1,9 @@
+2006-06-18 Andrew Skiba <[email protected]>
+
+	* System.Web_test.dll.sources: add TemplateControlCompilerTest.cs
+	* Makefile: add ReadOnlyPropertyBind.aspx and
+	ReadOnlyPropertyControl.ascx
+
 2006-06-14 Andrew Skiba <[email protected]>
 
 	* Makefile: add menuclass.aspx test resource file

+ 2 - 0
mcs/class/System.Web/Makefile

@@ -74,6 +74,8 @@ TEST_RESOURCE_FILES = \
 	Test/mainsoft/NunitWebResources/PageWithStyleSheet.aspx \
 	Test/mainsoft/NunitWebResources/PageWithTheme.aspx \
 	Test/mainsoft/NunitWebResources/RunTimeSetTheme.aspx \
+	Test/mainsoft/NunitWebResources/ReadOnlyPropertyBind.aspx \
+	Test/mainsoft/NunitWebResources/ReadOnlyPropertyControl.ascx \
 	Test/mainsoft/NunitWebResources/Theme1.skin \
 	Test/mainsoft/NunitWebResources/Web.sitemap \
 	Test/mainsoft/MainsoftWebTest/nunitweb_config.xml 

+ 5 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,8 @@
+2006-06-18 Andrew Skiba <[email protected]>
+
+	* TemplateControlCompiler.cs: check IsWritablePropertyOrField before
+	generating code for assignment statement and DataBind event.
+	
 2006-06-15 Juraj Skripsky <[email protected]>
 
 	* AspTokenizer.cs (ReadAttValue), AspParser.cs (GetAttributes):

+ 14 - 4
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -399,7 +399,7 @@ namespace System.Web.Compilation
 		void AddCodeForPropertyOrField (ControlBuilder builder, Type type, string var_name, string att, MemberInfo member, bool isDataBound)
 		{
 			CodeMemberMethod method = builder.method;
-			if (isDataBound) {
+			if (isDataBound && IsWritablePropertyOrField (member)) {
 				string dbMethodName = DataBoundProperty (builder, type, var_name, att);
 				AddEventAssign (method, "DataBinding", typeof (EventHandler), dbMethodName);
 				return;
@@ -476,6 +476,17 @@ namespace System.Web.Compilation
 			return member;
 		}
 
+		static bool IsWritablePropertyOrField (MemberInfo member)
+		{
+			PropertyInfo pi = member as PropertyInfo;
+			if (pi != null)
+				return pi.CanWrite;
+			FieldInfo fi = member as FieldInfo;
+			if (fi != null)
+				return !fi.IsInitOnly;
+			throw new ArgumentException ("Argument must be of PropertyInfo or FieldInfo type", "member");
+		}
+
 		bool ProcessPropertiesAndFields (ControlBuilder builder, MemberInfo member, string id,
 						string attValue, string prefix)
 		{
@@ -486,8 +497,6 @@ namespace System.Web.Compilation
 			Type type;
 			if (isPropertyInfo) {
 				type = ((PropertyInfo) member).PropertyType;
-				if (hyphen == -1 && ((PropertyInfo) member).CanWrite == false)
-					return false;
 			} else {
 				type = ((FieldInfo) member).FieldType;
 			}
@@ -496,7 +505,8 @@ namespace System.Web.Compilation
 #if NET_2_0
 				if (isDataBound) RegisterBindingInfo (builder, member.Name, ref attValue);
 #endif
-				AddCodeForPropertyOrField (builder, type, member.Name, attValue, member, isDataBound);
+				if (IsWritablePropertyOrField (member))
+					AddCodeForPropertyOrField (builder, type, member.Name, attValue, member, isDataBound);
 				return true;
 			}
 			

+ 1 - 0
mcs/class/System.Web/System.Web_test.dll.sources

@@ -31,6 +31,7 @@ System.Web/SiteMapProviderTest.cs
 System.Web/SiteMapNodeTest.cs
 System.Web/StaticSiteMapProviderTest.cs
 System.Web.Compilation/ClientBuildManagerParameterTest.cs
+System.Web.Compilation/TemplateControlCompilerTest.cs
 System.Web.Configuration/AnonymousIdentificationSectionTest.cs
 System.Web.Configuration/AssemblyCollectionTest.cs
 System.Web.Configuration/AssemblyInfoTest.cs

+ 4 - 0
mcs/class/System.Web/Test/System.Web.Compilation/ChangeLog

@@ -1,3 +1,7 @@
+2006-06-18  Andrew Skiba  <[email protected]>
+
+	* TemplateControlCompilerTest.cs: new test.
+
 2006-01-20  Chris Toshok  <[email protected]>
 
 	* ClientBuildManagerParameterTest.cs: new test.

+ 43 - 0
mcs/class/System.Web/Test/System.Web.Compilation/TemplateControlCompilerTest.cs

@@ -0,0 +1,43 @@
+#if NET_2_0
+
+using NunitWeb;
+using NUnit.Framework;
+using System.Web.UI.WebControls;
+using System.Reflection;
+using System.ComponentModel;
+using System.Threading;
+
+namespace MonoTests.System.Web.Compilation {
+	public class ReadOnlyPropertyControl:TextBox {
+		[Bindable (true)]
+		public bool MyProp
+		{
+			get { return true; }
+		}
+
+	}
+	
+	[TestFixture]
+	public class TemplateControlCompilerTest
+	{
+        	[Test]
+		[NUnit.Framework.Category ("NunitWeb")]
+		public void ReadOnlyPropertyBindTest ()
+		{
+			Helper.Instance.CopyResource (Assembly.GetExecutingAssembly (),
+				"ReadOnlyPropertyBind.aspx", "ReadOnlyPropertyBind.aspx");
+			Helper.Instance.CopyResource (Assembly.GetExecutingAssembly (),
+				"ReadOnlyPropertyControl.ascx", "ReadOnlyPropertyControl.ascx");
+			Helper.Instance.RunUrl ("ReadOnlyPropertyBind.aspx");
+		}
+		[TestFixtureTearDown]
+		public void TearDown ()
+		{
+			Thread.Sleep (100);
+			Helper.Unload ();
+		}
+	}
+}
+
+#endif
+

+ 21 - 0
mcs/class/System.Web/Test/mainsoft/NunitWebResources/ReadOnlyPropertyBind.aspx

@@ -0,0 +1,21 @@
+<%@ Page Language="C#" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<%@ Register TagPrefix="uc1" TagName="ReadOnlyPropertyControl" Src="ReadOnlyPropertyControl.ascx" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+    <head>
+        <title>UrlProperty test</title>
+    </head>
+<body>
+    <form id="form1" runat="server">
+    <asp:FormView runat="server" ID="fv1" DataSourceID="DataSource1" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" >
+    <ItemTemplate>
+    <uc1:ReadOnlyPropertyControl runat="server" ID="wuc1" ReadOnlyProperty='<%# Bind("Chars") %>' />
+    <uc1:ReadOnlyPropertyControl runat="server" ID="wuc2" ReadOnlyField='<%# Bind("Chars") %>' />
+    </ItemTemplate>
+    </asp:FormView>
+    <asp:ObjectDataSource ID="DataSource1" runat="server" TypeName="System.Guid" SelectMethod="ToByteArray" />
+    </form>
+</body>
+</html>

+ 10 - 0
mcs/class/System.Web/Test/mainsoft/NunitWebResources/ReadOnlyPropertyControl.ascx

@@ -0,0 +1,10 @@
+<%@ Control Language="C#" %>
+<script runat="server">
+    [System.ComponentModel.Bindable (true)]
+    public readonly bool ReadOnlyField = true;
+    [System.ComponentModel.Bindable (true)]
+    public bool ReadOnlyProperty
+    {
+        get { return true; }
+    }
+</script>