473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;
}
}
}



Nov 15 '05 #1
0 4631

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

Similar topics

1
3227
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 understand is:
17
5046
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
3449
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, or one-past the end of the object as long as it isn't dereferenced. I use "object" in the standard 'C' sense. Is there some special dispensation given to comparing two pointers
3
1491
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 that I am testing and their properties are diverse, including enums, basic system types, arrays and nested types. The objects themselves were not written by me, and do not have any overrides for equals, compare ... etc.
6
2782
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
4090
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 some details which I'll highly appreciated your assistance on. 1- When using pure paging and for a page size equal to 4KB=2^12, each page should be located at 4KB's offset in the main memory. There is no similar restriction with segmentation...
15
2733
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 IpFormCollection : IEnumerable<IpForm> { ArrayList forms = new ArrayList(); public IEnumerator<IpFormGetEnumerator() {
9
1462
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 changed by another thread int var_this_thread;
23
5740
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 or Array, correct? An example: create the object, create an array, the stuff the object into the array. Later on, assume the object is mutable, the object changes, but you can find it, if you have enough state information to uniquely identify...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.