[Mono-list] Mono/.Net: object comparison

Martin Hinks mhinks at gmail.com
Thu Jun 30 05:12:59 EDT 2005


Sounds like a classic referencing problem, I would think logically
that myArray[0] different from foo is the correct behaviour...

MyClass test = new MyClass ("1","2","3");
MyClass test2 = new MyClass ("1","2","3");

test != test2

They have different references although the values are the same...

I wouldn't therefore be able to do test.String1 = "new" and expect the
value of test2.String1 to change. They are different objects...

So, the answer is that Mono seems to be comparing on memory reference
whilst .NET does the comparison on value. Guess a bugzilla report is
needed, I can file it if you want or you can as you have the working
test case...



On 6/24/05, Julien Sobrier <julien at sobrier.net> wrote:
> Hello,
> I've compiled a program with Mono 1.1.6 under Linux, and Windows .Net,
> with NAnt 0.85RC3 and NUnit 2.2.0
> 
> I see a different behavior when I compare object with NUnit:
> 
> I have a custom class MyClass with 3 public variables: String1 (string),
> String2 (string) and Version1 (Version).
> 
> In one class, I do like:
> ArrayList myArray = new ArrayList();
> myArray.Add(new MyClass(string1, string2, version1);
> myArray.Add(new MyClass(string1a, string2a, version1a);
> myArray.Add(new MyClass(string1b, string2b, version1b);
> 
> Then I create MyClass foo = new MyClass(string1, string2, version1)
> 
> Then, with Nunit, I do some comparisons (note sure about the index for
> myArray):
> * Mono 1.1.6/Linux
> myArray[0] different from foo
> (MyClass) MyArray[0] different from foo
> ((MyClass) MyArray[0]).String1 =  foo.String1
> ((MyClass) MyArray[0]).String2 =  foo.String2
> ((MyClass) MyArray[0]).Version1 =  foo.Version1
> 
> * .Net/Windows
> myArray[0] = foo
> (MyClass) MyArray[0] = foo
> ((MyClass) MyArray[0]).String1 =  foo.String1
> ((MyClass) MyArray[0]).String2 =  foo.String2
> ((MyClass) MyArray[0]).Version1 =  foo.Version1
> 
> 
> Who is right? I hope .Net is right :-) I wonder what cause this
> different behavior
> 
> 
> Details of the code:
> [Test]
> [Category("attributes")]
> public void AssemblyDependTest()
> {
>     Assert.AreEqual(this.PluginA.Dependencies.Count, 6,
> "AssemblyDepend: number of dependencies");
> 
>     AssemblyDepend test = new
> Platine.CoreLibs.Attributes.AssemblyDepend("PluginB");
> 
>     Assert.AreEqual(test.PluginName, "PluginB", "AssemblyDepend:
> PluginA depends on PluginB"); // OK
>     Assert.AreEqual(test.MinVersion.ToString(), "0.0.0.0",
> "AssemblyDepend: PluginA depends on PluginB"); // OK
>     Assert.AreEqual(test.EventName, "*", "AssemblyDepend: PluginA
> depends on PluginB"); // OK
> 
>                        Assert.IsTrue(this.PluginA.Dependencies.Contains(test),
> "AssemblyDepend: PluginA depends on PluginB"); // WRONG, should be OK
> 
> Assert.AreEqual(((AssemblyDepend)
> this.PluginA.Dependencies[5]).PluginName, test.PluginName,
> "AssemblyDepend: PluginA depends on PluginB"); // OK
> Assert.AreEqual(((AssemblyDepend)
> this.PluginA.Dependencies[5]).EventName, test.EventName,
> "AssemblyDepend: PluginA depends on PluginB"); // OK
> Assert.AreEqual(((AssemblyDepend)
> this.PluginA.Dependencies[5]).MinVersion, test.MinVersion,
> "AssemblyDepend: PluginA depends on PluginB"); // OK
> }
> 
> Thank you
> Julien
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 


-- 
Martin Hinks
http://www.m-s-d.net


More information about the Mono-list mailing list