473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:

[MethodImplAttribute(MethodImplOptions.InternalCall )]

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.CompilerServices;
using CultureInfo = System.Globalization.CultureInfo;
using FieldInfo = System.Reflection.FieldInfo;
using BindingFlags = System.Reflection.BindingFlags;
using RemotingException = System.Runtime.Remoting.RemotingException;
// 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\Object.uex' path='docs/doc[@for="Object"]/*' />
[Serializable()]
public class Object
{
// Creates a new instance of an Object.
/// <include file='doc\Object.uex'
path='docs/doc[@for="Object.Object"]/*' />
public Object()
{
}

[MethodImplAttribute(MethodImplOptions.InternalCall )]
private extern Type InternalGetType();
[MethodImplAttribute(MethodImplOptions.InternalCall )]
private extern Type FastGetExistingType();
// 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\Object.uex'
path='docs/doc[@for="Object.ToString"]/*' />
public virtual String ToString()
{
return GetType().FullName;
}

// 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\Object.uex'
path='docs/doc[@for="Object.Equals"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall )]
public extern virtual bool Equals(Object obj);

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

/// <include file='doc\Object.uex'
path='docs/doc[@for="Object.ReferenceEquals"]/*' />
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\Object.uex'
path='docs/doc[@for="Object.GetHashCode"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall )]
public extern virtual int GetHashCode();

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

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

// Allow an object to free resources before the object is reclaimed by
the GC.
//
/// <include file='doc\Object.uex'
path='docs/doc[@for="Object.Finalize"]/*' />
~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\Object.uex'
path='docs/doc[@for="Object.MemberwiseClone"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall )]
protected extern Object MemberwiseClone();
// Sets the value specified in the variant on the field
//
private void FieldSetter(String typeName, String fieldName, Object val)
{
// Extract the field info object
FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);

// Make sure that the value is compatible with the type
// of field
System.Runtime.Remoting.Messaging.Message.CoerceAr g(val,
fldInfo.FieldType);

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

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

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

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

t = t.BaseType;
}

if (null == t)
{
throw new RemotingException(String.Format(
Environment.GetResourceString("Remoting_BadType"),
typeName));
}

FieldInfo fldInfo = t.GetField(fieldName, BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.IgnoreCase);
if(null == fldInfo)
{
throw new RemotingException(String.Format(
Environment.GetResourceString("Remoting_BadField") ,
fieldName, typeName));
}

return fldInfo;
}
}
}



Nov 15 '05 #1
0 4609

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
3
by: Ben | last post by:
Hi There I am doing some unit testing at the moment, and the majority of the leg work involves taking two objects (expected vs actual) and verifying that their properties are equal. The objects...
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
1
by: Maria | last post by:
Hi, I have read about paging, segmentation and paged segmentation and I believe I have (nearly) understood how these techniques are implemented in hardware. However, I am till confused about the...
15
by: Gustaf | last post by:
Using VS 2005. I got an 'IpForm' class and an 'IpFormCollection' class, containing IpForm objects. To iterate through IpFrom objects with foreach, the class is implemented as such: public class...
9
by: anon.asdf | last post by:
Hi! The following code is a snippet where the goto's cannot be removed "without increasing code-size, or decreasing performance". /*********A**************/ int var_other_thread; // value...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.