So, I have done a unit test (and run it on linux but not on windows) and fix
some bug thanks to it ;)
If someone can test it under the MS framework.
So here is a new patch with unit test and modified class. I have truncate
the patch to remove my other changes. So maybe it will not work. If you have
issue to patch with it mail me and I will try to make a new one.

cheers,
Olivier

2007/11/30, Gert Driesen <[EMAIL PROTECTED]>:
>
> Olivier,
>
> As you mention in your patch, you need unit tests to verify whether the
> behavior matches the MS implementation.
>
> I suggest submitting a bug report, and attaching the current patch before
> continueing working on it.
>
> Thay way the patch will not get lost in all the "noise" ...
>
> Gert
> ----- Original Message -----
> From: "olivier dufour" <[EMAIL PROTECTED]>
> To: <mono-devel-list@lists.ximian.com>
> Sent: Friday, November 30, 2007 7:45 AM
> Subject: [Mono-dev] patch winform resource reader
>
>
> > OK, I have done a small part at work. So I have forget to change the
> > convention on it.
> > I have attach the fixed patch.
> >
> >
> > 2007/11/30, Jb Evain <[EMAIL PROTECTED] >:
> >>
> >> Hey,
> >>
> >> On 11/30/07, olivier dufour < [EMAIL PROTECTED]> wrote:
> >> > Can someone check it before I commit.
> >>
> >> Please do not commit this as it is. The code:
> >>
> >> * doesn't respect the Mono coding conventions,
> >> * mixes spaces and tabs all over the place.
> >>
> >> --
> >> Jb Evain  <[EMAIL PROTECTED]>
> >>
> >
>
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >
>
>
Index: Test/System.Resources/ResXResourceReaderTest.cs
===================================================================
--- Test/System.Resources/ResXResourceReaderTest.cs     (révision 90518)
+++ Test/System.Resources/ResXResourceReaderTest.cs     (copie de travail)
@@ -1472,7 +1472,61 @@
                        }
                }
 
+
+               
                [Test]
+               public void useResXDataNodes ()
+               {
+                       string refFile = Path.Combine (_tempDirectory, 
"32x32.ico");
+                       WriteEmbeddedResource ("32x32.ico", refFile);
+
+                       string resxFile = Path.Combine (_tempDirectory, 
"resources.resx");
+                       using (StreamWriter sw = new StreamWriter (resxFile, 
false, Encoding.UTF8)) {
+                               sw.Write (string.Format 
(CultureInfo.InvariantCulture,
+                                       _resXFileRefTemplate, 
ResXResourceWriter.ResMimeType, "1.0",
+                                       Consts.AssemblySystem_Windows_Forms, 
refFile,
+                                       typeof (Bitmap).AssemblyQualifiedName, 
string.Empty));
+                       }
+
+                       using (ResXResourceReader r = new ResXResourceReader 
(resxFile)) {
+                               r.UseResXDataNodes = true;
+                               IDictionaryEnumerator enumerator = 
r.GetEnumerator ();
+                               enumerator.MoveNext ();
+                               Assert.IsNotNull (enumerator.Current, "#A1");
+                               Assert.AreEqual ("foo", enumerator.Key, "#A2");
+                               ResXDataNode node = enumerator.Value as 
ResXDataNode;
+                               Assert.IsNotNull (node, "#A3");
+                               Assert.AreEqual ("foo", node.Name, "#A4");
+                       }
+               }
+               //TODO assemblyNames
+
+               [Test]
+               public void GetMetadataEnumerator ()
+               {
+                       string refFile = Path.Combine (_tempDirectory, 
"32x32.ico");
+                       WriteEmbeddedResource ("32x32.ico", refFile);
+
+                       string resxFile = Path.Combine (_tempDirectory, 
"resources.resx");
+                       using (StreamWriter sw = new StreamWriter (resxFile, 
false, Encoding.UTF8)) {
+                               sw.Write (string.Format 
(CultureInfo.InvariantCulture,
+                                       _resXFileRefTemplate, 
ResXResourceWriter.ResMimeType, "1.0",
+                                       Consts.AssemblySystem_Windows_Forms, 
refFile,
+                                       typeof (Bitmap).AssemblyQualifiedName, 
string.Empty));
+                       }
+
+                       using (ResXResourceReader r = new ResXResourceReader 
(resxFile)) {
+                               IDictionaryEnumerator enumerator = 
r.GetMetadataEnumerator ();
+                               enumerator.MoveNext ();
+                               Assert.IsNotNull (enumerator.Current, "#A1");
+                               Assert.AreEqual ("panel_label.Locked", 
enumerator.Key, "#A2");
+                               bool flag = (bool)enumerator.Value;
+                               Assert.IsNotNull (flag, "#A3");
+                               Assert.AreEqual (true, flag, "#A4");
+                       }
+               }
+
+               [Test]
                public void TypeConversion ()
                {
                        string resXContent = string.Format 
(CultureInfo.CurrentCulture,
@@ -1661,9 +1715,13 @@
                        "       <resheader name=\"writer\">" +
                        "               
<value>System.Resources.ResXResourceWriter, {2}</value>" +
                        "       </resheader>" +
+                       "       <metadata name=\"panel_label.Locked\" 
type=\"System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089\">" +
+                       "               <value>True</value>" +
+                       "       </metadata>" +
                        "       <data name=\"foo\" 
type=\"System.Resources.ResXFileRef, {2}\">" +
                        "               <value>{3};{4}{5}</value>" +
                        "       </data>" +
                        "</root>";
        }
 }
+
Index: System.Resources/ResXResourceReader.cs
===================================================================
--- System.Resources/ResXResourceReader.cs      (révision 90518)
+++ System.Resources/ResXResourceReader.cs      (copie de travail)
@@ -37,6 +37,7 @@
 using System.Resources;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Xml;
+using System.Reflection;
 
 namespace System.Resources
 {
@@ -48,11 +49,14 @@
                private TextReader reader;
                private Hashtable hasht;
                private ITypeResolutionService typeresolver;
-
                private XmlTextReader xmlReader;
 
+
 #if NET_2_0
                private string basepath;
+               private bool useResXDataNodes;
+               private AssemblyName [] assemblyNames;
+               private Hashtable hashtm;
 #endif
                #endregion      // Local Variables
 
@@ -66,7 +70,10 @@
                                throw new ArgumentException ("Stream was not 
readable.");
 
                        this.stream = stream;
-               }
+#if NET_2_0
+                       this.useResXDataNodes = false;
+#endif
+        }
 
                public ResXResourceReader (Stream stream, 
ITypeResolutionService typeresolver)
                        : this (stream)
@@ -77,7 +84,10 @@
                public ResXResourceReader (string fileName)
                {
                        this.fileName = fileName;
-               }
+#if NET_2_0
+                       this.useResXDataNodes = false;
+#endif
+        }
 
                public ResXResourceReader (string fileName, 
ITypeResolutionService typeresolver)
                        : this (fileName)
@@ -88,6 +98,9 @@
                public ResXResourceReader (TextReader reader)
                {
                        this.reader = reader;
+#if NET_2_0
+                       this.useResXDataNodes = false;
+#endif
                }
 
                public ResXResourceReader (TextReader reader, 
ITypeResolutionService typeresolver)
@@ -96,6 +109,28 @@
                        this.typeresolver = typeresolver;
                }
 
+#if NET_2_0
+
+               public ResXResourceReader (Stream stream, AssemblyName [] 
assemblyNames)
+                       : this (stream)
+               {
+                       this.assemblyNames = assemblyNames;
+               }
+
+               public ResXResourceReader (string fileName, AssemblyName [] 
assemblyNames)
+                       : this (fileName)
+               {
+                       this.assemblyNames = assemblyNames;
+               }
+
+               public ResXResourceReader (TextReader reader, AssemblyName [] 
assemblyNames)
+                       : this (reader)
+               {
+                       this.assemblyNames = assemblyNames;
+               }
+
+
+#endif
                ~ResXResourceReader ()
                {
                        Dispose (false);
@@ -107,11 +142,23 @@
                        get { return basepath; }
                        set { basepath = value; }
                }
+               public bool UseResXDataNodes {
+                       get { return useResXDataNodes; }
+                       set {
+                               if (xmlReader != null)
+                                       throw new InvalidOperationException ();
+                               useResXDataNodes = value; 
+                       }
+               }
 #endif
 
                #region Private Methods
                private void LoadData ()
                {
+                       hasht = new Hashtable ();
+#if NET_2_0
+                       hashtm = new Hashtable ();
+#endif
                        if (fileName != null) {
                                stream = File.OpenRead (fileName);
                        }
@@ -141,8 +188,13 @@
                                                        ParseHeaderNode 
(header);
                                                        break;
                                                case "data":
-                                                       ParseDataNode ();
+                                                       ParseDataNode (false);
                                                        break;
+#if NET_2_0
+                                               case "metadata":
+                                                       ParseDataNode (true);
+                                                       break;
+#endif
                                                }
                                        }
 #if NET_2_0
@@ -165,6 +217,7 @@
                                        stream.Close ();
                                        stream = null;
                                }
+                               xmlReader = null;
                        }
                }
 
@@ -213,12 +266,12 @@
                        return null;
                }
 
-               private string GetDataValue ()
+               private string GetDataValue (bool meta)
                {
                        string value = null;
 #if NET_2_0
                        while (xmlReader.Read ()) {
-                               if (xmlReader.NodeType == 
XmlNodeType.EndElement && xmlReader.LocalName == "data")
+                               if (xmlReader.NodeType == 
XmlNodeType.EndElement && xmlReader.LocalName == (meta ? "metadata" : "data"))
                                        break;
 
                                if (xmlReader.NodeType == XmlNodeType.Element) {
@@ -228,7 +281,7 @@
                                                xmlReader.WhitespaceHandling = 
WhitespaceHandling.None;
                                        } else if (xmlReader.Name.Equals 
("comment")) {
                                                xmlReader.Skip ();
-                                               if (xmlReader.NodeType == 
XmlNodeType.EndElement && xmlReader.LocalName == "data")
+                                               if (xmlReader.NodeType == 
XmlNodeType.EndElement && xmlReader.LocalName == (meta ? "metadata" : "data"))
                                                        break;
                                        }
                                }
@@ -249,11 +302,12 @@
                        return value;
                }
 
-               private void ParseDataNode ()
+               private void ParseDataNode (bool meta)
                {
                        string name = GetAttribute ("name");
                        string type_name = GetAttribute ("type");
                        string mime_type = GetAttribute ("mimetype");
+                       Hashtable hashtable = (meta ? hashtm : hasht);
 
                        Type type = type_name == null ? null : ResolveType 
(type_name);
 
@@ -262,11 +316,17 @@
                                        "The type '{0}' of the element '{1}' 
could not be resolved.", type_name, name));
 
                        if (type == typeof (ResXNullRef)) {
-                               hasht [name] = null;
+                               
+#if NET_2_0
+                               if (useResXDataNodes)
+                                       hashtable [name] = new 
ResXDataNode(name, null);
+                               else
+#endif
+                                       hashtable [name] = null;
                                return;
                        }
 
-                       string value = GetDataValue ();
+                       string value = GetDataValue (meta);
                        object obj = null;
 
                        if (mime_type != null && mime_type.Length > 0) {
@@ -315,17 +375,35 @@
                                throw new ArgumentException (string.Format 
(CultureInfo.CurrentCulture,
                                        "Could not find a name for a resource. 
The resource value "
                                        + "was '{0}'.", obj));
-
-                       hasht [name] = obj;
+#if NET_2_0
+                       if (useResXDataNodes)
+                               hashtable [name] = new ResXDataNode(name, obj);
+                       else
+#endif
+                       hashtable [name] = obj;
                }
 
                private Type ResolveType (string type)
                {
-                       if (typeresolver == null) {
-                               return Type.GetType (type);
-                       } else {
+                       if (typeresolver != null) {
                                return typeresolver.GetType (type);
+                       } 
+#if NET_2_0
+                       if (assemblyNames != null) {
+                               Type result;
+                               foreach (AssemblyName assem in assemblyNames) {
+                                       Assembly myAssembly = Assembly.Load 
(assem);
+                                       result = myAssembly.GetType (type, 
false);
+                                       if (result != null)
+                                               return result;
+                                       //else loop
+                               }
+                               //if type not found on assembly list we return 
null or we get from current assembly?
+                               //=> unit test needed
                        }
+#endif
+                       return Type.GetType (type);
+
                }
                #endregion      // Private Methods
 
@@ -341,7 +419,6 @@
                public IDictionaryEnumerator GetEnumerator ()
                {
                        if (hasht == null) {
-                               hasht = new Hashtable ();
                                LoadData ();
                        }
                        return hasht.GetEnumerator ();
@@ -374,7 +451,19 @@
                {
                        return new ResXResourceReader (new StringReader 
(fileContents), typeResolver);
                }
+#if NET_2_0
+               public static ResXResourceReader FromFileContents (string 
fileContents, AssemblyName [] assemblyNames)
+               {
+                       return new ResXResourceReader (new StringReader 
(fileContents), assemblyNames);
+               }
 
+               public IDictionaryEnumerator GetMetadataEnumerator ()
+               {
+                       if (hashtm == null)
+                               LoadData ();
+                       return hashtm.GetEnumerator ();
+               }
+#endif
                #endregion      // Public Methods
 
                #region Internal Classes
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to