472,993 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 4585

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: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.