/// <summary>
 /// 生成序列化代码
 /// </summary>
 /// <param name="g"></param>
 public virtual void GenerateSerializeIL(MethodGenerator g)
 {
     //serializer.serialize(v); 或 //writer.Writer(v);
     SerializationMethodHelper.Write(g, this.DTOMemberName, this.TargetType, (argType) =>
     {
         LoadMemberValue(g);
         //TargetType是成员(也就是属性或者字段)的类型
         //argType是方法需要接受到的类型,如果两者类型不匹配,就需要转换
         if (this.TargetType.IsStruct() && !argType.IsStruct())
         {
             g.Box();
         }
     });
 }
예제 #2
0
        /// <summary>
        /// 加载成员的值到堆栈上
        /// </summary>
        protected void LoadMemberValue(MethodGenerator g)
        {
            LoadOwner(g);

            if (this.IsClassInfo)
            {
                return;
            }
            if (this.IsFieldInfo)
            {
                g.LoadField(this.FieldInfo);
            }
            else
            {
                g.LoadProperty(this.PropertyInfo);
            }

            if (this.TargetType.IsStruct())
            {
                g.Box();
            }
        }