Where is the implemented code for Object.Equal()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bijay Kumar

    #1

    Where is the implemented code for Object.Equal()

    Hi Guys,

    I was going through the source code of Object class (Object.cs in rotor). What I found is
    Equals() implemented as follows:

    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]

    public extern virtual bool Equals(Object obj);

    What I don't understand is:

    A) where is the actual code implemented?

    B) What does 'extern' mean in this context?

    Thanks in advance.

    Bijay

    PS: The code for Object.cs is attached herewith for ref

    // ==--==
    /*============== =============== =============== =============== =
    **
    ** Class: Object
    **
    **
    **
    ** Object is the root class for all CLR objects. This class
    ** defines only the basics.
    **
    ** Date: January 29, 1998
    **
    =============== =============== =============== ==============*/

    namespace System {
    using System;
    using System.Runtime. InteropServices ;
    using System.Runtime. CompilerService s;
    using CultureInfo = System.Globaliz ation.CultureIn fo;
    using FieldInfo = System.Reflecti on.FieldInfo;
    using BindingFlags = System.Reflecti on.BindingFlags ;
    using RemotingExcepti on = System.Runtime. Remoting.Remoti ngException;
    // The Object is the root class for all object in the CLR System. Object
    // is the super class for all other CLR objects and provide a set of methods
    and low level
    // services to subclasses. These services include object synchronization
    and support for clone
    // operations.
    //
    //This class contains no data and does not need to be serializable
    /// <include file='doc\Objec t.uex' path='docs/doc[@for="Object"]/*' />
    [Serializable()]
    public class Object
    {
    // Creates a new instance of an Object.
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Ob ject"]/*' />
    public Object()
    {
    }

    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]
    private extern Type InternalGetType ();
    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]
    private extern Type FastGetExisting Type();


    // Returns a String which represents the object instance. The default
    // for an object is to return the fully qualified name of the class.
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.To String"]/*' />
    public virtual String ToString()
    {
    return GetType().FullN ame;
    }

    // Returns a boolean indicating if the passed in object obj is
    // Equal to this. Equality is defined as object equality for reference
    // types and bitwise equality for value types using a loader trick to
    // replace Equals with EqualsValue for value types).
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Eq uals"]/*' />
    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]
    public extern virtual bool Equals(Object obj);

    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Eq uals1"]/*' />
    public static bool Equals(Object objA, Object objB) {
    if (objA==objB) {
    return true;
    }
    if (objA==null || objB==null) {
    return false;
    }
    return objA.Equals(obj B);
    }

    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Re ferenceEquals"]/*' />
    public static bool ReferenceEquals (Object objA, Object objB) {
    return objA == objB;
    }

    // GetHashCode is intended to serve as a hash function for this object.
    // Based on the contents of the object, the hash function will return a
    suitable
    // value with a relatively random distribution over the various inputs.
    //
    // The default implementation returns the sync block index for this
    instance.
    // Calling it on the same object multiple times will return the same
    value, so
    // it will technically meet the needs of a hash function, but it's less
    than ideal.
    // Objects (& especially value classes) should override this method.
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Ge tHashCode"]/*' />
    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]
    public extern virtual int GetHashCode();

    // Returns a Type object which represent this object instance.
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Ge tType"]/*' />
    public Type GetType()
    {
    Type ret;
    ret = FastGetExisting Type();

    if (ret == null)
    ret = InternalGetType ();
    return ret;
    }

    // Allow an object to free resources before the object is reclaimed by
    the GC.
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Fi nalize"]/*' />
    ~Object()
    {
    }

    // Returns a new object instance that is a memberwise copy of this
    // object. This is always a shallow copy of the instance. The method is
    protected
    // so that other object may only call this method on themselves. It is
    entended to
    // support the ICloneable interface.
    //
    /// <include file='doc\Objec t.uex'
    path='docs/doc[@for="Object.Me mberwiseClone"]/*' />
    [MethodImplAttri bute(MethodImpl Options.Interna lCall)]
    protected extern Object MemberwiseClone ();


    // Sets the value specified in the variant on the field
    //
    private void FieldSetter(Str ing typeName, String fieldName, Object val)
    {
    // Extract the field info object
    FieldInfo fldInfo = GetFieldInfo(ty peName, fieldName);

    // Make sure that the value is compatible with the type
    // of field
    System.Runtime. Remoting.Messag ing.Message.Coe rceArg(val,
    fldInfo.FieldTy pe);

    // Set the value
    fldInfo.SetValu e(this, val);
    }

    // Gets the value specified in the variant on the field
    //
    private void FieldGetter(Str ing typeName, String fieldName, ref Object
    val)
    {
    // Extract the field info object
    FieldInfo fldInfo = GetFieldInfo(ty peName, fieldName);

    // Get the value
    val = fldInfo.GetValu e(this);
    }

    // Gets the field info object given the type name and field name.
    //
    private FieldInfo GetFieldInfo(St ring typeName, String fieldName)
    {
    Type t = GetType();
    while(null != t)
    {
    if(t.FullName.E quals(typeName) )
    {
    break;
    }

    t = t.BaseType;
    }

    if (null == t)
    {
    throw new RemotingExcepti on(String.Forma t(
    Environment.Get ResourceString( "Remoting_BadTy pe"),
    typeName));
    }

    FieldInfo fldInfo = t.GetField(fiel dName, BindingFlags.Pu blic |
    BindingFlags.In stance |
    BindingFlags.Ig noreCase);
    if(null == fldInfo)
    {
    throw new RemotingExcepti on(String.Forma t(
    Environment.Get ResourceString( "Remoting_BadFi eld"),
    fieldName, typeName));
    }

    return fldInfo;
    }
    }
    }







Working...