Share via


ModulePageInfo.Equals(Object) Method

Definition

Determines whether the specified object is equal to the current ModulePageInfo.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

Parameters

obj
Object

The object to compare with the current ModulePageInfo object.

Returns

true if the objects are both ModulePageInfo objects and have some fields with equal values; otherwise, false.

Examples

    ModulePageInfo getModPage(string title, string sDesc, Image imgSm,
        Image ImLg, string longDes) 
    {
        return new ModulePageInfo(
        this, typeof(DemoPage), title, sDesc, imgSm, ImLg, longDes);
    }

    ModulePageInfo getModPage(string title) 
    {
        return new ModulePageInfo(this, typeof(DemoPage), title);
    }

    bool imageMatch(object o1, object o2) 
    {
        Image i1 = (Image)o1;
        Image i2 = (Image)o2;

        if (i1 == null && i2 != null ||
            i1 != null && i2 == null
            )
            return false;

        if (i1 != null && i2 != null) 
        {
            bool b = true;
            b = i1.GetHashCode() == i1.GetHashCode();
            if (b == false)
                return b;
        }

        // Both images NULL -> equality.
        return true;
    }

    bool myCompare(ModulePageInfo m1, ModulePageInfo m2) 
    {
        bool b = m1.Equals(m2);
        if (b == false)
            return b;

        b = m1.Description == m2.Description;
        if (b == false)
            return b;

        b = imageMatch(m1.SmallImage, m2.SmallImage);
        if (b == false)
            return b;

        b = imageMatch(m1.LargeImage, m2.LargeImage);
        if (b == false)
            return b;

        b = m1.LongDescription == m2.LongDescription;
        if (b == false)
            return b;

        return b;
    }

    void testModPageEq() 
    {
        string strFirst = "First Title";

        ModulePageInfo modPgInfo1 = getModPage(strFirst);
        ModulePageInfo modPgInfo2 = getModPage(strFirst, "Descrip", 
            rLoadImg.loadImgs("rSmall.bmp"),
            rLoadImg.loadImgs("rLarge.bmp"), "Long Descript");

        // The two show equality here.
        bool bEQ = modPgInfo1.Equals(modPgInfo2);
        Trace.WriteLine("modPgInfo1.Equals(modPgInfo2) : " 
            + bEQ.ToString());

        // A better compare shows they differ.
        bEQ = myCompare(modPgInfo1, modPgInfo2);
        Trace.WriteLine("myCompare(Mod1, Mod2) : " + bEQ.ToString());

    }
}

Remarks

For the objects to be equal, the specified object must be assignable to a ModulePageInfo object and must have the same PageType and Title.

Applies to