mscorlib(4.0.0.0) API with additions
Object.cs
2 using System.Reflection;
9 using System.Security;
10 
11 namespace System
12 {
14  [Serializable]
15  [ClassInterface(ClassInterfaceType.AutoDual)]
16  [ComVisible(true)]
17  [__DynamicallyInvokable]
18  public class Object
19  {
21  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
22  [NonVersionable]
23  [__DynamicallyInvokable]
24  public Object()
25  {
26  }
27 
30  [__DynamicallyInvokable]
31  public virtual string ToString()
32  {
33  return GetType().ToString();
34  }
35 
40  [__DynamicallyInvokable]
41  public virtual bool Equals(object obj)
42  {
43  return RuntimeHelpers.Equals(this, obj);
44  }
45 
51  [__DynamicallyInvokable]
52  public static bool Equals(object objA, object objB)
53  {
54  if (objA == objB)
55  {
56  return true;
57  }
58  if (objA == null || objB == null)
59  {
60  return false;
61  }
62  return objA.Equals(objB);
63  }
64 
70  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
71  [NonVersionable]
72  [__DynamicallyInvokable]
73  public static bool ReferenceEquals(object objA, object objB)
74  {
75  return objA == objB;
76  }
77 
80  [__DynamicallyInvokable]
81  public virtual int GetHashCode()
82  {
83  return RuntimeHelpers.GetHashCode(this);
84  }
85 
88  [MethodImpl(MethodImplOptions.InternalCall)]
89  [SecuritySafeCritical]
90  [__DynamicallyInvokable]
91  public extern Type GetType();
92 
94  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
95  [NonVersionable]
96  [__DynamicallyInvokable]
97  ~Object()
98  {
99  }
100 
103  [MethodImpl(MethodImplOptions.InternalCall)]
104  [SecuritySafeCritical]
105  [__DynamicallyInvokable]
106  protected extern object MemberwiseClone();
107 
108  [SecurityCritical]
109  private void FieldSetter(string typeName, string fieldName, object val)
110  {
111  FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
112  if (fieldInfo.IsInitOnly)
113  {
114  throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
115  }
116  Message.CoerceArg(val, fieldInfo.FieldType);
117  fieldInfo.SetValue(this, val);
118  }
119 
120  private void FieldGetter(string typeName, string fieldName, ref object val)
121  {
122  FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
123  val = fieldInfo.GetValue(this);
124  }
125 
126  private FieldInfo GetFieldInfo(string typeName, string fieldName)
127  {
128  Type type = GetType();
129  while (null != type && !type.FullName.Equals(typeName))
130  {
131  type = type.BaseType;
132  }
133  if (null == type)
134  {
135  throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), typeName));
136  }
137  FieldInfo field = type.GetField(fieldName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
138  if (null == field)
139  {
140  throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
141  }
142  return field;
143  }
144  }
145 }
virtual int GetHashCode()
Serves as the default hash function.
Definition: Object.cs:81
abstract Type FieldType
Gets the type of this field object.
Definition: FieldInfo.cs:34
static int GetHashCode(object o)
Serves as a hash function for a particular object, and is suitable for use in algorithms and data str...
object MemberwiseClone()
Creates a shallow copy of the current T:System.Object.
Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived...
Definition: Object.cs:18
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Definition: __Canon.cs:3
override string ToString()
Returns a String representing the name of the current Type.
Definition: Type.cs:2788
bool IsInitOnly
Gets a value indicating whether the field can only be set in the body of the constructor.
Definition: FieldInfo.cs:144
abstract object GetValue(object obj)
When overridden in a derived class, returns the value of a field supported by a given object.
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
Type GetType()
Gets the T:System.Type of the current instance.
virtual bool Equals(object obj)
Determines whether the specified object is equal to the current object.
Definition: Object.cs:41
static new bool Equals(object o1, object o2)
Determines whether the specified T:System.Object instances are considered equal.
static bool Equals(object objA, object objB)
Determines whether the specified object instances are considered equal.
Definition: Object.cs:52
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
MethodImplOptions
Defines the details of how a method is implemented.
Indicates that data in the pipe is transmitted and read as a stream of messages.
Object()
Initializes a new instance of the T:System.Object class.
Definition: Object.cs:24
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
virtual string ToString()
Returns a string that represents the current object.
Definition: Object.cs:31
abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
When overridden in a derived class, sets the value of the field supported by the given object.
Specifies that the class can be serialized.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
static bool ReferenceEquals(object objA, object objB)
Determines whether the specified T:System.Object instances are the same instance.
Definition: Object.cs:73
The exception that is thrown when something has gone wrong during remoting.
Provides a set of static methods and properties that provide support for compilers....