System.Object

using System.Runtime.InteropServices;

using System.Runtime.CompilerServices;

using System.Runtime.ConstrainedExecution;

using System.Reflection;

using System.Globalization;

using System.Runtime.Remoting;

namespace System

{

[Serializable,ComVisible(true),ClassInterface(ClassInterfaceType.AutoDual)]

public class Object

{

        [ReliabilityContract(Consistency.WillNotCorruptState,Cer.MayFail)]    

public Object()

{

            //.maxstack  8

            //IL_0000:  ret

}

        /// <summary>

        /// return this.GetType().ToString();

        /// </summary>

        /// <returns></returns>

        public new virtual string ToString()

        {

            //.maxstack  8

            //IL_0000:  ldarg.0

            //IL_0001:  call       instance class System.Type System.Object::GetType()

            //IL_0006:  callvirt   instance string System.Object::ToString()

            //IL_000b:  ret

            return this.GetType().ToString();

        }

        public new virtual bool Equals(object obj)

        {

            //.maxstack  8

            //IL_0000:  ldarg.0

            //IL_0001:  ldarg.1

            //IL_0002:  call       bool System.Object::InternalEquals(object,object)

            //IL_0007:  ret

            return InternalEquals(this,obj);

        }

        [MethodImpl(MethodImplAttributes.InternalCall)]

        internal static bool InternalEquals(object objA,object objB)

        {

            //internalcall

        }

        /// <summary>

        /// 对象地址相同返回true,如果不同而两者皆非null,则返回objA.Equals(objB),有null者返回false。

        /// 地址由native int(IL)表示,对应于BCL中的System.IntPtr,其大小取决于操作系统平台字长可为32/64位

        /// 同时可知System.Object.Equals(null,null)==true,对象变量为null表示地址为初始值0,意即未指向有效对象。

        /// </summary>

        /// <param name="objA"></param>

        /// <param name="objB"></param>

        /// <returns></returns>

        public static bool Equals(object objA, object objB)

        {

            //.maxstack  8

            //IL_0000:  ldarg.0

            //IL_0001:  ldarg.1

            //IL_0002:  bne.un.s   IL_0006

 

            //IL_0004:  ldc.i4.1

            //IL_0005:  ret

 

            //IL_0006:  ldarg.0

            //IL_0007:  brfalse.s  IL_000c

 

            //IL_0009:  ldarg.1

            //IL_000a:  brtrue.s   IL_000e

 

            //IL_000c:  ldc.i4.0

            //IL_000d:  ret

 

            //IL_000e:  ldarg.0

            //IL_000f:  ldarg.1

            //IL_0010:  callvirt   instance bool System.Object::Equals(object)

            //IL_0015:  ret

 

            if (objA == objB)

            {

                return true;

            }

            else

            {

                if (objA != null && objB != null)

                {

                    return objA.Equals(objB);

                }

                else

                {

                    return false;

                }

            }

            //关于相等运算符的csharp解析:

            //查找是否有匹配等号两边类型的==运算符过载(顺序也必须一致),并调用之。

            //如果没有,对于同是引用类型的直接比较两者的地址(ceq,beq),

            //对于同为primitive type值类型直接可以转换成简单的IL指令;

            //其他情况csharp无法解析,抛出异常。

 

        }

        /// <summary>

        /// 直接比较对象地址

        /// </summary>

        /// <param name="objA"></param>

        /// <param name="objB"></param>

        /// <returns></returns>

        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]

        public static bool ReferenceEquals(object objA,object objB)

        {

            //.maxstack  8

            //IL_0000:  ldarg.0

            //IL_0001:  ldarg.1

            //IL_0002:  ceq

            //IL_0004:  ret

            if (objA == objB)

            {

                return true;

            }

            else

            {

                return false;

            }

        }

        public new virtual int GetHashCode()

        {

            //.maxstack  8

            //IL_0000:  ldarg.0

            //IL_0001:  call       int32 System.Object::InternalGetHashCode(object)

            //IL_0006:  ret

            return InternalGetHashCode(this);

        }

        [MethodImpl(MethodImplAttributes.InternalCall)]

        internal static int InternalGetHashCode(object obj)

        {

            //internalcall

        }

        [MethodImpl(MethodImplAttributes.InternalCall)]

        public Type GetType()

        {

            //internalcall

        }

        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]

        protected virtual ~Object()

        {

            //.maxstack  8

            //IL_0000:  ret

        }

        [MethodImpl(MethodImplAttributes.InternalCall)]

        protected object MemberwiseClone()

        {

            //internalcall

        }

        /// <summary>

        /// 利用GetFieldInfo找到相应字段,然后利用反射技术(FieldInfo.SetValue())将值改为val;

        /// 修改前发送相应的字段值修改通知。

        /// </summary>

        /// <param name="typeName"></param>

        /// <param name="fieldName"></param>

        /// <param name="val"></param>

        private void FieldSetter(string typeName, string fieldName, object val)

        {

            //.maxstack  3

            //.locals init (class System.Reflection.FieldInfo V_0)

            //IL_0000:  ldarg.0

            //IL_0001:  ldarg.1

            //IL_0002:  ldarg.2

            //IL_0003:  call       instance class System.Reflection.FieldInfo System.Object::GetFieldInfo(string,

            //                                                                                            string)

            //IL_0008:  stloc.0

            //IL_0009:  ldloc.0

            //IL_000a:  callvirt   instance bool System.Reflection.FieldInfo::get_IsInitOnly()

            //IL_000f:  brfalse.s  IL_0021

 

            //IL_0011:  ldstr      "FieldAccess_InitOnly"

            //IL_0016:  call       string System.Environment::GetResourceString(string)

            //IL_001b:  newobj     instance void System.FieldAccessException::.ctor(string)

            //IL_0020:  throw

 

            //IL_0021:  ldarg.3

            //IL_0022:  ldloc.0

            //IL_0023:  callvirt   instance class System.Type System.Reflection.FieldInfo::get_FieldType()

            //IL_0028:  call       object System.Runtime.Remoting.Messaging.Message::CoerceArg(object,

            //                                                                                 class System.Type)

            //IL_002d:  pop

            //IL_002e:  ldloc.0

            //IL_002f:  ldarg.0

            //IL_0030:  ldarg.3

            //IL_0031:  callvirt   instance void System.Reflection.FieldInfo::SetValue(object,

            //                                                                         object)

            //IL_0036:  ret

            FieldInfo V_0;

            V_0 = this.GetFieldInfo(typeName, fieldName);

            if (V_0.IsInitOnly)

            {

                throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));

            }

            else

            {

                System.Runtime.Remoting.Messaging.Message.CoerceArg(val, V_0.FieldType);

                V_0.SetValue(this, val);

            }

        }

        /// <summary>

        /// 利用GetFieldInfo找到相应字段,然后利用反射技术(FieldInfo.GetValue())返回字段值,并将它赋予val

        /// </summary>

        /// <param name="typeName"></param>

        /// <param name="fieldName"></param>

        /// <param name="val"></param>

        private void FieldGetter(string typeName, string fieldName, ref object val)

        {

            //.maxstack  3

            //.locals init (class System.Reflection.FieldInfo V_0)

            //IL_0000:  ldarg.0

            //IL_0001:  ldarg.1

            //IL_0002:  ldarg.2

            //IL_0003:  call       instance class System.Reflection.FieldInfo System.Object::GetFieldInfo(string,

            //                                                                                            string)

            //IL_0008:  stloc.0

            //IL_0009:  ldarg.3

            //IL_000a:  ldloc.0

            //IL_000b:  ldarg.0

            //IL_000c:  callvirt   instance object System.Reflection.FieldInfo::GetValue(object)

            //IL_0011:  stind.ref

            //IL_0012:  ret

            FieldInfo V_0;

            V_0 = this.GetFieldInfo(typeName, fieldName);

            val=V_0.GetValue(this);

 

        }

        /// <summary>

        /// 利用反射技术(Type.GetField())从本对象中获取指定类型的指定属性,该指定类型应该是本对象的适配类型,否者将抛出错误。

        /// 先获取本对象类型的FullName与指定typeName进行比对,然后逐层与父类型FullName比较,直到最终匹配或者父类型为Null为止;

        /// 如果没有找到匹配类型则抛出错误。       

        /// </summary>

        /// <param name="typeName">指定类型的FullName,本类型或者其父类型</param>

        /// <param name="fieldName">指定的字段名称,它的修饰符是:BindingFlags.Public|BindingFlags.Instance|BindingFlags.IgnoreCase</param>

        /// <returns></returns>

        private System.Reflection.FieldInfo GetFieldInfo(string typeName, string fieldName)

        {

            //.maxstack  5

            //.locals init (class System.Type V_0,

            //         class System.Reflection.FieldInfo V_1,

            //         object[] V_2,

            //         object[] V_3)

            //IL_0000:  ldarg.0

            //IL_0001:  call       instance class System.Type System.Object::GetType()

            //IL_0006:  stloc.0

            //IL_0007:  br.s       IL_001e

 

            //IL_0009:  ldloc.0

            //IL_000a:  callvirt   instance string System.Type::get_FullName()

            //IL_000f:  ldarg.1

            //IL_0010:  callvirt   instance bool System.String::Equals(string)

            //IL_0015:  brtrue.s   IL_0021

 

            //IL_0017:  ldloc.0

            //IL_0018:  callvirt   instance class System.Type System.Type::get_BaseType()

            //IL_001d:  stloc.0

            //IL_001e:  ldloc.0

            //IL_001f:  brtrue.s   IL_0009

 

            //IL_0021:  ldloc.0

            //IL_0022:  brtrue.s   IL_004a

 

            //IL_0024:  call       class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()

            //IL_0029:  ldstr      "Remoting_BadType"

            //IL_002e:  call       string System.Environment::GetResourceString(string)

            //IL_0033:  ldc.i4.1

            //IL_0034:  newarr     System.Object

            //IL_0039:  stloc.2

            //IL_003a:  ldloc.2

            //IL_003b:  ldc.i4.0

            //IL_003c:  ldarg.1

            //IL_003d:  stelem.ref

            //IL_003e:  ldloc.2

            //IL_003f:  call       string System.String::Format(class System.IFormatProvider,

            //                                                  string,

            //                                                  object[])

            //IL_0044:  newobj     instance void System.Runtime.Remoting.RemotingException::.ctor(string)

            //IL_0049:  throw

 

            //IL_004a:  ldloc.0

            //IL_004b:  ldarg.2

            //IL_004c:  ldc.i4.s   21

            //IL_004e:  callvirt   instance class System.Reflection.FieldInfo System.Type::GetField(string,

            //                                                                                      valuetype System.Reflection.BindingFlags)

            //IL_0053:  stloc.1

            //IL_0054:  ldloc.1

            //IL_0055:  brtrue.s   IL_0081

 

            //IL_0057:  call       class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()

            //IL_005c:  ldstr      "Remoting_BadField"

            //IL_0061:  call       string System.Environment::GetResourceString(string)

            //IL_0066:  ldc.i4.2

            //IL_0067:  newarr     System.Object

            //IL_006c:  stloc.3

            //IL_006d:  ldloc.3

            //IL_006e:  ldc.i4.0

            //IL_006f:  ldarg.2

            //IL_0070:  stelem.ref

            //IL_0071:  ldloc.3

            //IL_0072:  ldc.i4.1

            //IL_0073:  ldarg.1

            //IL_0074:  stelem.ref

            //IL_0075:  ldloc.3

            //IL_0076:  call       string System.String::Format(class System.IFormatProvider,

            //                                                  string,

            //                                                  object[])

            //IL_007b:  newobj     instance void System.Runtime.Remoting.RemotingException::.ctor(string)

            //IL_0080:  throw

 

            //IL_0081:  ldloc.1

            //IL_0082:  ret

            Type V_0;

            FieldInfo V_1;

            object[] V_2, V_3;

            V_0 = this.GetType();

            //IL0009

            if (V_0.FullName.Equals(typeName))//真的话跳往IL_0021

            {

                //IL_0021

                if (V_0 != null)//真的话跳往IL_004a

                {

                    V_1=V_0.GetField(fieldName, BindingFlags.Public|BindingFlags.Instance|BindingFlags.IgnoreCase);

                }

 

            }

            else

            {

                do

                {

                    V_0 = V_0.BaseType;

                }while (!V_0.FullName.Equals(typeName)&&(V_0!=null));

                if (V_0 != null)//真的话跳往IL_004a

                {

                    V_1 = V_0.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);

                }

                else

                {

                    V_2 = new object[1];

                    V_2[0] = typeName;

                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), V_2));

                }                 

            }

            if (V_1 == null)//为假的时候跳往IL_0081

            {

                V_3=new object[2];

                V_3[0]=fieldName;

                V_3[1]=typeName;

                throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadField"), V_3));

            }

            else   //IL_0081

            {

                return V_1;

            }

 

 

 

        }

 

 

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值