.Net System.Object 对象实现代码
1// Decompiled by Salamander version 1.0.6
2// Copyright 2002 Remotesoft Inc. All rights reserved.
3// http://www.remotesoft.com/salamander
4
5using System.Reflection;
6using System.Runtime;
7using System.Runtime.Remoting;
8using System.Runtime.Remoting.Messaging;
9
10namespace System
11{
12 [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
13 [SerializableAttribute()]
14 public class Object
15 {
16
17 public Object()
18 {
19 }
20
21 // internalcall
22 private Type InternalGetType();
23
24 // internalcall
25 private Type FastGetExistingType();
26
27 public virtual string ToString()
28 {
29 return GetType().FullName;
30 }
31
32 // internalcall
33 public virtual bool Equals(object obj);
34
35 public static bool Equals(object objA, object objB)
36 {
37 if (objA == objB)
38 {
39 return true;
40 }
41 if (objA == null || objB == null)
42 {
43 return false;
44 }
45 else
46 {
47 return objA.Equals(objB);
48 }
49 }
50
51 public static bool ReferenceEquals(object objA, object objB)
52 {
53 return objA == objB;
54 }
55
56 // internalcall
57 public virtual int GetHashCode();
58
59 public Type GetType()
60 {
61 Type type = FastGetExistingType();
62 if (type == null)
63 {
64 type = InternalGetType();
65 }
66 return type;
67 }
68
69 ~Object()
70 {
71 }
72
73 // internalcall
74 protected object MemberwiseClone();
75
76 private void FieldSetter(string typeName, string fieldName, object val)
77 {
78 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
79 if (fieldInfo.IsInitOnly)
80 {
81 throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
82 }
83 Message.CoerceArg(val, fieldInfo.FieldType);
84 fieldInfo.SetValue(this, val);
85 }
86
87 private void FieldGetter(string typeName, string fieldName, ref object val)
88 {
89 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
90 val = fieldInfo.GetValue(this);
91 }
92
93 private FieldInfo GetFieldInfo(string typeName, string fieldName)
94 {
95 Type type;
96
97 for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)
98 {
99 }
100 if (type == null)
101 {
102 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));
103 }
104 FieldInfo fieldInfo = type.GetField(fieldName, 21);
105 if (fieldInfo == null)
106 {
107 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
108 }
109 else
110 {
111 return fieldInfo;
112 }
113 }
114 }
115
116}
117
2// Copyright 2002 Remotesoft Inc. All rights reserved.
3// http://www.remotesoft.com/salamander
4
5using System.Reflection;
6using System.Runtime;
7using System.Runtime.Remoting;
8using System.Runtime.Remoting.Messaging;
9
10namespace System
11{
12 [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
13 [SerializableAttribute()]
14 public class Object
15 {
16
17 public Object()
18 {
19 }
20
21 // internalcall
22 private Type InternalGetType();
23
24 // internalcall
25 private Type FastGetExistingType();
26
27 public virtual string ToString()
28 {
29 return GetType().FullName;
30 }
31
32 // internalcall
33 public virtual bool Equals(object obj);
34
35 public static bool Equals(object objA, object objB)
36 {
37 if (objA == objB)
38 {
39 return true;
40 }
41 if (objA == null || objB == null)
42 {
43 return false;
44 }
45 else
46 {
47 return objA.Equals(objB);
48 }
49 }
50
51 public static bool ReferenceEquals(object objA, object objB)
52 {
53 return objA == objB;
54 }
55
56 // internalcall
57 public virtual int GetHashCode();
58
59 public Type GetType()
60 {
61 Type type = FastGetExistingType();
62 if (type == null)
63 {
64 type = InternalGetType();
65 }
66 return type;
67 }
68
69 ~Object()
70 {
71 }
72
73 // internalcall
74 protected object MemberwiseClone();
75
76 private void FieldSetter(string typeName, string fieldName, object val)
77 {
78 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
79 if (fieldInfo.IsInitOnly)
80 {
81 throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
82 }
83 Message.CoerceArg(val, fieldInfo.FieldType);
84 fieldInfo.SetValue(this, val);
85 }
86
87 private void FieldGetter(string typeName, string fieldName, ref object val)
88 {
89 FieldInfo fieldInfo = GetFieldInfo(typeName, fieldName);
90 val = fieldInfo.GetValue(this);
91 }
92
93 private FieldInfo GetFieldInfo(string typeName, string fieldName)
94 {
95 Type type;
96
97 for (type = GetType(); type != null && !type.FullName.Equals(typeName); type = type.BaseType)
98 {
99 }
100 if (type == null)
101 {
102 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadType"), typeName));
103 }
104 FieldInfo fieldInfo = type.GetField(fieldName, 21);
105 if (fieldInfo == null)
106 {
107 throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_BadField"), fieldName, typeName));
108 }
109 else
110 {
111 return fieldInfo;
112 }
113 }
114 }
115
116}
117
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 语音处理 开源项目 EchoSharp
· 《HelloGitHub》第 106 期
· Huawei LiteOS基于Cortex-M4 GD32F4平台移植
· mysql8.0无备份通过idb文件恢复数据过程、idb文件修复和tablespace id不一致处