.Net System.Object 对象实现代码
  1 // Decompiled by Salamander version 1.0.6
// Decompiled by Salamander version 1.0.6
2 // Copyright 2002 Remotesoft Inc. All rights reserved.
// Copyright 2002 Remotesoft Inc. All rights reserved.
3 // http://www.remotesoft.com/salamander
// http://www.remotesoft.com/salamander
4
5 using System.Reflection;
using System.Reflection;
6 using System.Runtime;
using System.Runtime;
7 using System.Runtime.Remoting;
using System.Runtime.Remoting;
8 using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Messaging;
9
10 namespace System
namespace System
11 {
{
12 [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
  [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
13 [SerializableAttribute()]
  [SerializableAttribute()]
14 public class Object
  public class Object
15 {
  {
16
17 public Object()
    public Object()
18 {
    {
19 }
    }
20
21 // internalcall
    // internalcall
22 private Type InternalGetType();
    private Type InternalGetType();
23
24 // internalcall
    // internalcall
25 private Type FastGetExistingType();
    private Type FastGetExistingType();
26
27 public virtual string ToString()
    public virtual string ToString()
28 {
    {
29 return GetType().FullName;
      return GetType().FullName;
30 }
    }
31
32 // internalcall
    // internalcall
33 public virtual bool Equals(object obj);
    public virtual bool Equals(object obj);
34
35 public static bool Equals(object objA, object objB)
    public static bool Equals(object objA, object objB)
36 {
    {
37 if (objA == objB)
      if (objA == objB)
38 {
      {
39 return true;
        return true;
40 }
      }
41 if (objA == null || objB == null)
      if (objA == null || objB == null)
42 {
      {
43 return false;
        return false;
44 }
      }
45 else
      else
46 {
      {
47 return objA.Equals(objB);
        return objA.Equals(objB);
48 }
      }
49 }
    }
50
51 public static bool ReferenceEquals(object objA, object objB)
    public static bool ReferenceEquals(object objA, object objB)
52 {
    {
53 return objA == objB;
      return objA == objB;
54 }
    }
55
56 // internalcall
    // internalcall
57 public virtual int GetHashCode();
    public virtual int GetHashCode();
58
59 public Type GetType()
    public Type GetType()
60 {
    {
61 Type type = FastGetExistingType();
      Type type = FastGetExistingType();
62 if (type == null)
      if (type == null)
63 {
      {
64 type = InternalGetType();
        type = InternalGetType();
65 }
      }
66 return type;
      return type;
67 }
    }
68
69 ~Object()
    ~Object()
70 {
    {
71 }
    }
72
73 // internalcall
    // internalcall
74 protected object MemberwiseClone();
    protected object MemberwiseClone();
75
76 private void FieldSetter(string typeName, string fieldName, object val)
    private void FieldSetter(string typeName, string fieldName, object val)
77 {
    {
78 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
      FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
79 if (fieldInfo.IsInitOnly)
      if (fieldInfo.IsInitOnly)
80 {
      {
81 throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
        throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
82 }
      }
83 Message.CoerceArg(val, fieldInfo.FieldType);
      Message.CoerceArg(val, fieldInfo.FieldType);
84 fieldInfo.SetValue(this, val);
      fieldInfo.SetValue(this, val);
85 }
    }
86
87 private void FieldGetter(string typeName, string fieldName, ref object val)
    private void FieldGetter(string typeName, string fieldName, ref object val)
88 {
    {
89 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
      FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
90 val = fieldInfo.GetValue(this);
      val = fieldInfo.GetValue(this);
91 }
    }
92
93 private FieldInfo GetFieldInfo(string typeName, string fieldName)
    private FieldInfo GetFieldInfo(string typeName, string fieldName)
94 {
    {
95 Type type;
      Type type;
96
97 for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)
      for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)
98 {
      {
99 }
      }
100 if (type == null)
      if (type == null)
101 {
      {
102 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));
        throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));
103 }
      }
104 FieldInfo fieldInfo = type.GetField(fieldName, 21);
      FieldInfo fieldInfo = type.GetField(fieldName, 21);
105 if (fieldInfo == null)
      if (fieldInfo == null)
106 {
      {
107 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
        throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
108 }
      }
109 else
      else
110 {
      {
111 return fieldInfo;
        return fieldInfo;
112 }
      }
113 }
    }
114 }
  }
115
116 }
}
117
 // Decompiled by Salamander version 1.0.6
// Decompiled by Salamander version 1.0.62
 // Copyright 2002 Remotesoft Inc. All rights reserved.
// Copyright 2002 Remotesoft Inc. All rights reserved.3
 // http://www.remotesoft.com/salamander
// http://www.remotesoft.com/salamander4

5
 using System.Reflection;
using System.Reflection;6
 using System.Runtime;
using System.Runtime;7
 using System.Runtime.Remoting;
using System.Runtime.Remoting;8
 using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Messaging;9

10
 namespace System
namespace System11
 {
{12
 [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
  [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]13
 [SerializableAttribute()]
  [SerializableAttribute()]14
 public class Object
  public class Object15
 {
  {16

17
 public Object()
    public Object()18
 {
    {19
 }
    }20

21
 // internalcall
    // internalcall22
 private Type InternalGetType();
    private Type InternalGetType();23

24
 // internalcall
    // internalcall25
 private Type FastGetExistingType();
    private Type FastGetExistingType();26

27
 public virtual string ToString()
    public virtual string ToString()28
 {
    {29
 return GetType().FullName;
      return GetType().FullName;30
 }
    }31

32
 // internalcall
    // internalcall33
 public virtual bool Equals(object obj);
    public virtual bool Equals(object obj);34

35
 public static bool Equals(object objA, object objB)
    public static bool Equals(object objA, object objB)36
 {
    {37
 if (objA == objB)
      if (objA == objB)38
 {
      {39
 return true;
        return true;40
 }
      }41
 if (objA == null || objB == null)
      if (objA == null || objB == null)42
 {
      {43
 return false;
        return false;44
 }
      }45
 else
      else46
 {
      {47
 return objA.Equals(objB);
        return objA.Equals(objB);48
 }
      }49
 }
    }50

51
 public static bool ReferenceEquals(object objA, object objB)
    public static bool ReferenceEquals(object objA, object objB)52
 {
    {53
 return objA == objB;
      return objA == objB;54
 }
    }55

56
 // internalcall
    // internalcall57
 public virtual int GetHashCode();
    public virtual int GetHashCode();58

59
 public Type GetType()
    public Type GetType()60
 {
    {61
 Type type = FastGetExistingType();
      Type type = FastGetExistingType();62
 if (type == null)
      if (type == null)63
 {
      {64
 type = InternalGetType();
        type = InternalGetType();65
 }
      }66
 return type;
      return type;67
 }
    }68

69
 ~Object()
    ~Object()70
 {
    {71
 }
    }72

73
 // internalcall
    // internalcall74
 protected object MemberwiseClone();
    protected object MemberwiseClone();75

76
 private void FieldSetter(string typeName, string fieldName, object val)
    private void FieldSetter(string typeName, string fieldName, object val)77
 {
    {78
 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
      FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);79
 if (fieldInfo.IsInitOnly)
      if (fieldInfo.IsInitOnly)80
 {
      {81
 throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
        throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));82
 }
      }83
 Message.CoerceArg(val, fieldInfo.FieldType);
      Message.CoerceArg(val, fieldInfo.FieldType);84
 fieldInfo.SetValue(this, val);
      fieldInfo.SetValue(this, val);85
 }
    }86

87
 private void FieldGetter(string typeName, string fieldName, ref object val)
    private void FieldGetter(string typeName, string fieldName, ref object val)88
 {
    {89
 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
      FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);90
 val = fieldInfo.GetValue(this);
      val = fieldInfo.GetValue(this);91
 }
    }92

93
 private FieldInfo GetFieldInfo(string typeName, string fieldName)
    private FieldInfo GetFieldInfo(string typeName, string fieldName)94
 {
    {95
 Type type;
      Type type;96

97
 for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)
      for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)98
 {
      {99
 }
      }100
 if (type == null)
      if (type == null)101
 {
      {102
 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));
        throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));103
 }
      }104
 FieldInfo fieldInfo = type.GetField(fieldName, 21);
      FieldInfo fieldInfo = type.GetField(fieldName, 21);105
 if (fieldInfo == null)
      if (fieldInfo == null)106
 {
      {107
 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
        throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));108
 }
      }109
 else
      else110
 {
      {111
 return fieldInfo;
        return fieldInfo;112
 }
      }113
 }
    }114
 }
  }115

116
 }
}117

 
                    
                     
                    
                 
                    
                 
 
        

 
   
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号