Procházet zdrojové kódy

2010-01-20 Marek Habersack <[email protected]>

	* ObjectStateFormatter.cs: implemented support for IndexedString
	on top of the existing StringFormatter.

	* IndexedString.cs: implemented

svn path=/trunk/mcs/; revision=149919
Marek Habersack před 16 roky
rodič
revize
4083fbfc3f

+ 7 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,10 @@
+2010-01-20  Marek Habersack  <[email protected]>
+
+	* ObjectStateFormatter.cs: implemented support for IndexedString
+	on top of the existing StringFormatter.
+
+	* IndexedString.cs: implemented
+
 2009-12-22  Marek Habersack  <[email protected]>
 
 	* Page.cs: form javascript declaration block is rendered only if

+ 10 - 2
mcs/class/System.Web/System.Web.UI/IndexedString.cs

@@ -29,6 +29,8 @@
 //
 
 #if NET_2_0
+using System;
+
 namespace System.Web.UI
 {
 	[SerializableAttribute]
@@ -36,10 +38,16 @@ namespace System.Web.UI
 	{
 		public IndexedString (string s)
 		{
-			throw new NotImplementedException ();
+			if (String.IsNullOrEmpty (s))
+				throw new ArgumentNullException ("s");
+			
+			Value = s;
 		}
 		
-		public string Value { get { throw new NotImplementedException (); } }
+		public string Value {
+			get;
+			private set;
+		}
 	}
 }
 #endif

+ 34 - 4
mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs

@@ -6,7 +6,7 @@
 //	Gonzalo Paniagua ([email protected])
 //
 // (C) 2003 Ben Maurer
-// (c) Copyright 2004-2008 Novell, Inc. (http://www.novell.com)
+// (c) Copyright 2004-2010 Novell, Inc. (http://www.novell.com)
 //
 
 //
@@ -254,7 +254,7 @@ namespace System.Web.UI {
 
 #region Object Readers/Writers
 		
-		class WriterContext
+		sealed class WriterContext
 		{
 			Hashtable cache;
 			short nextKey = 0;
@@ -286,7 +286,7 @@ namespace System.Web.UI {
 			}
 		}
 		
-		class ReaderContext
+		sealed class ReaderContext
 		{
 			ArrayList cache;
 			
@@ -331,7 +331,7 @@ namespace System.Web.UI {
 				new ObjectArrayFormatter ().Register ();
 				new UnitFormatter ().Register ();
 				new FontUnitFormatter ().Register ();
-				
+				new IndexedStringFormatter ().Register ();
 				new ColorFormatter ().Register ();
 
 				enumFormatter = new EnumFormatter ();
@@ -532,6 +532,36 @@ namespace System.Web.UI {
 				get { return 2; }
 			}
 		}
+
+		class IndexedStringFormatter : StringFormatter
+		{
+			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
+			{
+				IndexedString s = o as IndexedString;
+
+				if (s == null)
+					throw new InvalidOperationException ("object is not of the IndexedString type");
+				
+				base.Write (w, s.Value, ctx);
+			}
+			
+			protected override object Read (byte token, BinaryReader r, ReaderContext ctx)
+			{
+				string s = base.Read (token, r, ctx) as string;
+				if (String.IsNullOrEmpty (s))
+					throw new InvalidOperationException ("string must not be null or empty.");
+				
+				return new IndexedString (s);
+			}
+			
+			protected override Type Type {
+				get { return typeof (IndexedString); }
+			}
+			
+			protected override int NumberOfIds {
+				get { return 2; }
+			}
+		}
 		
 		class Int64Formatter : ObjectFormatter
 		{