lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DIGY" <digyd...@gmail.com>
Subject RE: [jira] Updated: (LUCENENET-100) Problem with remoting of IComparable[] in FieldDoc.cs
Date Wed, 19 Sep 2007 18:41:36 GMT
Hi Neal,

These sample codes are just to point to the problem in FieldDoc.cs
What you suggest is what i exactly did in the attached patch.

DIGY

-----Original Message-----
From: Granroth, Neal V. [mailto:neal.granroth@thermofisher.com] 
Sent: Wednesday, September 19, 2007 9:30 PM
To: lucene-net-dev@incubator.apache.org
Subject: RE: [jira] Updated: (LUCENENET-100) Problem with remoting of
IComparable[] in FieldDoc.cs

Very curious.
However attempting to remote an array of interfaces does not seem like a
very useful thing to do.  When the array is deserialized, what objects would
.NET be expected to create?  Since IComparable is not an object, simply an
interface, some real concrete object must be created.  There are many System
objects implementing this interface (double, float, int, string, ...); in
that example code it would be valid for deserialization to construct any of
these are concrete objects to obtain the IComparable interfaces required to
satisfy construction of the requested IComparable[] arr2.

One solution, referring to the example using the BinaryFormater, is to
convert (box) the values being remoted to String objects as in:

MemoryStream m = new MemoryStream();
             System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
formatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
             IComparable[] arr = new IComparable[1];
             arr[0] = Convert.ToString(123.45);
             formatter.Serialize(m, arr);
             m.Seek(0, SeekOrigin.Begin);
             IComparable[] arr2 = (IComparable[])formatter.Deserialize(m);
             Console.WriteLine(arr2[0].ToString() + " " +
arr2[0].GetType().ToString());


A better solution would be to always remote arrays of objects that support
the IComparable interface, instead of interfaces:

MemoryStream m = new MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object [] arrx = new object[3];
arrx[0] = 123.45;
arrx[1] = "122.46";
arrx[2] = 121.47f;
formatter.Serialize(m, arrx);
m.Seek(0, SeekOrigin.Begin);
object[] arr2 = (object[])formatter.Deserialize(m);
foreach(object oC in arr2)
{
   Console.WriteLine(oC.ToString() + " " + oC.GetType().ToString());
   Console.WriteLine("   " +
oC.GetType().GetInterface("System.IComparable").ToString());
}
Console.ReadLine();


-- Neal


Mime
View raw message