|
Rotor explanation...
1: // ==++==
2: //
3: //
4: // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
5: //
6: // The use and distribution terms for this software are contained in the file
7: // named license.txt, which can be found in the root of this distribution.
8: // By using this software in any fashion, you are agreeing to be bound by the
9: // terms of this license.
10: //
11: // You must not remove this notice, or any other, from this software.
12: //
13: //
14: // ==--==
15: /*============================================================
16: **
17: ** Class: Object
18: **
19: **
20: **
21: ** Object is the root class for all CLR objects. This class
22: ** defines only the basics.
23: **
24: ** Date: January 29, 1998
25: **
26: ===========================================================*/
27:
28: namespace System {
29: using System;
30: using System.Runtime.InteropServices;
31: using System.Runtime.CompilerServices;
32: using CultureInfo = System.Globalization.CultureInfo;
33: using FieldInfo = System.Reflection.FieldInfo;
34: using BindingFlags = System.Reflection.BindingFlags;
35: using RemotingException = System.Runtime.Remoting.RemotingException;
36: // The Object is the root class for all object in the CLR System. Object
37: // is the super class for all other CLR objects and provide a set of methods and low level
38: // services to subclasses. These services include object synchronization and support for clone
39: // operations.
40: //
41: //This class contains no data and does not need to be serializable
42: /// <include file='doc\Object.uex' path='docs/doc[@for="Object"]/*' />
43: [Serializable()]
44: public class Object
45: {
46: // Creates a new instance of an Object.
47: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.Object"]/*' />
48: public Object()
49: {
50: }
51:
InternalGetType - Info | MSDN | Search
52: [MethodImplAttribute(MethodImplOptions.InternalCall)]
53: private extern Type InternalGetType();
54: [MethodImplAttribute(MethodImplOptions.InternalCall)]
FastGetExistingType - Info | MSDN | Search
55: private extern Type FastGetExistingType();
56:
57:
ToString - Info | MSDN | Search
58: // Returns a String which represents the object instance. The default
59: // for an object is to return the fully qualified name of the class.
60: //
61: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.ToString"]/*' />
62: public virtual String ToString()
63: {
64: return GetType().FullName;
65: }
66:
Equals - Info | MSDN | Search
67: // Returns a boolean indicating if the passed in object obj is
68: // Equal to this. Equality is defined as object equality for reference
69: // types and bitwise equality for value types using a loader trick to
70: // replace Equals with EqualsValue for value types).
71: //
72: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.Equals"]/*' />
73: [MethodImplAttribute(MethodImplOptions.InternalCall)]
74: public extern virtual bool Equals(Object obj);
75:
Equals - Info | MSDN | Search
76: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.Equals1"]/*' />
77: public static bool Equals(Object objA, Object objB) {
78: if (objA==objB) {
79: return true;
80: }
81: if (objA==null || objB==null) {
82: return false;
83: }
84: return objA.Equals(objB);
85: }
86:
ReferenceEquals - Info | MSDN | Search
87: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.ReferenceEquals"]/*' />
88: public static bool ReferenceEquals (Object objA, Object objB) {
89: return objA == objB;
90: }
91:
GetHashCode - Info | MSDN | Search
92: // GetHashCode is intended to serve as a hash function for this object.
93: // Based on the contents of the object, the hash function will return a suitable
94: // value with a relatively random distribution over the various inputs.
95: //
96: // The default implementation returns the sync block index for this instance.
97: // Calling it on the same object multiple times will return the same value, so
98: // it will technically meet the needs of a hash function, but it's less than ideal.
99: // Objects (& especially value classes) should override this method.
100: //
101: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.GetHashCode"]/*' />
102: [MethodImplAttribute(MethodImplOptions.InternalCall)]
103: public extern virtual int GetHashCode();
104:
GetType - Info | MSDN | Search
105: // Returns a Type object which represent this object instance.
106: //
107: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.GetType"]/*' />
108: public Type GetType()
109: {
110: Type ret;
111: ret = FastGetExistingType();
112:
113: if (ret == null)
114: ret = InternalGetType();
115: return ret;
116: }
117:
118: // Allow an object to free resources before the object is reclaimed by the GC.
119: //
120: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.Finalize"]/*' />
121: ~Object()
122: {
123: }
124:
MemberwiseClone - Info | MSDN | Search
125: // Returns a new object instance that is a memberwise copy of this
126: // object. This is always a shallow copy of the instance. The method is protected
127: // so that other object may only call this method on themselves. It is entended to
128: // support the ICloneable interface.
129: //
130: /// <include file='doc\Object.uex' path='docs/doc[@for="Object.MemberwiseClone"]/*' />
131: [MethodImplAttribute(MethodImplOptions.InternalCall)]
132: protected extern Object MemberwiseClone();
133:
134:
FieldSetter - Info | MSDN | Search
135: // Sets the value specified in the variant on the field
136: //
137: private void FieldSetter(String typeName, String fieldName, Object val)
138: {
139: // Extract the field info object
140: FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
141:
142: // Make sure that the value is compatible with the type
143: // of field
144: System.Runtime.Remoting.Messaging.Message.CoerceArg(val, fldInfo.FieldType);
145:
146: // Set the value
147: fldInfo.SetValue(this, val);
148: }
149:
FieldGetter - Info | MSDN | Search
150: // Gets the value specified in the variant on the field
151: //
152: private void FieldGetter(String typeName, String fieldName, ref Object val)
153: {
154: // Extract the field info object
155: FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
156:
157: // Get the value
158: val = fldInfo.GetValue(this);
159: }
160:
GetFieldInfo - Info | MSDN | Search
161: // Gets the field info object given the type name and field name.
162: //
163: private FieldInfo GetFieldInfo(String typeName, String fieldName)
164: {
165: Type t = GetType();
166: while(null != t)
167: {
168: if(t.FullName.Equals(typeName))
169: {
170: break;
171: }
172:
173: t = t.BaseType;
174: }
175:
176: if (null == t)
177: {
178: throw new RemotingException(String.Format(
179: Environment.GetResourceString("Remoting_BadType"),
180: typeName));
181: }
182:
183: FieldInfo fldInfo = t.GetField(fieldName, BindingFlags.Public |
184: BindingFlags.Instance |
185: BindingFlags.IgnoreCase);
186: if(null == fldInfo)
187: {
188: throw new RemotingException(String.Format(
189: Environment.GetResourceString("Remoting_BadField"),
190: fieldName, typeName));
191: }
192:
193: return fldInfo;
194: }
195: }
196: }
Generated on
24/10/2003 19:00:38
|