merge 99422:99508
authorJb Evain <jbevain@gmail.com>
Tue, 1 Apr 2008 12:56:44 +0000 (12:56 -0000)
committerJb Evain <jbevain@gmail.com>
Tue, 1 Apr 2008 12:56:44 +0000 (12:56 -0000)
svn path=/branches/jb/ml2/mcs/; revision=99510

44 files changed:
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolBar.cs
mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataView.cs
mcs/class/System.Web/System.Web.Hosting/ChangeLog
mcs/class/System.Web/System.Web.Hosting/HostingEnvironment.cs
mcs/class/System.Web/System.Web.Hosting/VirtualPathProvider.cs
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpResponse.cs
mcs/class/System.Web/System.Web/StaticFileHandler.cs
mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/Test/System.Xml.Serialization/XmlCodeExporterTests.cs
mcs/class/System.XML/Test/System.Xml/ChangeLog
mcs/class/System.XML/Test/System.Xml/XmlAttributeCollectionTests.cs
mcs/class/System.XML/Test/System.Xml/XmlAttributeTests.cs
mcs/class/System.XML/Test/System.Xml/XmlDocumentEventTests.cs
mcs/class/System.XML/Test/System.Xml/XmlDocumentTests.cs
mcs/class/System.XML/Test/System.Xml/XmlDocumentTypeTests.cs
mcs/class/System.XML/Test/System.Xml/XmlEntityReferenceTests.cs
mcs/class/System.XML/Test/System.Xml/XmlNodeTests.cs
mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs
mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MonoMethod.cs
mcs/class/corlib/System.Threading/ChangeLog
mcs/class/corlib/System.Threading/Thread.cs
mcs/class/corlib/System/Byte.cs
mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Decimal.cs
mcs/class/corlib/System/Double.cs
mcs/class/corlib/System/Int16.cs
mcs/class/corlib/System/Int32.cs
mcs/class/corlib/System/Int64.cs
mcs/class/corlib/System/MonoType.cs
mcs/class/corlib/System/NumberFormatter.cs
mcs/class/corlib/System/NumberFormatter.jvm.cs
mcs/class/corlib/System/SByte.cs
mcs/class/corlib/System/Single.cs
mcs/class/corlib/System/TimeSpan.cs
mcs/class/corlib/System/UInt16.cs
mcs/class/corlib/System/UInt32.cs
mcs/class/corlib/System/UInt64.cs
mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/NumberFormatterTest.cs
mcs/mcs/gmcs.sln

index 00cef50367d7289e3738fff39e11bb5f7cff9bf3..63d012db1ed321320a7b99b921a1a98ce1801bc9 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-31  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolBar.cs: Don't do our painting if UserPaint is set.  If UserPaint
+       isn't set, don't call OnPaint.  [Fixes bug #375300]
+
 2008-03-30  Carlos Alberto Cortez <calberto.cortez@gmail.com>
 
        * BindingSource.cs: IsBindingSuspended, ResumeBinding and
index 6bcf21192d9eca4f726d6777d8060e7c5a020812..4efbbc7603bc5e227b237c28661c5e56e1799a92 100644 (file)
@@ -912,7 +912,13 @@ namespace System.Windows.Forms
 
                internal override void OnPaintInternal (PaintEventArgs pevent)
                {
+                       if (GetStyle (ControlStyles.UserPaint))
+                               return;
+                               
                        ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
+                       
+                       // Toolbars do not raise OnPaint unless UserPaint is set
+                       pevent.Handled = true;
                }
 
                internal void Redraw (bool recalculate)
index dfce8df8a377393624d095511a934981ba874aa0..03e5622bca14bc1028b29e25e3805b376d202fc6 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-31  Veerapuram Varadhan <vvaradhan@novell.com>
+
+       * DataView.cs: Reverting rev#98474 changes - as it broke quite a
+       few test profiles.
+       
 2008-03-23  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * DataSet.cs: Corcompare fix.
index d9b0c2a71080febc1c9ed5fecb545dee7ea9587f..62ccb09bd80f4c3aec271d9dc9e776c4e760e4e8 100644 (file)
@@ -735,8 +735,7 @@ namespace System.Data
                        /* ItemDeleted */\r
                        int newIndex;\r
                        newIndex = IndexOf (args.Row);\r
-                       if (Index != null)\r
-                               Index.Delete (args.Row);\r
+                       UpdateIndex (true);\r
                        OnListChanged (new ListChangedEventArgs (ListChangedType.ItemDeleted, newIndex, -1));\r
                }\r
                \r
index 416cf05774c82860a3c1de8c323eaf3d85c2084b..4183707444a5a626e63e60ec0d69a92860f92998 100644 (file)
@@ -1,3 +1,15 @@
+2008-04-01  Marek Habersack  <mhabersack@novell.com>
+
+       * HostingEnvironment.cs: initialize custom VPP on
+       registration.
+       Added an internal boolena property to signal if we're using a
+       custom VPP or not (HaveCustomVPP)
+
+2008-03-31  Marek Habersack  <mhabersack@novell.com>
+
+       * VirtualPathProvider.cs: internal SetPrevious method renamed to
+       InitializeAndSetPrevious.
+
 2008-03-27  Marek Habersack  <mhabersack@novell.com>
 
        * DefaultVirtualPathProvider.cs: support relative virtual paths in
index 150ecb7772ce1df65ab8c6bcaac8915f2e3b430a..727b9c450864ff41d735774d6f51b4ccf42ff793 100644 (file)
@@ -53,6 +53,11 @@ namespace System.Web.Hosting {
                                                                new DefaultVirtualPathProvider ();
                static int busy_count;
 
+               internal static bool HaveCustomVPP {
+                       get;
+                       private set;
+               }
+               
                public HostingEnvironment ()
                {
                        // The documentation says that this is called once per domain by the ApplicationManager and
@@ -161,8 +166,13 @@ namespace System.Web.Hosting {
                        if (virtualPathProvider == null)
                                throw new ArgumentNullException ("virtualPathProvider");
 
-                       virtualPathProvider.SetPrevious (vpath_provider);
+                       VirtualPathProvider previous = vpath_provider;
                        vpath_provider = virtualPathProvider;
+                       vpath_provider.InitializeAndSetPrevious (previous);
+                       if (!(virtualPathProvider is DefaultVirtualPathProvider))
+                               HaveCustomVPP = true;
+                       else
+                               HaveCustomVPP = false;
                }
                
                public static IDisposable SetCultures (string virtualPath)
index 8e06450f3d45997df656e97f09b1fe16cafab7e0..9e829ca08df0edfbf3d0d1f139e112bafb7afdfb 100644 (file)
@@ -43,11 +43,6 @@ namespace System.Web.Hosting {
                {
                }
 
-               internal void SetPrevious (VirtualPathProvider prev)
-               {
-                       this.prev = prev;
-               }
-
                protected internal VirtualPathProvider Previous {
                        get { return prev; }
                }
@@ -56,6 +51,21 @@ namespace System.Web.Hosting {
                {
                }
 
+               internal void InitializeAndSetPrevious (VirtualPathProvider prev)
+               {
+                       Console.WriteLine ("{0}.InitializeAndSetPrevious ({1})", this, prev);
+                       this.prev = prev;
+                       Console.WriteLine ("\tprevious chain:");
+
+                       VirtualPathProvider p = this.prev;
+                       while (p != null) {
+                               Console.WriteLine ("\t\t{0}", p);
+                               p = p.Previous;
+                       }
+                       
+                       Initialize ();
+               }
+               
                public virtual string CombineVirtualPaths (string basePath, string relativePath)
                {
                        return VirtualPathUtility.Combine (basePath, relativePath);
index 5d96045849671a7485e226959888d80690cf9006..ec965b0a1650c0001d45b222f2889193ccb41dda 100644 (file)
@@ -1,3 +1,12 @@
+2008-03-31  Marek Habersack  <mhabersack@novell.com>
+
+       * StaticFileHandler.cs: added code to use custom
+       VirtualPathProvider, if present, to serve files from virtual
+       storage.
+
+       * HttpResponse.cs: added two internal TransmitFile overloads which
+       take a VirtualFile as a parameter.
+
 2008-03-27  Marek Habersack  <mhabersack@novell.com>
 
        * HttpRequest.cs: make UrlComponents internal.
index fc3c39807257c37293eccc9ed84786cac52fbda1..8720b459d7f775b1d9a94bb66c950a82806efa53 100644 (file)
@@ -39,6 +39,7 @@ using System.Web.Util;
 using System.Web.Configuration;
 using System.Globalization;
 using System.Security.Permissions;
+using System.Web.Hosting;
 
 namespace System.Web {
        
@@ -959,8 +960,29 @@ namespace System.Web {
                        output_stream.ApplyFilter (final_flush);
                        Flush (final_flush);
                }
-               
 
+#if NET_2_0
+               internal void TransmitFile (VirtualFile vf)
+               {
+                       TransmitFile (vf, false);
+               }
+               
+               internal void TransmitFile (VirtualFile vf, bool final_flush)
+               {
+                       if (vf == null)
+                               throw new ArgumentNullException ("vf");
+
+                       using (Stream s = vf.Open ()) {
+                               long len = s.Length;
+                               byte[] buf = new byte [len];
+                               int readBytes = s.Read (buf, 0, (int) len);
+                               output_stream.Write (buf, 0, readBytes);
+                               output_stream.ApplyFilter (final_flush);
+                               Flush (final_flush);
+                       }
+               }
+#endif
+               
 #region Session state support
                internal void SetAppPathModifier (string app_modifier)
                {
index 48827d096024b1b0337773e35d0c7d95433e9e70..2ed20085e1aa2fff055b2e66aa30ec42e04542c6 100644 (file)
@@ -32,6 +32,7 @@ using System;
 using System.Globalization;
 using System.IO;
 using System.Web.Util;
+using System.Web.Hosting;
 
 namespace System.Web
 {
@@ -60,6 +61,25 @@ namespace System.Web
                {
                        HttpRequest request = context.Request;
                        HttpResponse response = context.Response;
+
+#if NET_2_0
+                       if (HostingEnvironment.HaveCustomVPP) {
+                               VirtualFile vf = null;
+                               VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
+                               string vpath = request.FilePath;
+                               
+                               if (vpp.FileExists (vpath))
+                                       vf = vpp.GetFile (vpath);
+
+                               if (vf == null)
+                                       throw new HttpException (404, "Path '" + vpath + "' was not found.", vpath);
+
+                               response.ContentType = MimeTypes.GetMimeType (vpath);
+                               response.TransmitFile (vf);
+                               return;
+                       }
+#endif
+                       
                        string fileName = request.PhysicalPath;
                        FileInfo fi = new FileInfo (fileName);
                        if (!fi.Exists || !ValidFileName (fileName))
@@ -69,7 +89,7 @@ namespace System.Web
                                response.Redirect (request.Path + '/');
                                return;
                        }
-
+                       
                        string strHeader = request.Headers ["If-Modified-Since"];
                        try {
                                if (strHeader != null) {
@@ -103,7 +123,6 @@ namespace System.Web
                        try {
                                DateTime lastWT = fi.LastWriteTime.ToUniversalTime ();
                                response.AddHeader ("Last-Modified", lastWT.ToString ("r"));
-
                                response.ContentType = MimeTypes.GetMimeType (fileName);
                                response.TransmitFile (fileName, true);
                        } catch (Exception) {
index d579410653687446fb8cf56f592617c677739e8a..e9d89461ea89b61c795c119b355f275c03cb4e70 100644 (file)
@@ -1,3 +1,7 @@
+2008-03-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * XmlCodeExporterTests.cs: Remove CWL.
+
 2008-03-30  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * XmlSerializationReaderTests.cs: Marked HandleOutAttributeParameters
index b12b205ea52e61550e908a7d2f45d35a6cfea711..25a1ecf74bfdaacb1c357445bc5529916a7ca99a 100644 (file)
@@ -679,7 +679,7 @@ namespace MonoTests.System.XmlSerialization
                        CodeDomProvider provider = new CSharpCodeProvider ();
                        ICodeGenerator generator = provider.CreateGenerator ();
                        generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
-                       Console.WriteLine (sw.ToString ());
+
                        Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
                                "{0}{0}" +
                                "/// <remarks/>{0}" +
index b0495a440e233252b200db71bc6820b731809cfb..42dae40ee8f4b95e94753347bfe2532421612251 100644 (file)
@@ -1,3 +1,19 @@
+2008-03-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * XmlDocumentTests.cs: Fixed line endings.
+       * XmlAttributeCollectionTests.cs: Fixed line endings.
+       * XmlDocumentEventTests.cs: Fixed line endings.
+       * XmlNodeTests.cs: Fixed line endings.
+       * XsdValidatingReaderTests.cs: Fixed line endings.
+       * XmlDocumentTypeTests.cs: Fixed line endings.
+       * XmlEntityReferenceTests.cs: Fixed line endings.
+
+2008-03-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * XmlAttributeTests.cs: Use Assert instead of deprecated Assertion
+       class. Improved a few tests. Added link to MS bug report for regression
+       in .NET 2.0. Numbered tests.
+
 2008-02-19  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlParserContextTests.cs : they are working. case #3 should not
index 592349f0824d7df858f10ee0656037300882730b..c0789e006ad0d42311ed4fdbfc979f662ae81e94 100644 (file)
@@ -148,29 +148,29 @@ namespace MonoTests.System.Xml
                [Test]
                public void InsertAfterReplacesInCorrectOrder ()
                {
-                       XmlDocument testDoc = new XmlDocument ();\r
-                       XmlElement testElement = testDoc.CreateElement ("TestElement" );\r
-                       testDoc.AppendChild (testElement);\r
-\r
-                       XmlAttribute testAttr1 = testDoc.CreateAttribute ("TestAttribute1");\r
-                       testAttr1.Value = "First attribute";\r
-                       testElement.Attributes.Prepend (testAttr1);\r
-\r
-                       XmlAttribute testAttr2 = testDoc.CreateAttribute ("TestAttribute2");\r
-                       testAttr2.Value = "Second attribute";\r
-                       testElement.Attributes.InsertAfter (testAttr2, testAttr1);\r
-\r
-                       XmlAttribute testAttr3 = testDoc.CreateAttribute ("TestAttribute3");\r
-                       testAttr3.Value = "Third attribute";\r
-                       testElement.Attributes.InsertAfter (testAttr3, testAttr2);\r
-\r
-                       XmlAttribute outOfOrder = testDoc.CreateAttribute ("TestAttribute2");\r
-                       outOfOrder.Value = "Should still be second attribute";\r
-                       testElement.Attributes.InsertAfter (outOfOrder, testElement.Attributes [0]);\r
-\r
-                       AssertEquals ("First attribute", testElement.Attributes [0].Value);\r
-                       AssertEquals ("Should still be second attribute", testElement.Attributes [1].Value);\r
-                       AssertEquals ("Third attribute", testElement.Attributes [2].Value);\r
+                       XmlDocument testDoc = new XmlDocument ();
+                       XmlElement testElement = testDoc.CreateElement ("TestElement" );
+                       testDoc.AppendChild (testElement);
+
+                       XmlAttribute testAttr1 = testDoc.CreateAttribute ("TestAttribute1");
+                       testAttr1.Value = "First attribute";
+                       testElement.Attributes.Prepend (testAttr1);
+
+                       XmlAttribute testAttr2 = testDoc.CreateAttribute ("TestAttribute2");
+                       testAttr2.Value = "Second attribute";
+                       testElement.Attributes.InsertAfter (testAttr2, testAttr1);
+
+                       XmlAttribute testAttr3 = testDoc.CreateAttribute ("TestAttribute3");
+                       testAttr3.Value = "Third attribute";
+                       testElement.Attributes.InsertAfter (testAttr3, testAttr2);
+
+                       XmlAttribute outOfOrder = testDoc.CreateAttribute ("TestAttribute2");
+                       outOfOrder.Value = "Should still be second attribute";
+                       testElement.Attributes.InsertAfter (outOfOrder, testElement.Attributes [0]);
+
+                       AssertEquals ("First attribute", testElement.Attributes [0].Value);
+                       AssertEquals ("Should still be second attribute", testElement.Attributes [1].Value);
+                       AssertEquals ("Third attribute", testElement.Attributes [2].Value);
                }
 
                [Test]
@@ -200,18 +200,18 @@ namespace MonoTests.System.Xml
                {
                        string dtd = "<!DOCTYPE root [<!ELEMENT root EMPTY><!ATTLIST root attr CDATA 'default'>]>";
                        string xml = dtd + "<root/>";
-                       XmlDocument doc = new XmlDocument();\r
-                       doc.LoadXml (xml);\r
-\r
-                       doc.DocumentElement.Attributes ["attr"].Value = "modified";\r
-                       doc.DocumentElement.RemoveAttribute("attr");\r
-\r
-                       XmlAttribute defAttr = doc.DocumentElement.Attributes ["attr"];\r
-                       AssertNotNull (defAttr);\r
-                       AssertEquals ("default", defAttr.Value);\r
-
-                       defAttr.Value = "default"; // same value as default\r
-                       AssertEquals (true, defAttr.Specified);\r
+                       XmlDocument doc = new XmlDocument();
+                       doc.LoadXml (xml);
+
+                       doc.DocumentElement.Attributes ["attr"].Value = "modified";
+                       doc.DocumentElement.RemoveAttribute("attr");
+
+                       XmlAttribute defAttr = doc.DocumentElement.Attributes ["attr"];
+                       AssertNotNull (defAttr);
+                       AssertEquals ("default", defAttr.Value);
+
+                       defAttr.Value = "default"; // same value as default
+                       AssertEquals (true, defAttr.Specified);
                }
        }
 }
index c1aec15bdb86a2ef77a876d2abdfe46bfeb86e52..7ef7a62387c52c70ed57d5014f3234ec6cc50c01 100644 (file)
@@ -15,7 +15,7 @@ using NUnit.Framework;
 namespace MonoTests.System.Xml
 {
        [TestFixture]
-       public class XmlAttributeTests : Assertion
+       public class XmlAttributeTests
        {
                XmlDocument doc;
                XmlAttribute attr;
@@ -49,7 +49,7 @@ namespace MonoTests.System.Xml
                [Test]
                public void Attributes ()
                {
-                       AssertNull (attr.Attributes);
+                       Assert.IsNull (attr.Attributes);
                }
 
                [Test]
@@ -57,19 +57,19 @@ namespace MonoTests.System.Xml
                {
                        attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
                        attr.Value = "baz";
-                       AssertEquals ("baz", attr.InnerXml);
-                       AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
+                       Assert.AreEqual ("baz", attr.InnerXml, "#1");
+                       Assert.AreEqual ("foo:bar=\"baz\"", attr.OuterXml, "#2");
                }
 
                [Test]
                public void AttributeWithNoValue ()
                {
                        XmlAttribute attribute = doc.CreateAttribute ("name");
-                       AssertEquals (String.Empty, attribute.Value);
-                       Assert (!attribute.HasChildNodes);
-                       AssertNull (attribute.FirstChild);
-                       AssertNull (attribute.LastChild);
-                       AssertEquals (0, attribute.ChildNodes.Count);
+                       Assert.AreEqual (String.Empty, attribute.Value, "#1");
+                       Assert.IsFalse (attribute.HasChildNodes, "#2");
+                       Assert.IsNull (attribute.FirstChild, "#3");
+                       Assert.IsNull (attribute.LastChild, "#4");
+                       Assert.AreEqual (0, attribute.ChildNodes.Count, "#5");
                }
 
                [Test]
@@ -77,82 +77,108 @@ namespace MonoTests.System.Xml
                {
                        XmlAttribute attribute = doc.CreateAttribute ("name");
                        attribute.Value = "value";
-                       AssertEquals ("value", attribute.Value);
-                       Assert (attribute.HasChildNodes);
-                       AssertNotNull (attribute.FirstChild);
-                       AssertNotNull (attribute.LastChild);
-                       AssertEquals (1, attribute.ChildNodes.Count);
-                       AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
-                       AssertEquals ("value", attribute.ChildNodes [0].Value);
+                       Assert.AreEqual ("value", attribute.Value, "#1");
+                       Assert.IsTrue (attribute.HasChildNodes, "#2");
+                       Assert.IsNotNull (attribute.FirstChild, "#3");
+                       Assert.IsNotNull (attribute.LastChild, "#4");
+                       Assert.AreEqual (1, attribute.ChildNodes.Count, "#5");
+                       Assert.AreEqual (XmlNodeType.Text, attribute.ChildNodes [0].NodeType, "#6");
+                       Assert.AreEqual ("value", attribute.ChildNodes [0].Value, "#7");
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void CheckPrefixWithNamespace ()
                {
                        XmlDocument doc = new XmlDocument ();
                        doc.LoadXml ("<root xmlns:foo='urn:foo' foo='attfoo' foo:foo='attfoofoo' />");
                        // hogehoge does not match to any namespace.
-                       AssertEquals ("xmlns:foo", doc.DocumentElement.Attributes [0].Name);
-                       doc.DocumentElement.Attributes [0].Prefix="hogehoge";
-                       doc.Save (Console.Out);
+                       Assert.AreEqual ("xmlns:foo", doc.DocumentElement.Attributes [0].Name);
+                       try {
+                               doc.DocumentElement.Attributes [0].Prefix = "hogehoge";
+                               doc.Save (TextWriter.Null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Cannot bind to the reserved namespace
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNull (ex.ParamName, "#5");
+                       }
                }
 
                [Test]
                public void NamespaceAttributes ()
                {
                        try {
-                               doc.CreateAttribute ("", "xmlns", "urn:foo");
-                               Assertion.Fail ("Creating xmlns attribute with invalid nsuri should be error.");
-                       } catch (Exception) {
+                               doc.CreateAttribute (string.Empty, "xmlns", "urn:foo");
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentException ex) {
+                               // The namespace declaration attribute has an
+                               // incorrect namespaceURI: urn:foo
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNull (ex.ParamName, "#A5");
                        }
+
                        doc.LoadXml ("<root/>");
+
                        try {
                                doc.DocumentElement.SetAttribute ("xmlns", "urn:foo", "urn:bar");
-                               Assertion.Fail ("SetAttribute for xmlns with invalid nsuri should be error.");
-                       } catch (ArgumentException) {
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // The namespace declaration attribute has an
+                               // incorrect namespaceURI: urn:foo
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
                        }
                }
 
                [Test]
                public void HasChildNodes ()
                {
-                       Assert (attr.HasChildNodes);
+                       Assert.IsTrue (attr.HasChildNodes, "#1");
+                       XmlAttribute attr2 = doc.CreateAttribute ("attr2");
+                       Assert.IsFalse (attr2.HasChildNodes, "#2");
                }
 
                [Test]
                public void Name ()
                {
-                       AssertEquals ("attr1", attr.Name);
+                       Assert.AreEqual ("attr1", attr.Name);
                }
 
                [Test]
                public void NodeType ()
                {
-                       AssertEquals (XmlNodeType.Attribute, attr.NodeType);
+                       Assert.AreEqual (XmlNodeType.Attribute, attr.NodeType);
                }
 
                [Test]
                public void OwnerDocument ()
                {
-                       AssertSame (doc, attr.OwnerDocument);
+                       Assert.AreSame (doc, attr.OwnerDocument);
                }
 
                [Test]
                public void ParentNode ()
                {
-                       AssertNull ("Attr parents not allowed", attr.ParentNode);
+                       Assert.IsNull (attr.ParentNode, "Attr parents not allowed");
                }
 
                [Test]
                public void Value ()
                {
-                       AssertEquals ("val1", attr.Value);
+                       Assert.AreEqual ("val1", attr.Value, "#1");
+                       XmlAttribute attr2 = doc.CreateAttribute ("attr2");
+                       Assert.AreEqual (string.Empty, attr2.Value, "#2");
                }
 
                [Test]
 #if NET_2_0
-               [Category ("NotDotNet")] // enbug in 2.0
+               [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=336180
 #endif
                public void SetInnerTextAndXml ()
                {
@@ -160,19 +186,18 @@ namespace MonoTests.System.Xml
                        doc.LoadXml ("<root name='value' />");
                        XmlAttribute attr = doc.DocumentElement.Attributes ["name"];
                        attr.InnerText = "a&b";
-                       AssertEquals ("setInnerText", "a&b", attr.Value);
+                       Assert.AreEqual ("a&b", attr.Value, "setInnerText");
                        attr.InnerXml = "a&amp;b";
-                       AssertEquals ("setInnerXml", "a&b", attr.Value);
+                       Assert.AreEqual ("a&b", attr.Value, "setInnerXml");
                        attr.InnerXml = "'a&amp;b'";
-                       AssertEquals ("setInnerXml.InnerXml", "'a&amp;b'", attr.InnerXml);
-                       AssertEquals ("setInnerXml.Value", "'a&b'", attr.Value);
+                       Assert.AreEqual ("'a&amp;b'", attr.InnerXml, "setInnerXml.InnerXml");
+                       Assert.AreEqual ("'a&b'", attr.Value, "setInnerXml.Value");
                        attr.InnerXml = "\"a&amp;b\"";
-                       AssertEquals ("Double_Quote", "\"a&amp;b\"", attr.InnerXml);
+                       Assert.AreEqual ("\"a&amp;b\"", attr.InnerXml, "Double_Quote");
                        attr.InnerXml = "\"a&amp;b'";
-                       AssertEquals ("DoubleQuoteStart_SingleQuoteEnd",
-                               "\"a&amp;b'", attr.InnerXml);
+                       Assert.AreEqual ("\"a&amp;b'", attr.InnerXml, "DoubleQuoteStart_SingleQuoteEnd");
 
-                       attr.Value = "";
+                       attr.Value = string.Empty;
                        XmlNodeChangedEventHandler evInserted = new XmlNodeChangedEventHandler (EventNodeInserted);
                        XmlNodeChangedEventHandler evChanged = new XmlNodeChangedEventHandler (EventNodeChanged);
                        XmlNodeChangedEventHandler evRemoved = new XmlNodeChangedEventHandler (EventNodeRemoved);
@@ -182,15 +207,15 @@ namespace MonoTests.System.Xml
                        try {
                                // set_InnerText event
                                attr.InnerText = "fire";
-                               AssertEquals ("setInnerText.NodeInserted", false, inserted);
-                               AssertEquals ("setInnerText.NodeChanged", true, changed);
-                               AssertEquals ("setInnerText.NodeRemoved", false, removed);
+                               Assert.IsFalse (inserted, "setInnerText.NodeInserted");
+                               Assert.IsTrue (changed, "setInnerText.NodeChanged");
+                               Assert.IsFalse (removed, "setInnerText.NodeRemoved");
                                inserted = changed = removed = false;
                                // set_InnerXml event
                                attr.InnerXml = "fire";
-                               AssertEquals ("setInnserXml.NodeInserted", true, inserted);
-                               AssertEquals ("setInnserXml.NodeChanged", false, changed);
-                               AssertEquals ("setInnserXml.NodeRemoved", true, removed);
+                               Assert.IsTrue (inserted, "setInnserXml.NodeInserted");
+                               Assert.IsFalse (changed, "setInnserXml.NodeChanged");
+                               Assert.IsTrue (removed, "setInnserXml.NodeRemoved");
                                inserted = changed = removed = false;
                        } finally {
                                doc.NodeInserted -= evInserted;
@@ -199,8 +224,6 @@ namespace MonoTests.System.Xml
                        }
                }
 
-
-
                private void OnSetInnerText (object o, XmlNodeChangedEventArgs e)
                {
                        if(e.NewParent.Value == "fire")
@@ -211,7 +234,7 @@ namespace MonoTests.System.Xml
                public void WriteTo ()
                {
                        doc.AppendChild (doc.CreateElement ("root"));
-                       doc.DocumentElement.SetAttribute ("attr","");
+                       doc.DocumentElement.SetAttribute ("attr", string.Empty);
                        doc.DocumentElement.Attributes ["attr"].InnerXml = "&ent;";
                        StringWriter sw = new StringWriter ();
                        XmlTextWriter xtw = new XmlTextWriter (sw);
@@ -219,7 +242,7 @@ namespace MonoTests.System.Xml
                        XmlAttribute attr = doc.DocumentElement.Attributes ["attr"];
                        attr.WriteTo (xtw);
                        xtw.Close ();
-                       Assertion.AssertEquals ("<result attr=\"&ent;\" />", sw.ToString ());
+                       Assert.AreEqual ("<result attr=\"&ent;\" />", sw.ToString ());
                }
 
                [Test]
@@ -229,23 +252,23 @@ namespace MonoTests.System.Xml
                        string xml = dtd + "<root><c foo='id1' bar='1' /><c foo='id2' bar='2'/></root>";
                        XmlValidatingReader vr = new XmlValidatingReader (xml, XmlNodeType.Document, null);
                        doc.Load (vr);
-                       AssertNotNull (doc.GetElementById ("id1"));
-                       AssertNotNull (doc.GetElementById ("id2"));
+                       Assert.IsNotNull (doc.GetElementById ("id1"));
+                       Assert.IsNotNull (doc.GetElementById ("id2"));
                        // MS.NET BUG: Later I try to append it to another element, but
                        // it should raise InvalidOperationException.
                        // (and if MS.NET conform to DOM 1.0, it should be XmlException.)
 //                     XmlAttribute attr = doc.DocumentElement.FirstChild.Attributes [0];
                        XmlAttribute attr = doc.DocumentElement.FirstChild.Attributes.RemoveAt (0);
-                       AssertEquals ("id1", attr.Value);
+                       Assert.AreEqual ("id1", attr.Value);
 
                        doc.DocumentElement.LastChild.Attributes.SetNamedItem (attr);
-                       AssertNotNull (doc.GetElementById ("id1"));
+                       Assert.IsNotNull (doc.GetElementById ("id1"));
                        XmlElement elem2 = doc.GetElementById ("id2");
                        // MS.NET BUG: it doesn't remove replaced attribute with SetNamedItem!
 //                     AssertNull (elem2);
 //                     AssertEquals ("2", elem2.GetAttribute ("bar"));
 //                     elem2.RemoveAttribute ("foo");
-//                     AssertEquals ("", elem2.GetAttribute ("foo"));
+//                     AssertEquals (string.Empty, elem2.GetAttribute ("foo"));
 
                        // MS.NET BUG: elem should be the element which has the attribute bar='1'!
                        XmlElement elem = doc.GetElementById ("id1");
@@ -256,9 +279,9 @@ namespace MonoTests.System.Xml
                        doc.DocumentElement.AppendChild (elemNew);
                        // but once attribute is set, document recognizes this ID.
                        elemNew.SetAttribute ("foo", "id3");
-                       AssertNotNull (doc.GetElementById ("id3"));
+                       Assert.IsNotNull (doc.GetElementById ("id3"));
                        elemNew.RemoveAttribute ("foo");
-                       AssertNull (doc.GetElementById ("id3"));
+                       Assert.IsNull (doc.GetElementById ("id3"));
 
                        // MS.NET BUG: multiple IDs are allowed.
                        // In such case GetElementById fails.
@@ -270,9 +293,9 @@ namespace MonoTests.System.Xml
 
                        // Finally...
                        doc.RemoveAll ();
-                       AssertNull (doc.GetElementById ("id1"));
-                       AssertNull (doc.GetElementById ("id2"));
-                       AssertNull (doc.GetElementById ("id3"));
+                       Assert.IsNull (doc.GetElementById ("id1"));
+                       Assert.IsNull (doc.GetElementById ("id2"));
+                       Assert.IsNull (doc.GetElementById ("id3"));
                }
 
                int removeAllStep;
@@ -290,23 +313,24 @@ namespace MonoTests.System.Xml
                private void OnInsert (object o, XmlNodeChangedEventArgs e)
                {
                        if (removeAllStep == 1)
-                               AssertEquals (XmlNodeType.Text, e.Node.NodeType);
+                               Assert.AreEqual (XmlNodeType.Text, e.Node.NodeType);
                        else if (removeAllStep == 2) {
-                               AssertEquals ("foo", e.Node.Name);
-                               Assert (! ((XmlAttribute) e.Node).Specified);
-                       }
-                       else
-                               Fail ();
+                               Assert.AreEqual ("foo", e.Node.Name);
+                               Assert.IsFalse (((XmlAttribute) e.Node).Specified);
+                       } else
+                               Assert.Fail ();
                        removeAllStep++;
                }
+
                private void OnChange (object o, XmlNodeChangedEventArgs e)
                {
-                       Fail ("Should not be called.");
+                       Assert.Fail ("Should not be called.");
                }
+
                private void OnRemove (object o, XmlNodeChangedEventArgs e)
                {
-                       AssertEquals (0, removeAllStep);
-                       AssertEquals ("foo", e.Node.Name);
+                       Assert.AreEqual (0, removeAllStep, "#1");
+                       Assert.AreEqual ("foo", e.Node.Name, "#2");
                        removeAllStep++;
                }
 
@@ -315,10 +339,10 @@ namespace MonoTests.System.Xml
                {
                        doc.LoadXml ("<root attr=''/>");
                        XmlAttribute attr = doc.DocumentElement.GetAttributeNode ("attr");
-                       AssertNotNull (attr);
-                       AssertEquals (1, attr.ChildNodes.Count);
-                       AssertEquals (XmlNodeType.Text, attr.ChildNodes [0].NodeType);
-                       AssertEquals (String.Empty, attr.ChildNodes [0].Value);
+                       Assert.IsNotNull (attr, "#1");
+                       Assert.AreEqual (1, attr.ChildNodes.Count, "#2");
+                       Assert.AreEqual (XmlNodeType.Text, attr.ChildNodes [0].NodeType, "#3");
+                       Assert.AreEqual (String.Empty, attr.ChildNodes [0].Value, "#4");
                }
 
                [Test]
@@ -330,7 +354,7 @@ namespace MonoTests.System.Xml
                        XmlAttribute a = doc.DocumentElement.Attributes [0];
                        a.Prefix ="hoge:hoge:hoge";
                        // This test is nothing more than ****.
-                       AssertEquals ("hoge:hoge:hoge", a.Prefix);
+                       Assert.AreEqual ("hoge:hoge:hoge", a.Prefix);
                        // The resulting string is not XML (so broken), so 
                        // it should not be tested.
                        // doc.Save (TextWriter.Null);
@@ -355,25 +379,26 @@ namespace MonoTests.System.Xml
                {
                        XmlDocument doc = new XmlDocument ();
                        doc.LoadXml ("<!DOCTYPE USS[<!ELEMENT USS EMPTY><!ATTLIST USS Id ID #REQUIRED>]><USS Id='foo'/>");
-                       AssertNotNull ("#1", doc.SelectSingleNode ("id ('foo')"));
+                       Assert.IsNotNull (doc.SelectSingleNode ("id ('foo')"), "#1");
                        doc.DocumentElement.Attributes [0].Value = "bar";
-                       AssertNull ("#2", doc.SelectSingleNode ("id ('foo')"));
-                       AssertNotNull ("#3", doc.SelectSingleNode ("id ('bar')"));
+                       Assert.IsNull (doc.SelectSingleNode ("id ('foo')"), "#2");
+                       Assert.IsNotNull (doc.SelectSingleNode ("id ('bar')"), "#3");
                        doc.DocumentElement.Attributes [0].ChildNodes [0].Value = "baz";
                        // Tests below don't work fine under MS.NET
-//                     AssertNull ("#4", doc.SelectSingleNode ("id ('bar')"));
-//                     AssertNotNull ("#5", doc.SelectSingleNode ("id ('baz')"));
+//                     Assert.IsNull (doc.SelectSingleNode ("id ('bar')"), "#4");
+//                     Assert.IsNotNull (doc.SelectSingleNode ("id ('baz')"), "#5");
                        doc.DocumentElement.Attributes [0].AppendChild (doc.CreateTextNode ("baz"));
-                       AssertNull ("#6", doc.SelectSingleNode ("id ('baz')"));
-//                     AssertNull ("#6-2", doc.SelectSingleNode ("id ('bar')"));
-//                     AssertNotNull ("#7", doc.SelectSingleNode ("id ('bazbaz')"));
+                       Assert.IsNull (doc.SelectSingleNode ("id ('baz')"), "#6");
+//                     Assert.IsNull (doc.SelectSingleNode ("id ('bar')"), "#7");
+//                     Assert.IsNotNull (doc.SelectSingleNode ("id ('bazbaz')"), "#7");
                }
 
                [Test] // http://lists.ximian.com/pipermail/mono-list/2006-May/031557.html
                public void NonEmptyPrefixWithEmptyNS ()
                {
                        XmlDocument xmlDoc = new XmlDocument ();
-                       xmlDoc.AppendChild (xmlDoc.CreateNode (XmlNodeType.XmlDeclaration, "", ""));
+                       xmlDoc.AppendChild (xmlDoc.CreateNode (XmlNodeType.XmlDeclaration,
+                               string.Empty, string.Empty));
 
                        XmlElement docElement = xmlDoc.CreateElement ("doc");
                        docElement.SetAttribute ("xmlns", "http://whatever.org/XMLSchema/foo");
index 8cde7c4ad38009bafb34d1ef20e02ffe5c60cd3f..bd667db8cf1ca614259c1891192f99bb874ac0ff 100644 (file)
@@ -89,29 +89,29 @@ namespace MonoTests.System.Xml
                        XmlElement el = document.CreateElement ("root");\r
                        el.AppendChild (document.CreateTextNode ("simple text node."));\r
                        document.AppendChild (el);\r
-                       AssertEquals (
-@"Inserting: Text into Element.
-Inserted: Text into Element.
-Inserting: Element into Document.
-Inserted: Element into Document.
-", EventLog);\r
+                       AssertEquals (\r
+                               "Inserting: Text into Element.\n" +\r
+                               "Inserted: Text into Element.\n" +\r
+                               "Inserting: Element into Document.\n" +\r
+                               "Inserted: Element into Document.\n",\r
+                               EventLog);\r
                }\r
 \r
                [Test]\r
-               public void DefaultAttributeRemoval ()
-               {
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml ("<!DOCTYPE root [<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def'>]><root></root>");
-                       SetEvents (doc);
-                       doc.DocumentElement.RemoveAll ();
-                       AssertEquals (
-@"Removing: Attribute from Element.
-Removed: Attribute from Element.
-Inserting: Text into Attribute.
-Inserted: Text into Attribute.
-Inserting: Attribute into Element.
-Inserted: Attribute into Element.
-", EventLog);
-               }
+               public void DefaultAttributeRemoval ()\r
+               {\r
+                       XmlDocument doc = new XmlDocument ();\r
+                       doc.LoadXml ("<!DOCTYPE root [<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def'>]><root></root>");\r
+                       SetEvents (doc);\r
+                       doc.DocumentElement.RemoveAll ();\r
+                       AssertEquals (\r
+                               "Removing: Attribute from Element.\n" +\r
+                               "Removed: Attribute from Element.\n" +\r
+                               "Inserting: Text into Attribute.\n" +\r
+                               "Inserted: Text into Attribute.\n" +\r
+                               "Inserting: Attribute into Element.\n" +\r
+                               "Inserted: Attribute into Element.\n",\r
+                               EventLog);\r
+               }\r
        }\r
 }\r
index 1940e2b8bc1eea79451933022408fe6952c1961d..4ecfd7c405ec5270eb7063949f3ff4831e7319ce 100644 (file)
@@ -599,63 +599,63 @@ namespace MonoTests.System.Xml
                [Test]
                public void GetElementsByTagNameNs2 ()
                {
-                       document.LoadXml (@"<root>\r
-                       <x:a xmlns:x='urn:foo' id='a'>\r
-                       <y:a xmlns:y='urn:foo' id='b'/>\r
-                       <x:a id='c' />\r
-                       <z id='d' />\r
-                       text node\r
-                       <?a processing instruction ?>\r
-                       <x:w id='e'/>\r
-                       </x:a>\r
-                       </root>");\r
-                       // id='b' has different prefix. Should not caught by (name),\r
-                       // while should caught by (name, ns).\r
-                       XmlNodeList nl = document.GetElementsByTagName ("x:a");\r
-                       AssertEquals (2, nl.Count);\r
-                       AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [1].Attributes ["id"].Value);\r
-
-                       nl = document.GetElementsByTagName ("a", "urn:foo");\r
-                       AssertEquals (3, nl.Count);\r
-                       AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
-                       AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
+                       document.LoadXml (@"<root>
+                       <x:a xmlns:x='urn:foo' id='a'>
+                       <y:a xmlns:y='urn:foo' id='b'/>
+                       <x:a id='c' />
+                       <z id='d' />
+                       text node
+                       <?a processing instruction ?>
+                       <x:w id='e'/>
+                       </x:a>
+                       </root>");
+                       // id='b' has different prefix. Should not caught by (name),
+                       // while should caught by (name, ns).
+                       XmlNodeList nl = document.GetElementsByTagName ("x:a");
+                       AssertEquals (2, nl.Count);
+                       AssertEquals ("a", nl [0].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [1].Attributes ["id"].Value);
+
+                       nl = document.GetElementsByTagName ("a", "urn:foo");
+                       AssertEquals (3, nl.Count);
+                       AssertEquals ("a", nl [0].Attributes ["id"].Value);
+                       AssertEquals ("b", nl [1].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [2].Attributes ["id"].Value);
 
                        // name wildcard
-                       nl = document.GetElementsByTagName ("*");\r
-                       AssertEquals (6, nl.Count);\r
-                       AssertEquals ("root", nl [0].Name);\r
-                       AssertEquals ("a", nl [1].Attributes ["id"].Value);\r
-                       AssertEquals ("b", nl [2].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [3].Attributes ["id"].Value);\r
-                       AssertEquals ("d", nl [4].Attributes ["id"].Value);\r
-                       AssertEquals ("e", nl [5].Attributes ["id"].Value);\r
+                       nl = document.GetElementsByTagName ("*");
+                       AssertEquals (6, nl.Count);
+                       AssertEquals ("root", nl [0].Name);
+                       AssertEquals ("a", nl [1].Attributes ["id"].Value);
+                       AssertEquals ("b", nl [2].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [3].Attributes ["id"].Value);
+                       AssertEquals ("d", nl [4].Attributes ["id"].Value);
+                       AssertEquals ("e", nl [5].Attributes ["id"].Value);
 
                        // wildcard - local and ns
-                       nl = document.GetElementsByTagName ("*", "*");\r
-                       AssertEquals (6, nl.Count);\r
-                       AssertEquals ("root", nl [0].Name);\r
-                       AssertEquals ("a", nl [1].Attributes ["id"].Value);\r
-                       AssertEquals ("b", nl [2].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [3].Attributes ["id"].Value);\r
-                       AssertEquals ("d", nl [4].Attributes ["id"].Value);\r
-                       AssertEquals ("e", nl [5].Attributes ["id"].Value);\r
+                       nl = document.GetElementsByTagName ("*", "*");
+                       AssertEquals (6, nl.Count);
+                       AssertEquals ("root", nl [0].Name);
+                       AssertEquals ("a", nl [1].Attributes ["id"].Value);
+                       AssertEquals ("b", nl [2].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [3].Attributes ["id"].Value);
+                       AssertEquals ("d", nl [4].Attributes ["id"].Value);
+                       AssertEquals ("e", nl [5].Attributes ["id"].Value);
 
                        // namespace wildcard - namespace
-                       nl = document.GetElementsByTagName ("*", "urn:foo");\r
-                       AssertEquals (4, nl.Count);\r
-                       AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
-                       AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
-                       AssertEquals ("e", nl [3].Attributes ["id"].Value);\r
+                       nl = document.GetElementsByTagName ("*", "urn:foo");
+                       AssertEquals (4, nl.Count);
+                       AssertEquals ("a", nl [0].Attributes ["id"].Value);
+                       AssertEquals ("b", nl [1].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [2].Attributes ["id"].Value);
+                       AssertEquals ("e", nl [3].Attributes ["id"].Value);
 
                        // namespace wildcard - local only. I dare say, such usage is not XML-ish!
-                       nl = document.GetElementsByTagName ("a", "*");\r
-                       AssertEquals (3, nl.Count);\r
-                       AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
-                       AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
-                       AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
+                       nl = document.GetElementsByTagName ("a", "*");
+                       AssertEquals (3, nl.Count);
+                       AssertEquals ("a", nl [0].Attributes ["id"].Value);
+                       AssertEquals ("b", nl [1].Attributes ["id"].Value);
+                       AssertEquals ("c", nl [2].Attributes ["id"].Value);
                }
 
                [Test]
@@ -1087,36 +1087,36 @@ namespace MonoTests.System.Xml
                [Test]
                public void LoadEntityReference ()
                {
-                       string xml = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*><!ENTITY ent 'val'>]><root attr='a &ent; string'>&ent;</root>";\r
-                       XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);\r
-                       XmlDocument doc = new XmlDocument ();\r
-                       doc.Load (xtr);\r
-                       AssertEquals ("#text node", XmlNodeType.EntityReference, \r
-                               doc.DocumentElement.FirstChild.NodeType);\r
-                       AssertEquals ("#attribute", XmlNodeType.EntityReference, \r
-                               doc.DocumentElement.Attributes [0].ChildNodes [1].NodeType);\r
+                       string xml = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*><!ENTITY ent 'val'>]><root attr='a &ent; string'>&ent;</root>";
+                       XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);
+                       XmlDocument doc = new XmlDocument ();
+                       doc.Load (xtr);
+                       AssertEquals ("#text node", XmlNodeType.EntityReference, 
+                               doc.DocumentElement.FirstChild.NodeType);
+                       AssertEquals ("#attribute", XmlNodeType.EntityReference, 
+                               doc.DocumentElement.Attributes [0].ChildNodes [1].NodeType);
                }
 
                [Test]
                public void ReadNodeEmptyContent ()
                {
-                       XmlTextReader xr = new XmlTextReader ("", XmlNodeType.Element, null);\r
-                       xr.Read ();\r
-                       Console.WriteLine (xr.NodeType);\r
-                       XmlNode n = document.ReadNode (xr);\r
-                       AssertNull (n);\r
+                       XmlTextReader xr = new XmlTextReader ("", XmlNodeType.Element, null);
+                       xr.Read ();
+                       Console.WriteLine (xr.NodeType);
+                       XmlNode n = document.ReadNode (xr);
+                       AssertNull (n);
                }
 
                [Test]
                public void ReadNodeWhitespace ()
                {
-                       XmlTextReader xr = new XmlTextReader ("  ", XmlNodeType.Element, null);\r
-                       xr.Read ();\r
-                       Console.WriteLine (xr.NodeType);\r
+                       XmlTextReader xr = new XmlTextReader ("  ", XmlNodeType.Element, null);
+                       xr.Read ();
+                       Console.WriteLine (xr.NodeType);
                        document.PreserveWhitespace = false; // Note this line.
-                       XmlNode n = document.ReadNode (xr);\r
-                       AssertNotNull (n);\r
-                       AssertEquals (XmlNodeType.Whitespace, n.NodeType);\r
+                       XmlNode n = document.ReadNode (xr);
+                       AssertNotNull (n);
+                       AssertEquals (XmlNodeType.Whitespace, n.NodeType);
                }
 
                [Test]
index 3d5b667ffc0fcd51a5db29f15abd1fb24cfb9b08..c19442cfcead3a14b653f934c4c85e05c9aeee09 100644 (file)
@@ -92,13 +92,13 @@ namespace MonoTests.System.Xml
                [ExpectedException (typeof (XmlException))]
                public void IncorrectInternalSubset ()
                {
-                       XmlDocument doc = new XmlDocument ();\r
-                       XmlDocumentType doctype = doc.CreateDocumentType (\r
-                               "root", "public-hogehoge", null,\r
-                               "invalid_intsubset");\r
-                       doctype = doc.CreateDocumentType ("root",\r
-                               "public-hogehoge", null, \r
-                               "<!ENTITY % pe1 '>'> <!ELEMENT e EMPTY%pe1;");\r
+                       XmlDocument doc = new XmlDocument ();
+                       XmlDocumentType doctype = doc.CreateDocumentType (
+                               "root", "public-hogehoge", null,
+                               "invalid_intsubset");
+                       doctype = doc.CreateDocumentType ("root",
+                               "public-hogehoge", null, 
+                               "<!ENTITY % pe1 '>'> <!ELEMENT e EMPTY%pe1;");
                }
 
                [Test]
index 200dd50deb23ff813fe5d6247deb096b33db192c..612135a2167f242b734e0d43a86bde0a1f93da47 100644 (file)
@@ -32,51 +32,51 @@ namespace MonoTests.System.Xml
                [Test]
                public void DescendantsRecursively ()
                {
-                       string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*>"\r
-                               + "<!ENTITY ent 'value'>"\r
-                               + "<!ENTITY ent2 'my &ent; string'>"\r
-                               + "]>";\r
-                       string xml = dtd + "<root>&ent;</root>";\r
-                       XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);\r
-                       XmlDocument doc = new XmlDocument ();\r
-                       doc.Load (xtr);\r
-                       XmlEntity ent = (XmlEntity) doc.DocumentType.Entities.GetNamedItem ("ent2");\r
-                       AssertEquals ("ent2", ent.Name);\r
-                       AssertEquals ("my ", ent.FirstChild.Value);\r
-                       AssertNotNull (ent.FirstChild.NextSibling.FirstChild);\r
-                       AssertEquals ("value", ent.FirstChild.NextSibling.FirstChild.Value);\r
+                       string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*>"
+                               + "<!ENTITY ent 'value'>"
+                               + "<!ENTITY ent2 'my &ent; string'>"
+                               + "]>";
+                       string xml = dtd + "<root>&ent;</root>";
+                       XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);
+                       XmlDocument doc = new XmlDocument ();
+                       doc.Load (xtr);
+                       XmlEntity ent = (XmlEntity) doc.DocumentType.Entities.GetNamedItem ("ent2");
+                       AssertEquals ("ent2", ent.Name);
+                       AssertEquals ("my ", ent.FirstChild.Value);
+                       AssertNotNull (ent.FirstChild.NextSibling.FirstChild);
+                       AssertEquals ("value", ent.FirstChild.NextSibling.FirstChild.Value);
                }
 
                [Test]
                public void ChildNodes ()
                {
-                       XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",\r
-                               XmlNodeType.Document, null);\r
-                       XmlDocument doc = new XmlDocument ();\r
-\r
-                       doc.Load (xtr);\r
-                       XmlEntityReference ent = doc.CreateEntityReference ("ent");\r
-                       // ChildNodes are not added yet.\r
-                       AssertNull (ent.FirstChild);\r
-                       doc.DocumentElement.AppendChild (ent);\r
-                       // ChildNodes are added here.\r
-                       AssertNotNull (ent.FirstChild);\r
-\r
-                       ent = doc.CreateEntityReference ("foo");\r
-                       AssertNull (ent.FirstChild);\r
-                       // Entity value is empty when the matching DTD entity \r
-                       // node does not exist.\r
-                       doc.DocumentElement.AppendChild (ent);\r
-                       AssertNotNull (ent.FirstChild);\r
-\r
-                       AssertEquals (String.Empty, ent.FirstChild.Value);\r
+                       XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",
+                               XmlNodeType.Document, null);
+                       XmlDocument doc = new XmlDocument ();
+
+                       doc.Load (xtr);
+                       XmlEntityReference ent = doc.CreateEntityReference ("ent");
+                       // ChildNodes are not added yet.
+                       AssertNull (ent.FirstChild);
+                       doc.DocumentElement.AppendChild (ent);
+                       // ChildNodes are added here.
+                       AssertNotNull (ent.FirstChild);
+
+                       ent = doc.CreateEntityReference ("foo");
+                       AssertNull (ent.FirstChild);
+                       // Entity value is empty when the matching DTD entity 
+                       // node does not exist.
+                       doc.DocumentElement.AppendChild (ent);
+                       AssertNotNull (ent.FirstChild);
+
+                       AssertEquals (String.Empty, ent.FirstChild.Value);
 
                        ent = doc.CreateEntityReference ("el");
-                       AssertEquals ("", ent.InnerText);\r
-                       doc.DocumentElement.AppendChild (ent);\r
-                       AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);\r
-                       AssertEquals ("hoge", ent.InnerText);\r
-                       AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);\r
+                       AssertEquals ("", ent.InnerText);
+                       doc.DocumentElement.AppendChild (ent);
+                       AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);
+                       AssertEquals ("hoge", ent.InnerText);
+                       AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);
                }
        }
 }
index 8d96ff9f8b91adfcee9b302e1bf7943e21ee17dc..849041bdbfd5eb937275f6f746de4878293d35d1 100644 (file)
@@ -241,54 +241,54 @@ namespace MonoTests.System.Xml
                [Test]
                public void Normalize2 ()
                {
-                       XmlDocument doc = new XmlDocument ();\r
-                       doc.PreserveWhitespace = true;\r
-                       doc.LoadXml ("<root>  </root>");\r
-                       XmlElement root = doc.DocumentElement;\r
-                       root.AppendChild (doc.CreateTextNode ("foo"));\r
-                       root.AppendChild (doc.CreateTextNode ("bar"));\r
-                       root.AppendChild (doc.CreateWhitespace ("   "));\r
-                       root.AppendChild (doc.CreateTextNode ("baz"));\r
-                       doc.NodeInserted += new XmlNodeChangedEventHandler (OnChange);\r
-                       doc.NodeChanged += new XmlNodeChangedEventHandler (OnChange);\r
-                       doc.NodeRemoved += new XmlNodeChangedEventHandler (OnChange);\r
-                       AssertEquals ("Before Normalize()", 5, root.ChildNodes.Count);\r
-                       root.Normalize ();\r
-                       AssertEquals ("<root>  foobar   baz</root>", root.OuterXml);\r
-                       AssertEquals ("After Normalize()", 1, root.ChildNodes.Count);\r
+                       XmlDocument doc = new XmlDocument ();
+                       doc.PreserveWhitespace = true;
+                       doc.LoadXml ("<root>  </root>");
+                       XmlElement root = doc.DocumentElement;
+                       root.AppendChild (doc.CreateTextNode ("foo"));
+                       root.AppendChild (doc.CreateTextNode ("bar"));
+                       root.AppendChild (doc.CreateWhitespace ("   "));
+                       root.AppendChild (doc.CreateTextNode ("baz"));
+                       doc.NodeInserted += new XmlNodeChangedEventHandler (OnChange);
+                       doc.NodeChanged += new XmlNodeChangedEventHandler (OnChange);
+                       doc.NodeRemoved += new XmlNodeChangedEventHandler (OnChange);
+                       AssertEquals ("Before Normalize()", 5, root.ChildNodes.Count);
+                       root.Normalize ();
+                       AssertEquals ("<root>  foobar   baz</root>", root.OuterXml);
+                       AssertEquals ("After Normalize()", 1, root.ChildNodes.Count);
                }
 
                int normalize2Count;
 
-               private void OnChange (object o, XmlNodeChangedEventArgs e)\r
-               {\r
-                       switch (normalize2Count) {\r
-                       case 0:\r
-                               AssertEquals ("Action0", XmlNodeChangedAction.Remove, e.Action);\r
-                               AssertEquals ("Value0", "  ", e.Node.Value);\r
-                               break;\r
-                       case 1:\r
-                               AssertEquals ("Action1", XmlNodeChangedAction.Remove, e.Action);\r
-                               AssertEquals ("Value1", "bar", e.Node.Value);\r
-                               break;\r
-                       case 2:\r
-                               AssertEquals ("Action2", XmlNodeChangedAction.Remove, e.Action);\r
-                               AssertEquals ("Value2", "   ", e.Node.Value);\r
-                               break;\r
-                       case 3:\r
-                               AssertEquals ("Action3", XmlNodeChangedAction.Remove, e.Action);\r
-                               AssertEquals ("Value3", "baz", e.Node.Value);\r
-                               break;\r
-                       case 4:\r
-                               AssertEquals ("Action4", XmlNodeChangedAction.Change, e.Action);\r
-                               AssertEquals ("Value4", "  foobar   baz", e.Node.Value);\r
-                               break;\r
-                       default:\r
-                               Fail (String.Format ("Unexpected event. Action = {0}, node type = {1}, node name = {2}, node value = {3}", e.Action, e.Node.NodeType, e.Node.Name, e.Node.Value));\r
-                               break;\r
-                       }\r
-                       normalize2Count++;\r
-               }\r
+               private void OnChange (object o, XmlNodeChangedEventArgs e)
+               {
+                       switch (normalize2Count) {
+                       case 0:
+                               AssertEquals ("Action0", XmlNodeChangedAction.Remove, e.Action);
+                               AssertEquals ("Value0", "  ", e.Node.Value);
+                               break;
+                       case 1:
+                               AssertEquals ("Action1", XmlNodeChangedAction.Remove, e.Action);
+                               AssertEquals ("Value1", "bar", e.Node.Value);
+                               break;
+                       case 2:
+                               AssertEquals ("Action2", XmlNodeChangedAction.Remove, e.Action);
+                               AssertEquals ("Value2", "   ", e.Node.Value);
+                               break;
+                       case 3:
+                               AssertEquals ("Action3", XmlNodeChangedAction.Remove, e.Action);
+                               AssertEquals ("Value3", "baz", e.Node.Value);
+                               break;
+                       case 4:
+                               AssertEquals ("Action4", XmlNodeChangedAction.Change, e.Action);
+                               AssertEquals ("Value4", "  foobar   baz", e.Node.Value);
+                               break;
+                       default:
+                               Fail (String.Format ("Unexpected event. Action = {0}, node type = {1}, node name = {2}, node value = {3}", e.Action, e.Node.NodeType, e.Node.Name, e.Node.Value));
+                               break;
+                       }
+                       normalize2Count++;
+               }
 
                [Test]
                public void PrependChild()
index 8c2fcca2dc068b364ef22ec0abafc55054ef21b2..a3bbde625d3f52ed1313d48049bb4652bbe86a3d 100644 (file)
@@ -230,15 +230,15 @@ namespace MonoTests.System.Xml
                        vr.Read (); // bug\r
                        AssertEquals ("#4", "urn:a", vr.NamespaceURI);\r
                }\r
-
-               [Test]
-               public void MultipleSchemaInSchemaLocation ()
-               {
-                       XmlTextReader xtr = new XmlTextReader ("Test/XmlFiles/xsd/multi-schemaLocation.xml");
-                       XmlValidatingReader vr = new XmlValidatingReader (xtr);
-                       while (!vr.EOF)
-                               vr.Read ();
-               }
+\r
+               [Test]\r
+               public void MultipleSchemaInSchemaLocation ()\r
+               {\r
+                       XmlTextReader xtr = new XmlTextReader ("Test/XmlFiles/xsd/multi-schemaLocation.xml");\r
+                       XmlValidatingReader vr = new XmlValidatingReader (xtr);\r
+                       while (!vr.EOF)\r
+                               vr.Read ();\r
+               }\r
 \r
                [Test]\r
                public void ReadTypedValueSimpleTypeRestriction ()\r
index 6b86cffa305a5ad6a871c2fffcb1fd969c71dfe9..c05a1f43b01865f61068b58732bca49b3d028ff5 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-31  Mark Probst  <mark.probst@gmail.com>
+
+       * MonoMethod.cs: Don't do CAS security checks in Invoke for 2.1
+       profile.
+
 2008-03-25  Zoltan Varga  <vargaz@gmail.com>
 
        * MonoCMethod.cs (Invoke): Avoid a crash if this is called on a ctor of an open
index 1677373a096bf5635167ac0c367a9fa52ff17318..35f56915c26e2a57b3efdb29d15adab641725c5e 100644 (file)
@@ -133,12 +133,14 @@ namespace System.Reflection {
                        if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
                                throw new ArgumentException ("parameters");
 
+#if !NET_2_1
                        if (SecurityManager.SecurityEnabled) {
                                // sadly Attributes doesn't tell us which kind of security action this is so
                                // we must do it the hard way - and it also means that we can skip calling
                                // Attribute (which is another an icall)
                                SecurityManager.ReflectedLinkDemandInvoke (this);
                        }
+#endif
 
 #if NET_2_0
                        if (ContainsGenericParameters)
index 77cca93e3d198110bb91360d2a2e9a9a0b1e5b73..5a0ee74ce0ce18e87911e675e268315148188b1f 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-01: Eyal Alaluf <eyala@mainsoft.com>
+
+       * Thread.cs: Put a NumberFormatter instance as a member of the current
+         thread so it can reused for performint ToString conversions.
+
 2008-03-26  Massimiliano Mantione <massi@ximian.com>
        * Thread.cs: Renamed "unused6" because it will be used to hold
        the "mono_thread_manage" callback.
index 79939f9deeecd33d05a2e6a03a7abcb9442fe325..c780e0c80f9776b03891d94e1f13c3af7569df49 100644 (file)
@@ -120,6 +120,7 @@ namespace System.Threading {
                private int managed_id;
                
                private IPrincipal _principal;
+               internal NumberFormatter _numberFormatter;
 
                public static Context CurrentContext {
                        [SecurityPermission (SecurityAction.LinkDemand, Infrastructure=true)]
@@ -238,6 +239,18 @@ namespace System.Threading {
                        slots [slot.slot] = data;
                }
 
+               internal NumberFormatter AcquireNumberFormatter() {
+                       NumberFormatter res = _numberFormatter;
+                       _numberFormatter = null;
+                       if (res == null)
+                               return new NumberFormatter (this);
+                       return res;
+               }
+
+               internal void ReleaseNumberFormatter (NumberFormatter formatter) {
+                       _numberFormatter = formatter;
+               }
+
                public static AppDomain GetDomain() {
                        return AppDomain.CurrentDomain;
                }
@@ -407,6 +420,8 @@ namespace System.Threading {
                                                //
                                                SetCachedCurrentCulture (culture);
                                                in_currentculture = false;
+                                               if (_numberFormatter != null)
+                                                       _numberFormatter.CurrentCulture = culture;
                                                return culture;
                                        }
                                }
@@ -425,6 +440,8 @@ namespace System.Threading {
                                        in_currentculture = false;
                                }
 
+                               if (_numberFormatter != null)
+                                       _numberFormatter.CurrentCulture = culture;
                                return culture;
                        }
                        
@@ -460,6 +477,8 @@ namespace System.Threading {
                                } finally {
                                        in_currentculture = false;
                                }
+                               if (_numberFormatter != null)
+                                       _numberFormatter.CurrentCulture = value;
                        }
                }
 
index 40ade96c5e0cd4d75b0d65104496de9f2e5a97aa..0071a7d1f21b79839a9d22eec49b68a666d387ba 100644 (file)
@@ -144,7 +144,7 @@ namespace System
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (string format)
@@ -154,14 +154,12 @@ namespace System
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== IConvertible Methods =========== //
index b830845efb0fdb476035e8d8642ef37eb6e52f8f..93cf54fb6dd40fcd2fba6913afbd55bbed2ba44c 100644 (file)
@@ -1,3 +1,18 @@
+2008-04-01  Eyal Alaluf <eyala@mainsoft.com>
+
+       * NumberFormatter.cs NumberFormatter.jvm.cs: Performance optimizations.
+         Reuse a per thread instance to format all the primitive types. Modify
+         class accordingly so the same
+         instance can be used multiple times.
+       * Int16.cs UInt64.cs Double.cs SByte.cs UInt16.cs Byte.csDecimal.cs
+         TimeSpan.cs Int32.cs Int64.cs Single.cs UInt32.cs: Change use of
+         NumberFormatter to adapt to above changes in class interface.
+
+2008-03-31  Mark Probst  <mark.probst@gmail.com>
+
+       * MonoType.cs: Don't do CAS security checks in CheckMethodSecurity
+       for 2.1 profile.
+
 2008-03-28  Marek Safar  <marek.safar@gmail.com>
 
        * Nullable.cs (Box): Do things explicitly and not rely on broken gmcs
index 13f50160409c64496352a00bef11dd8b0d7c6825..b49ffbc5a055001b2ef2a36cfc34bbf1477a7f33 100644 (file)
@@ -1326,13 +1326,7 @@ namespace System
 
         public string ToString (string format, IFormatProvider provider) 
         {
-               NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-
-               // use "G" for null or empty string
-               if ((format == null) || (format.Length == 0))
-                       format = "G";   
-               
-               return NumberFormatter.NumberToString (format, this, nfi);
+            return NumberFormatter.NumberToString (format, this, provider);
         }
 
         public override string ToString() 
index 9f5ff1c60af8c6f59c62e13d0a3ee5841abb84b4..8ab29576959973d96bfb500671e681ddbb07713e 100644 (file)
@@ -506,14 +506,12 @@ namespace System {
 #endif
                public override string ToString ()
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (null);
-                       return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -523,8 +521,7 @@ namespace System {
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== IConvertible Methods =========== //
index 919641395b8a57c6a64d2abd09ad4ff90f0102d8..a0eb592408bfe43d5e85c641b175a8040d249204 100644 (file)
@@ -241,13 +241,12 @@ namespace System {
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -257,8 +256,7 @@ namespace System {
 
                public string ToString (string format, IFormatProvider fp)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
-                       return NumberFormatter.NumberToString(format, m_value, nfi);
+                       return NumberFormatter.NumberToString(format, m_value, fp);
                }
 
                // =========== IConvertible Methods =========== //
index 5df15b4dcbdca94b1f279fae17a0bfc8a4344877..5539613b9b521b268940ac3a34442ceebdd54928 100644 (file)
@@ -625,13 +625,12 @@ namespace System {
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -641,8 +640,7 @@ namespace System {
 
                public string ToString (string format, IFormatProvider fp )
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, fp);
                }
 
                // =========== IConvertible Methods =========== //
index 5b105c60eaa9732b5cfd6a90867e3bf20c02f064..3c2810b5f88928d257093851b8e3b19191c4bce3 100644 (file)
@@ -498,13 +498,12 @@ namespace System {
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -514,8 +513,7 @@ namespace System {
 
                public string ToString (string format, IFormatProvider fp)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, fp);
                }
 
                // =========== IConvertible Methods =========== //
index 6ee7afb4f443e5bd91664310b084aec6a742e583..1a2ae351c30427f3e809a4c29e92bb91e1b03f8f 100644 (file)
@@ -641,6 +641,9 @@ namespace System
 
                private MethodBase CheckMethodSecurity (MethodBase mb)
                {
+#if NET_2_1
+                       return mb;
+#else
                        if (!SecurityManager.SecurityEnabled || (mb == null))
                                return mb;
 
@@ -651,6 +654,7 @@ namespace System
 
                        // this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
                        return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
+#endif
                }
 
                void ReorderParamArrayArguments(ref object[] args, MethodBase method)
index 56cf09f3363a5d605019f3e5f35ea0ba9afa4fd2..90dec6c3734187705f627672ca2d1d2e7083e9fa 100644 (file)
@@ -5,28 +5,43 @@
 //   Kazuki Oikawa (kazuki@panicode.com)
 //   Eyal Alaluf (eyala@mainsoft.com)
 //
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2008 Mainsoft Co. (http://www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
-// NumberFormatter is shared with Grasshopper and hence the #if TARGET_JVM
-// The differentiating issues are:
-//   * Mono runs faster when NumberFormatter is a struct. Grasshopper (and .Net
-//     for that matter) run faster when its a class.
-//   * No support for unsafe code in Grasshopper.
+// NumberFormatter is shared with Grasshopper and hence the #if TARGET_JVM for
+// marking the use of unsafe code that is not supported in Grasshopper.
 #if !TARGET_JVM
-#define STRUCT
 #define UNSAFE_TABLES
 #endif
 
 using System.Globalization;
 using System.Text;
+using System.Threading;
 using System.Runtime.CompilerServices;
 
 namespace System
 {
-#if STRUCT
-       internal partial struct NumberFormatter
-#else
        internal sealed partial class NumberFormatter
-#endif
        {
                #region Static Fields
 
@@ -91,17 +106,20 @@ namespace System
 
                #region Fields
 
-               private readonly bool _NaN;
-               private readonly bool _infinity;
-               private readonly bool _isCustomFormat;
-               private readonly bool _specifierIsUpper;
-               private readonly char _specifier;
-               private readonly sbyte _precision;
-               private readonly sbyte _defPrecision;
+               private Thread _thread;
+               private NumberFormatInfo _nfi;
 
+               private bool _NaN;
+               private bool _infinity;
+               private bool _isCustomFormat;
+               private bool _specifierIsUpper;
                private bool _positive;
-               private sbyte _digitsLen;
-               private sbyte _offset; // Represent the first digit offset.
+               private char _specifier;
+               private int _precision;
+               private int _defPrecision;
+
+               private int _digitsLen;
+               private int _offset; // Represent the first digit offset.
                private int _decPointPos;
 
                // The following fields are a hexadeimal representation of the digits.
@@ -120,9 +138,9 @@ namespace System
                private void InitDecHexDigits (uint value)
                {
                        if (value >= HundredMillion) {
-                               uint div1 = value / HundredMillion;
-                               value = value - HundredMillion * div1;
-                               _val2 = ToDecHex ((int)div1);
+                               int div1 = (int)(value / HundredMillion);
+                               value -= HundredMillion * (uint)div1;
+                               _val2 = FastToDecHex (div1);
                        }
                        _val1 = ToDecHex ((int)value);
                }
@@ -132,7 +150,7 @@ namespace System
                {
                        if (value >= HundredMillion) {
                                long div1 = (long)(value / HundredMillion);
-                               value = value - HundredMillion * (ulong)div1;
+                               value -= HundredMillion * (ulong)div1;
                                if (div1 >= HundredMillion) {
                                        int div2 = (int)(div1 / HundredMillion);
                                        div1 = div1 - div2 * (long)HundredMillion;
@@ -195,29 +213,27 @@ namespace System
 #if UNSAFE_TABLES
                unsafe
 #endif
-               private static int FastToDecHex (int val)
+               private static uint FastToDecHex (int val)
                {
-                       int res = 0;
-                       if (val >= 100) {
-                               // Uses 2^19 (524288) to compute val / 100 for val < 10000.
-                               int v = (val * 5243) >> 19;
-                               val -= v * 100;
-                               res = DecHexDigits [v] << 8;
-                       }
-                       return res | DecHexDigits [val];
+                       if (val < 100)
+                               return (uint)DecHexDigits [val];
+
+                       // Uses 2^19 (524288) to compute val / 100 for val < 10000.
+                       int v = (val * 5243) >> 19;
+                       return (uint)((DecHexDigits [v] << 8) | DecHexDigits [val - v * 100]);
                }
 
                // Helper to translate an int in the range 0 .. 99999999 to its
                // Hexadecimal digits representation.
                private static uint ToDecHex (int val)
                {
-                       int res = 0;
+                       uint res = 0;
                        if (val >= 10000) {
                                int v = val / 10000;
                                val -= v * 10000;
                                res = FastToDecHex (v) << 16;
                        }
-                       return (uint)(res | FastToDecHex (val));
+                       return res | FastToDecHex (val);
                }
 
                // Helper to count number of hexadecimal digits in a number.
@@ -236,26 +252,24 @@ namespace System
 
                private static int DecHexLen (uint val)
                {
-                       int v = (int)val;
-                       if (v < 0)
-                               return 8;
-                       if (v < 0x10000)
-                               return FastDecHexLen (v);
-                       return 4 + FastDecHexLen (v >> 16);
+                       if (val < 0x10000)
+                               return FastDecHexLen ((int)val);
+                       return 4 + FastDecHexLen ((int)(val >> 16));
                }
 
                // Count number of hexadecimal digits stored in _val1 .. _val4.
-               private sbyte DecHexLen ()
+               private int DecHexLen ()
                {
                        if (_val4 != 0)
-                               return (sbyte)(DecHexLen (_val4) + 24);
-                       if (_val3 != 0)
-                               return (sbyte)(DecHexLen (_val3) + 16);
-                       if (_val2 != 0)
-                               return (sbyte)(DecHexLen (_val2) + 8);
-                       if (_val1 != 0)
-                               return (sbyte)DecHexLen (_val1);
-                       return 0;
+                               return DecHexLen (_val4) + 24;
+                       else if (_val3 != 0)
+                               return DecHexLen (_val3) + 16;
+                       else if (_val2 != 0)
+                               return DecHexLen (_val2) + 8;
+                       else if (_val1 != 0)
+                               return DecHexLen (_val1);
+                       else
+                               return 0;
                }
 
                // Helper to count the 10th scale (number of digits) in a number
@@ -303,21 +317,24 @@ namespace System
 
                // Parse the given format and initialize the following fields:
                //   _isCustomFormat, _specifierIsUpper, _specifier & _precision.
-               private NumberFormatter (string format)
+               public NumberFormatter (Thread current)
+               {
+                       _cbuf = new char [0];
+                       if (current == null)
+                               return;
+                       _thread = current;
+                       CurrentCulture = _thread.CurrentCulture;
+               }
+
+               private void Init (string format)
                {
-#if STRUCT
-                       // Init all fields when using a struct.
                        _val1 = _val2 = _val3 = _val4 = 0;
-                       _defPrecision = 0;
                        _offset = 0;
-                       _decPointPos = _digitsLen = 0;
-                       _positive = _NaN = _infinity = false;
-                       _cbuf = null;
-                       _ind = 0;
-#endif
+                       _NaN = _infinity = false;
                        _isCustomFormat = false;
                        _specifierIsUpper = true;
                        _precision = -1;
+
                        if (format == null || format.Length == 0) {
                                _specifier = 'G';
                                return;
@@ -335,7 +352,7 @@ namespace System
                        }
                        _specifier = specifier;
                        if (format.Length > 1) {
-                               _precision = (sbyte)ParsePrecision (format);
+                               _precision = ParsePrecision (format);
                                if (_precision == -2) { // Is it a custom format?
                                        _isCustomFormat = true;
                                        _specifier = '0';
@@ -344,76 +361,45 @@ namespace System
                        }
                }
 
-               public NumberFormatter (string format, sbyte value)
-                       : this (format, (int)value)
-               {
-                       _defPrecision = Int8DefPrecision;
-                       if (_specifier == 'X' && value < 0) {
-                               _val1 = (byte)value;
-                               _decPointPos = _digitsLen = 2;
-                               return;
-                       }
-               }
-
-               public NumberFormatter (string format, byte value)
-                       : this (format, (uint)value)
-               {
-                       _defPrecision = UInt8DefPrecision;
-               }
-
-               public NumberFormatter (string format, short value)
-                       : this (format, (int)value)
+               private void InitHex (ulong value)
                {
-                       _defPrecision = Int16DefPrecision;
-                       if (_specifier == 'X' && value < 0) {
-                               _val1 = (ushort)value;
-                               _decPointPos = _digitsLen = 4;
-                               return;
+                       switch (_defPrecision) {
+                               case Int8DefPrecision:  value = (byte) value;    break;
+                               case Int16DefPrecision: value = (ushort) value;  break;
+                               case Int32DefPrecision: value = (uint) value;    break;
                        }
+                       _val1 = (uint)value;
+                       _val2 = (uint)(value >> 32);
+                       _decPointPos = _digitsLen = DecHexLen ();
+                       if (value == 0)
+                               _decPointPos = 1;
                }
 
-               public NumberFormatter (string format, ushort value)
-                       : this (format, (uint)value)
-               {
-                       _defPrecision = UInt16DefPrecision;
-               }
-
-               public NumberFormatter (string format, int value)
-                       : this (format)
+               private void Init (string format, int value, int defPrecision)
                {
-                       _defPrecision = Int32DefPrecision;
+                       Init (format);
+                       _defPrecision = defPrecision;
                        _positive = value >= 0;
 
-                       if (value == 0) {
-                               _decPointPos = 1;
-                               return;
-                       }
-                       if (_specifier == 'X') {
-                               _val1 = (uint)value;
-                               _decPointPos = _digitsLen = DecHexLen ();
+                       if (value == 0 || _specifier == 'X') {
+                               InitHex ((ulong)value);
                                return;
                        }
 
                        if (value < 0)
                                value = -value;
-
                        InitDecHexDigits ((uint)value);
                        _decPointPos = _digitsLen = DecHexLen ();
                }
 
-               public NumberFormatter (string format, uint value)
-                       : this (format)
+               private void Init (string format, uint value, int defPrecision)
                {
-                       _defPrecision = UInt32DefPrecision;
+                       Init (format);
+                       _defPrecision = defPrecision;
                        _positive = true;
 
-                       if (value == 0) {
-                               _decPointPos = 1;
-                               return;
-                       }
-                       if (_specifier == 'X') {
-                               _val1 = value;
-                               _decPointPos = _digitsLen = DecHexLen ();
+                       if (value == 0 || _specifier == 'X') {
+                               InitHex (value);
                                return;
                        }
 
@@ -421,44 +407,31 @@ namespace System
                        _decPointPos = _digitsLen = DecHexLen ();
                }
 
-               public NumberFormatter (string format, long value)
-                       : this (format)
+               private void Init (string format, long value)
                {
+                       Init (format);
                        _defPrecision = Int64DefPrecision;
                        _positive = value >= 0;
 
-                       if (value == 0) {
-                               _decPointPos = 1;
-                               return;
-                       }
-                       if (_specifier == 'X') {
-                               _val1 = (uint)value;
-                               _val2 = (uint)(value >> 32);
-                               _decPointPos = _digitsLen = DecHexLen ();
+                       if (value == 0 || _specifier == 'X') {
+                               InitHex ((ulong)value);
                                return;
                        }
 
                        if (value < 0)
                                value = -value;
-
                        InitDecHexDigits ((ulong)value);
                        _decPointPos = _digitsLen = DecHexLen ();
                }
 
-               public NumberFormatter (string format, ulong value)
-                       : this (format)
+               private void Init (string format, ulong value)
                {
+                       Init (format);
                        _defPrecision = UInt64DefPrecision;
                        _positive = true;
 
-                       if (value == 0) {
-                               _decPointPos = 1;
-                               return;
-                       }
-                       if (_specifier == 'X') {
-                               _val1 = (uint)value;
-                               _val2 = (uint)(value >> 32);
-                               _decPointPos = _digitsLen = DecHexLen ();
+                       if (value == 0 || _specifier == 'X') {
+                               InitHex ((ulong)value);
                                return;
                        }
 
@@ -466,30 +439,20 @@ namespace System
                        _decPointPos = _digitsLen = DecHexLen ();
                }
 
-               public NumberFormatter (string format, float value)
-                       : this (format, value, SingleDefPrecision)
-               {
-               }
-
-               public NumberFormatter (string format, double value)
-                       : this (format, value, DoubleDefPrecision)
-               {
-               }
-
 #if UNSAFE_TABLES // No unsafe code under TARGET_JVM
                unsafe
 #endif
-               public NumberFormatter (string format, double value, sbyte defPrecision)
-                       : this (format)
+               private void Init (string format, double value, int defPrecision)
                {
-                       _defPrecision = defPrecision;
+                       Init (format);
 
-                       // Double to bits
+                       _defPrecision = defPrecision;
                        long bits = BitConverter.DoubleToInt64Bits (value);
                        _positive = bits >= 0;
                        bits &= Int64.MaxValue;
                        if (bits == 0) {
                                _decPointPos = 1;
+                               _digitsLen = 0;
                                _positive = true;
                                return;
                        }
@@ -549,14 +512,13 @@ namespace System
                        }
 
                        InitDecHexDigits ((ulong)res);
-                       _offset = (sbyte)CountTrailingZeros ();
-                       _digitsLen = (sbyte)(order - _offset);
+                       _offset = CountTrailingZeros ();
+                       _digitsLen = order - _offset;
                }
 
-               public NumberFormatter (string format, decimal value)
-                       : this (format)
+               private void Init (string format, decimal value)
                {
-                       _infinity = _NaN = false;
+                       Init (format);
                        _defPrecision = DecimalDefPrecision;
 
                        int[] bits = decimal.GetBits (value);
@@ -565,12 +527,17 @@ namespace System
                        if (bits [0] == 0 && bits [1] == 0 && bits [2] == 0) {
                                _decPointPos = -scale;
                                _positive = true;
+                               _digitsLen = 0;
                                return;
                        }
 
                        InitDecHexDigits ((uint)bits [2], ((ulong)bits [1] << 32) | (uint)bits [0]);
                        _digitsLen = DecHexLen ();
                        _decPointPos = _digitsLen - scale;
+                       if (_precision != -1 || _specifier != 'G') {
+                               _offset = CountTrailingZeros ();
+                               _digitsLen -= _offset;
+                       }
                }
 
                #endregion Constructors
@@ -582,9 +549,9 @@ namespace System
 
                private void ResetCharBuf (int size)
                {
-                       if (_cbuf == null || _cbuf.Length < size)
-                               _cbuf = new char [size];
                        _ind = 0;
+                       if (_cbuf.Length < size)
+                               _cbuf = new char [size];
                }
 
                private void Resize (int len)
@@ -622,6 +589,22 @@ namespace System
 
                #region Helper properties
 
+               private NumberFormatInfo GetNumberFormatInstance (IFormatProvider fp)
+               {
+                       if (_nfi != null && fp == null)
+                               return _nfi;
+                       return NumberFormatInfo.GetInstance (fp);
+               }
+
+               public CultureInfo CurrentCulture {
+                       set {
+                               if (value != null && value.IsReadOnly)
+                                       _nfi = value.NumberFormat;
+                               else
+                                       _nfi = null;
+                       }
+               }
+
                private int IntegerDigits {
                        get { return _decPointPos > 0 ? _decPointPos : 1; }
                }
@@ -630,18 +613,10 @@ namespace System
                        get { return _digitsLen > _decPointPos ? _digitsLen - _decPointPos : 0; }
                }
 
-               private bool IsIntegerSource {
-                       get { return _defPrecision < 30 && _defPrecision != DoubleDefPrecision && _defPrecision != SingleDefPrecision; }
-               }
-
                private bool IsFloatingSource {
                        get { return _defPrecision == DoubleDefPrecision || _defPrecision == SingleDefPrecision; }
                }
 
-               private bool IsDecimalSource {
-                       get { return _defPrecision > 30; }
-               }
-
                private bool IsZero {
                        get { return _digitsLen == 0; }
                }
@@ -666,13 +641,8 @@ namespace System
 
                private bool RoundBits (int shift)
                {
-                       if (shift <= 0) {
-                               if (IsDecimalSource) {
-                                       _digitsLen += _offset;
-                                       RemoveTrailingZeros ();
-                               }
+                       if (shift <= 0)
                                return false;
-                       }
 
                        if (shift > _digitsLen) {
                                _digitsLen = 0;
@@ -699,7 +669,7 @@ namespace System
                        if (rem16 >= 0x5) {
                                _val1 |= 0x99999999 >> (28 - shift);
                                AddOneToDecHex ();
-                               sbyte newlen = DecHexLen ();
+                               int newlen = DecHexLen ();
                                res = newlen != _digitsLen;
                                _decPointPos = _decPointPos + newlen - _digitsLen;
                                _digitsLen = newlen;
@@ -710,7 +680,7 @@ namespace System
 
                private void RemoveTrailingZeros ()
                {
-                       _offset = (sbyte)CountTrailingZeros ();
+                       _offset = CountTrailingZeros ();
                        _digitsLen -= _offset;
                        if (_digitsLen == 0) {
                                _offset = 0;
@@ -803,94 +773,257 @@ namespace System
 
                #region public number formatting methods
 
-               public static string NumberToString (string format, sbyte value, NumberFormatInfo nfi)
+               private static NumberFormatter GetInstance()
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       return Thread.CurrentThread.AcquireNumberFormatter();
                }
 
-               public static string NumberToString (string format, byte value, NumberFormatInfo nfi)
+               private void Release()
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       _thread.ReleaseNumberFormatter (this);
                }
 
-               public static string NumberToString (string format, ushort value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, sbyte value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, Int8DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, short value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, byte value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, UInt8DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, uint value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, ushort value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, Int16DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, int value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, short value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, UInt16DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, ulong value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, uint value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, Int32DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, long value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, int value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, UInt32DefPrecision);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, float value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, ulong value, IFormatProvider fp)
                {
-                       NumberFormatter rep = new NumberFormatter (format, value);
-                       if (rep._specifier == 'R')
-                               return rep.FormatRoundtrip (value, nfi);
-                       return rep.NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, double value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, long value, IFormatProvider fp)
                {
-                       NumberFormatter rep = new NumberFormatter (format, value);
-                       if (rep._specifier == 'R')
-                               return rep.FormatRoundtrip (value, nfi);
-                       return rep.NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value);
+                       string res = inst.IntegerToString (format, fp);
+                       inst.Release();
+                       return res;
                }
 
-               public static string NumberToString (string format, decimal value, NumberFormatInfo nfi)
+               public static string NumberToString (string format, float value, IFormatProvider fp)
                {
-                       return new NumberFormatter (format, value).NumberToString (format, nfi);
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, SingleDefPrecision);
+                       NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+                       string res;
+                       if (inst._NaN)
+                               res = nfi.NaNSymbol;
+                       else if (inst._infinity)
+                               if (inst._positive)
+                                       res = nfi.PositiveInfinitySymbol;
+                               else
+                                       res = nfi.NegativeInfinitySymbol;
+                       else if (inst._specifier == 'R')
+                               res = inst.FormatRoundtrip (value, nfi);
+                       else
+                               res = inst.NumberToString (format, nfi);
+                       inst.Release();
+                       return res;
                }
 
-               public string NumberToString (string format, NumberFormatInfo nfi)
+               public static string NumberToString (string format, double value, IFormatProvider fp)
                {
-                       if (IsFloatingSource) {
-                               if (_NaN)
-                                       return nfi.NaNSymbol;
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value, DoubleDefPrecision);
+                       NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+                       string res;
+                       if (inst._NaN)
+                               res = nfi.NaNSymbol;
+                       else if (inst._infinity)
+                               if (inst._positive)
+                                       res = nfi.PositiveInfinitySymbol;
+                               else
+                                       res = nfi.NegativeInfinitySymbol;
+                       else if (inst._specifier == 'R')
+                               res = inst.FormatRoundtrip (value, nfi);
+                       else
+                               res = inst.NumberToString (format, nfi);
+                       inst.Release();
+                       return res;
+               }
 
-                               if (_infinity) {
-                                       if (_positive)
-                                               return nfi.PositiveInfinitySymbol;
-                                       else
-                                               return nfi.NegativeInfinitySymbol;
-                               }
+               public static string NumberToString (string format, decimal value, IFormatProvider fp)
+               {
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (format, value);
+                       string res = inst.NumberToString (format, inst.GetNumberFormatInstance (fp));
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (uint value, IFormatProvider fp)
+               {
+                       if (value >= HundredMillion)
+                               return NumberToString (null, value, fp);
+
+                       NumberFormatter inst = GetInstance();
+                       string res = inst.FastIntegerToString ((int)value, fp);
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (int value, IFormatProvider fp)
+               {
+                       if (value >= HundredMillion || value <= -HundredMillion)
+                               return NumberToString (null, value, fp);
+
+                       NumberFormatter inst = GetInstance();
+                       string res = inst.FastIntegerToString (value, fp);
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (ulong value, IFormatProvider fp)
+               {
+                       if (value >= HundredMillion)
+                               return NumberToString (null, value, fp);
+
+                       NumberFormatter inst = GetInstance();
+                       string res = inst.FastIntegerToString ((int)value, fp);
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (long value, IFormatProvider fp)
+               {
+                       if (value >= HundredMillion || value <= -HundredMillion)
+                               return NumberToString (null, value, fp);
+
+                       NumberFormatter inst = GetInstance();
+                       string res = inst.FastIntegerToString ((int)value, fp);
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (float value, IFormatProvider fp)
+               {
+                       NumberFormatter inst = GetInstance();
+                       inst.Init (null, value, SingleDefPrecision);
+                       NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+                       string res;
+                       if (inst._NaN)
+                               res = nfi.NaNSymbol;
+                       else if (inst._infinity)
+                               if (inst._positive)
+                                       res = nfi.PositiveInfinitySymbol;
+                               else
+                                       res = nfi.NegativeInfinitySymbol;
+                       else
+                               res = inst.FormatGeneral (-1, nfi);
+                       inst.Release();
+                       return res;
+               }
+
+               public static string NumberToString (double value, IFormatProvider fp)
+               {
+                       NumberFormatter inst = GetInstance();
+                       NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+                       inst.Init (null, value, DoubleDefPrecision);
+                       string res;
+                       if (inst._NaN)
+                               res = nfi.NaNSymbol;
+                       else if (inst._infinity)
+                               if (inst._positive)
+                                       res = nfi.PositiveInfinitySymbol;
+                               else
+                                       res = nfi.NegativeInfinitySymbol;
+                       else
+                               res = inst.FormatGeneral (-1, nfi);
+                       inst.Release();
+                       return res;
+               }
+
+               private string FastIntegerToString (int value, IFormatProvider fp)
+               {
+                       if (value < 0) {
+                               string sign = GetNumberFormatInstance(fp).NegativeSign;
+                               ResetCharBuf (8 + sign.Length);
+                               value = -value;
+                               Append (sign);
+                       }
+                       else
+                               ResetCharBuf (8);
+
+                       if (value >= 10000) {
+                               int v = value / 10000;
+                               FastAppendDigits (v, false);
+                               FastAppendDigits (value - v * 10000, true);
                        }
+                       else
+                               FastAppendDigits (value, false);
 
+                       return new string (_cbuf, 0, _ind);
+               }
+
+               private string IntegerToString (string format, IFormatProvider fp)
+               {
+                       NumberFormatInfo nfi = GetNumberFormatInstance (fp);
                        switch (_specifier) {
                        case 'C':
                                return FormatCurrency (_precision, nfi);
                        case 'D':
-                               if (IsIntegerSource)
-                                       return FormatDecimal (_precision, nfi);
-                               throw new FormatException ();
+                               return FormatDecimal (_precision, nfi);
                        case 'E':
                                return FormatExponential (_precision, nfi);
                        case 'F':
                                return FormatFixedPoint (_precision, nfi);
                        case 'G':
-                               if (IsIntegerSource && _precision <= 0)
+                               if (_precision <= 0)
                                        return FormatDecimal (-1, nfi);
                                return FormatGeneral (_precision, nfi);
                        case 'N':
@@ -898,11 +1031,30 @@ namespace System
                        case 'P':
                                return FormatPercent (_precision, nfi);
                        case 'X':
-                               if (IsIntegerSource)
-                                       return FormatHexadecimal (_precision);
-                               throw new FormatException ("The specified format cannot be used in this instance");
-                       case 'R':
-                               throw new FormatException ("The specified format cannot be used in this instance");
+                               return FormatHexadecimal (_precision);
+                       default:
+                               if (_isCustomFormat)
+                                       return FormatCustom (format, nfi);
+                               throw new FormatException ("The specified format '" + format + "' is invalid");
+                       }
+               }
+
+               private string NumberToString (string format, NumberFormatInfo nfi)
+               {
+                       switch (_specifier) {
+                       case 'C':
+                               return FormatCurrency (_precision, nfi);
+                       case 'E':
+                               return FormatExponential (_precision, nfi);
+                       case 'F':
+                               return FormatFixedPoint (_precision, nfi);
+                       case 'G':
+                               return FormatGeneral (_precision, nfi);
+                       case 'N':
+                               return FormatNumber (_precision, nfi);
+                       case 'P':
+                               return FormatPercent (_precision, nfi);
+                       case 'X':
                        default:
                                if (_isCustomFormat)
                                        return FormatCustom (format, nfi);
@@ -1050,7 +1202,7 @@ namespace System
                        return new string (_cbuf, 0, _ind);
                }
 
-               public string FormatDecimal (int precision, NumberFormatInfo nfi)
+               private string FormatDecimal (int precision, NumberFormatInfo nfi)
                {
                        if (precision < _digitsLen)
                                precision = _digitsLen;
@@ -1058,12 +1210,8 @@ namespace System
                                return "0";
 
                        ResetCharBuf (precision + 1);
-                       if (!_positive) {
-                               if (nfi == null)
-                                       nfi = NumberFormatInfo.GetInstance (null);
-
+                       if (!_positive)
                                Append (nfi.NegativeSign);
-                       }
                        AppendDigits (0, precision);
 
                        return new string (_cbuf, 0, _ind);
@@ -1072,7 +1220,7 @@ namespace System
 #if UNSAFE_TABLES // No unsafe code under TARGET_JVM
                unsafe
 #endif
-               public string FormatHexadecimal (int precision)
+               private string FormatHexadecimal (int precision)
                {
                        int size = Math.Max (precision, _decPointPos);
 #if UNSAFE_TABLES
@@ -1112,17 +1260,8 @@ namespace System
                        return new string (_cbuf, 0, _ind);
                }
 
-               public string FormatRoundtrip (double origval, NumberFormatInfo nfi)
+               private string FormatRoundtrip (double origval, NumberFormatInfo nfi)
                {
-                       if (_NaN)
-                               return nfi.NaNSymbol;
-
-                       if (_infinity)
-                               if (_positive)
-                                       return nfi.PositiveInfinitySymbol;
-                               else
-                                       return nfi.NegativeInfinitySymbol;
-
                        NumberFormatter nfc = GetClone ();
                        if (origval >= MinRoundtripVal && origval <= MaxRoundtripVal) {
                                string shortRep = FormatGeneral (_defPrecision, nfi);
@@ -1132,17 +1271,8 @@ namespace System
                        return nfc.FormatGeneral (_defPrecision + 2, nfi);
                }
 
-               public string FormatRoundtrip (float origval, NumberFormatInfo nfi)
+               private string FormatRoundtrip (float origval, NumberFormatInfo nfi)
                {
-                       if (_NaN)
-                               return nfi.NaNSymbol;
-
-                       if (_infinity)
-                               if (_positive)
-                                       return nfi.PositiveInfinitySymbol;
-                               else
-                                       return nfi.NegativeInfinitySymbol;
-
                        NumberFormatter nfc = GetClone ();
                        string shortRep = FormatGeneral (_defPrecision, nfi);
                        // Check roundtrip only for "normal" double values.
@@ -1151,20 +1281,6 @@ namespace System
                        return nfc.FormatGeneral (_defPrecision + 2, nfi);
                }
 
-               public string FormatGeneral (NumberFormatInfo nfi)
-               {
-                       if (_NaN)
-                               return nfi.NaNSymbol;
-
-                       if (_infinity)
-                               if (_positive)
-                                       return nfi.PositiveInfinitySymbol;
-                               else
-                                       return nfi.NegativeInfinitySymbol;
-
-                       return FormatGeneral (-1, nfi);
-               }
-
                private string FormatGeneral (int precision, NumberFormatInfo nfi)
                {
                        bool enableExp;
@@ -1595,7 +1711,7 @@ namespace System
                                Append ((char)('0' | exponent));
                        }
                        else {
-                               int hexDigit = FastToDecHex (exponent);
+                               uint hexDigit = FastToDecHex (exponent);
                                if (exponent >= 100 || minDigits == 3)
                                        Append ((char)('0' | (hexDigit >> 8)));
                                Append ((char)('0' | ((hexDigit >> 4) & 0xf)));
@@ -1626,6 +1742,30 @@ namespace System
                        _cbuf [_ind++] = (char)('0' | v & 0xf);
                }
 
+#if UNSAFE_TABLES // No unsafe code under TARGET_JVM
+               unsafe
+#endif
+               private void FastAppendDigits (int val, bool force)
+               {
+                       int i = _ind;
+                       int digits;
+                       if (force || val >= 100) {
+                               int v = (val * 5243) >> 19;
+                               digits = DecHexDigits [v];
+                               if (force || val >= 1000)
+                                       _cbuf [i++] = (char)('0' | digits >> 4);
+                               _cbuf [i++] = (char)('0' | (digits & 0xf));
+                               digits = DecHexDigits [val - v * 100];
+                       }
+                       else
+                               digits = DecHexDigits [val];
+
+                       if (force || val >= 10)
+                               _cbuf [i++] = (char)('0' | digits >> 4);
+                       _cbuf [i++] = (char)('0' | (digits & 0xf));
+                       _ind = i;
+               }
+
                private void AppendDigits (int start, int end)
                {
                        if (start >= end)
index 3a6eaaaea0b4542f9ec62bdad517d808effcf10a..1e71ffe344fa50a5ba2465f6673240cdb0e1bf03 100644 (file)
@@ -1,16 +1,39 @@
+//\r
+// System.NumberFormatter.cs\r
+//\r
+// Author:\r
+//   Eyal Alaluf (eyala@mainsoft.com)\r
+//\r
+// Copyright (C) 2008 Mainsoft Co. (http://www.mainsoft.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
 #if !TARGET_JVM\r
 #define UNSAFE_TABLES\r
-#define STRUCT\r
 #endif\r
 \r
-namespace System2\r
+namespace System\r
 {\r
 #if !UNSAFE_TABLES\r
-#if STRUCT\r
-       partial struct NumberFormatter\r
-#else\r
        partial class NumberFormatter\r
-#endif\r
        {\r
                static internal readonly char[] DigitLowerTable = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };\r
                static internal readonly char[] DigitUpperTable = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
@@ -992,4 +1015,4 @@ namespace System2
 #endif\r
        }\r
 }\r
-#endif\r
+#endif // !UNSAFE_TABLES\r
index 350d93c50660136f51530817ff43010c03ce2220..4741d20bf549cf4defff0401843b113248cd1298 100644 (file)
@@ -245,13 +245,12 @@ namespace System
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -261,8 +260,7 @@ namespace System
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== ICovnertible Methods =========== //
index 67cc7021ea6914796b47bedf06d34ebeda3c3fb4..0c6387d1d430aef756e380ce8c1a803dfaa2251a 100644 (file)
@@ -233,14 +233,12 @@ namespace System
 #endif
                public override string ToString ()
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (null);
-                       return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -250,8 +248,7 @@ namespace System
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // ============= IConvertible Methods ============ //
index b6cd5e7a8653db857671a5feba83c62514f4c36d..d5f183bf10bb039a1c01029724b1aac17115e684 100644 (file)
@@ -375,17 +375,16 @@ namespace System
                                sb.Append ('.');
                        }
 
-                       System.Globalization.NumberFormatInfo nfi = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
-                       sb.Append (new NumberFormatter (null, (int)Math.Abs (Hours)).FormatDecimal(2, nfi));
+                       sb.Append (Math.Abs (Hours).ToString ("D2"));
                        sb.Append (':');
-                       sb.Append (new NumberFormatter (null, (int)Math.Abs (Minutes)).FormatDecimal(2, nfi));
+                       sb.Append (Math.Abs (Minutes).ToString ("D2"));
                        sb.Append (':');
-                       sb.Append (new NumberFormatter (null, (int)Math.Abs (Seconds)).FormatDecimal(2, nfi));
+                       sb.Append (Math.Abs (Seconds).ToString ("D2"));
 
                        int fractional = (int) Math.Abs (_ticks % TicksPerSecond);
                        if (fractional != 0) {
                                sb.Append ('.');
-                               sb.Append (new NumberFormatter (null, (int)Math.Abs (fractional)).FormatDecimal(7, nfi));
+                               sb.Append (fractional.ToString ("D7"));
                        }
 
                        return sb.ToString ();
index 3d53bb89405f00ce40389b889faa70e35c9cee2b..ee8e0a29104f7a82b95a9b5cb81e50d278f04164 100644 (file)
@@ -142,13 +142,12 @@ namespace System
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -158,8 +157,7 @@ namespace System
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== IConvertible Methods =========== //
index a0bb1ef2813ac73e23229a5e8c93325a4d97446f..553c76af586bdbd9c202252cd663fd6c5d63e312 100644 (file)
@@ -460,13 +460,12 @@ namespace System
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -476,8 +475,7 @@ namespace System
 
                public string ToString (string format, IFormatProvider fp)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (fp);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, fp);
                }
 
                // =========== IConvertible Methods =========== //
index 1d98e1e4cf1031d14301bbfc08e7b5bc2cd476d0..f7de7238fbe6d238ad1ddfdff97a77a19f4a1ff8 100644 (file)
@@ -383,13 +383,12 @@ namespace System
 
                public override string ToString ()
                {
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
                public string ToString (IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -399,8 +398,7 @@ namespace System
 
                public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== IConvertible Methods =========== //
index 57d44e7a5a525c1ab0f79a0ef257479044e3e708..4322b2d91c6a4264d2ef2c9f6a6970e785e534ae 100644 (file)
@@ -1,3 +1,7 @@
+2008-04-01  Eyal Alaluf <eyala@mainsoft.com>
+
+       * NumberFormatterTest.cs: Test (-0.0).ToString.
+
 2008-03-06  Zoltan Varga  <vargaz@gmail.com>
 
        * TypeTest.cs (PublicKeyToken): Add a test for #367670.
index dbe2c7a42d863a45c9ca4e87a0250516e8aad400..c5ebca0291009ef06fb56710976518b4bd1c742d 100644 (file)
@@ -3291,6 +3291,7 @@ namespace MonoTests.System
                public void Test13000 ()\r
                {\r
                        AssertEquals ("#01", "0", 0.0.ToString ("G", _nfi));\r
+                       AssertEquals ("#01.1", "0", (-0.0).ToString ("G", _nfi));\r
                        AssertEquals ("#02", "0", 0.0.ToString ("g", _nfi));\r
                        AssertEquals ("#03", "-1.79769313486232E+308", Double.MinValue.ToString ("G", _nfi));\r
                        AssertEquals ("#04", "-1.79769313486232e+308", Double.MinValue.ToString ("g", _nfi));\r
index f6b37a7b96074a3dda37eedd066b6dda72777e58..7fe59487e15017db3df586fcaa7207c326b50111 100644 (file)
@@ -1,6 +1,6 @@
 \r
 Microsoft Visual Studio Solution File, Format Version 10.00\r
-# Visual C# Express Codename Orcas\r
+# Visual C# Express 2008\r
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gmcs", "gmcs.csproj", "{D4A01C5B-A1B5-48F5-BB5B-D2E1BD236E56}"\r
 EndProject\r
 Global\r