/// <summary> /// 添加字段 /// </summary> /// <param name="field">字段信息</param> public void Push(FieldIndex field) { isName(); bool isCustom = false; MethodInfo method = DeSerializeMethodCache.GetMemberMethodInfo(field.Member.FieldType, ref isCustom); if (isCustom) { generator.Emit(OpCodes.Ldarg_1); if (!isValueType) { generator.Emit(OpCodes.Ldind_Ref); } generator.Emit(OpCodes.Ldflda, field.Member); generator.Emit(OpCodes.Ldarg_0); } else { generator.Emit(OpCodes.Ldarg_0); generator.Emit(OpCodes.Ldarg_1); if (!isValueType) { generator.Emit(OpCodes.Ldind_Ref); } generator.Emit(OpCodes.Ldflda, field.Member); } generator.call(method); nextIndex(); if (isMemberMap) { generator.memberMapSetMember(OpCodes.Ldarg_3, field.MemberIndex); } }
/// <summary> /// 添加属性 /// </summary> /// <param name="property">属性信息</param> /// <param name="propertyMethod">函数信息</param> public void Push(PropertyIndex property, MethodInfo propertyMethod) { isName(); Type memberType = property.Member.PropertyType; LocalBuilder loadMember = generator.DeclareLocal(memberType); generator.initobj(memberType, loadMember); bool isCustom = false; MethodInfo method = DeSerializeMethodCache.GetMemberMethodInfo(memberType, ref isCustom); if (isCustom) { generator.Emit(OpCodes.Ldloca, loadMember); generator.Emit(OpCodes.Ldarg_0); } else { generator.Emit(OpCodes.Ldarg_0); generator.Emit(OpCodes.Ldloca, loadMember); } generator.call(method); generator.Emit(OpCodes.Ldarg_1); if (!isValueType) { generator.Emit(OpCodes.Ldind_Ref); } generator.Emit(OpCodes.Ldloc, loadMember); generator.call(propertyMethod); nextIndex(); if (isMemberMap) { generator.memberMapSetMember(OpCodes.Ldarg_3, property.MemberIndex); } }