andrew4582

System.Object

Sep 4th, 2010
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.59 KB | None | 0 0
  1. namespace System
  2. {
  3.     using System.Globalization;
  4.     using System.Reflection;
  5.     using System.Runtime;
  6.     using System.Runtime.CompilerServices;
  7.     using System.Runtime.ConstrainedExecution;
  8.     using System.Runtime.InteropServices;
  9.     using System.Runtime.Remoting;
  10.     using System.Runtime.Remoting.Messaging;
  11.     using System.Security;
  12.  
  13.     [Serializable, ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
  14.     public class Object
  15.     {
  16.         [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  17.         public virtual bool Equals(object obj)
  18.         {
  19.             return RuntimeHelpers.Equals(this, obj);
  20.         }
  21.  
  22.         [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  23.         public static bool Equals(object objA, object objB)
  24.         {
  25.             return ((objA == objB) || (((objA != null) && (objB != null)) && objA.Equals(objB)));
  26.         }
  27.  
  28.         private void FieldGetter(string typeName, string fieldName, ref object val)
  29.         {
  30.             val = this.GetFieldInfo(typeName, fieldName).GetValue(this);
  31.         }
  32.  
  33.         [SecurityCritical]
  34.         private void FieldSetter(string typeName, string fieldName, object val)
  35.         {
  36.             FieldInfo fieldInfo = this.GetFieldInfo(typeName, fieldName);
  37.             if (fieldInfo.IsInitOnly)
  38.             {
  39.                 throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
  40.             }
  41.             Message.CoerceArg(val, fieldInfo.FieldType);
  42.             fieldInfo.SetValue(this, val);
  43.         }
  44.  
  45.         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
  46.         protected virtual void Finalize()
  47.         {
  48.         }
  49.  
  50.         private FieldInfo GetFieldInfo(string typeName, string fieldName)
  51.         {
  52.             Type baseType = this.GetType();
  53.             while (null != baseType)
  54.             {
  55.                 if (baseType.FullName.Equals(typeName))
  56.                 {
  57.                     break;
  58.                 }
  59.                 baseType = baseType.BaseType;
  60.             }
  61.             if (null == baseType)
  62.             {
  63.                 throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { typeName }));
  64.             }
  65.             FieldInfo field = baseType.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
  66.             if (null == field)
  67.             {
  68.                 throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadField"), new object[] { fieldName, typeName }));
  69.             }
  70.             return field;
  71.         }
  72.  
  73.         [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  74.         public virtual int GetHashCode()
  75.         {
  76.             return RuntimeHelpers.GetHashCode(this);
  77.         }
  78.  
  79.         [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
  80.         public extern Type GetType();
  81.         [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
  82.         protected extern object MemberwiseClone();
  83.         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
  84.         public static bool ReferenceEquals(object objA, object objB)
  85.         {
  86.             return (objA == objB);
  87.         }
  88.  
  89.         public virtual string ToString()
  90.         {
  91.             return this.GetType().ToString();
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment