示例#1
0
                /// <summary>
                /// 设置字段信息
                /// </summary>
                /// <param name="field"></param>
                public void Set(KeyValue <FieldIndex, MemberAttribute> field)
                {
                    this.field = field.Key.Member;
                    Name       = field.Key.AnonymousName;
                    if (field.Value != null)
                    {
                        itemName = field.Value.ItemName;
                    }
                    MemberIndex = field.Key.MemberIndex;
                    MethodInfo method = SerializeMethodCache.GetIsOutputMethod(this.field.FieldType);

                    if (method != null)
                    {
                        isOutputMethod = (Func <Serializer, object, bool>) typeof(AutoCSer.Reflection.InvokeMethodReturn <, ,>).MakeGenericType(typeof(Serializer), this.field.FieldType, typeof(bool)).GetMethod("getTypeObjectReturnType", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                    bool isCustom = false;

                    method = SerializeMethodCache.GetMemberMethodInfo(this.field.FieldType, ref isCustom);
                    if (isCustom)
                    {
                        customSerializeMethod = (Action <object, Serializer>) typeof(AutoCSer.Reflection.InvokeMethodRef1 <,>).MakeGenericType(this.field.FieldType, typeof(Serializer)).GetMethod("getObjectType", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                    else
                    {
                        serializeMethod = (Action <Serializer, object>) typeof(AutoCSer.Reflection.InvokeMethod <,>).MakeGenericType(typeof(Serializer), this.field.FieldType).GetMethod("getTypeObject", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                }
        /// <summary>
        /// 添加属性
        /// </summary>
        /// <param name="property">属性信息</param>
        /// <param name="propertyMethod">函数信息</param>
        public void PushBox(PropertyIndex property, MethodInfo propertyMethod)
        {
            Label      end            = default(Label);
            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(property.Member.PropertyType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse, end = generator.DefineLabel());
            }

            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(property.Member.PropertyType, ref isCustom);

            if (isCustom)
            {
                LocalBuilder loadMember = generator.DeclareLocal(property.Member.PropertyType);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
                generator.Emit(OpCodes.Stloc_0);
                generator.Emit(OpCodes.Ldloca_S, loadMember);
                generator.Emit(OpCodes.Ldarg_0);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
            }
            generator.call(method);

            if (isOutputMethod != null)
            {
                generator.MarkLabel(end);
            }
        }
示例#3
0
                /// <summary>
                /// 设置属性信息
                /// </summary>
                /// <param name="property"></param>
                public void Set(PropertyMethod property)
                {
                    this.PropertyInfo = property.Property.Member;
                    if (PropertyInfo.DeclaringType.IsValueType)
                    {
                        getMethod = (Func <object, object>) typeof(AutoCSer.Reflection.InvokeMethodRefReturn <,>).MakeGenericType(PropertyInfo.DeclaringType, PropertyInfo.PropertyType).GetMethod("getObjectReturn", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { PropertyInfo.GetGetMethod(true) });
                    }
                    else
                    {
                        getMethod = (Func <object, object>) typeof(AutoCSer.Reflection.InvokeMethodReturn <,>).MakeGenericType(PropertyInfo.DeclaringType, PropertyInfo.PropertyType).GetMethod("getObjectReturn", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { PropertyInfo.GetGetMethod(true) });
                    }
                    if (property.Attribute != null)
                    {
                        itemName = property.Attribute.ItemName;
                    }
                    MemberIndex = property.Property.MemberIndex;
                    MethodInfo method = SerializeMethodCache.GetIsOutputMethod(this.PropertyInfo.PropertyType);

                    if (method != null)
                    {
                        isOutputMethod = (Func <Serializer, object, bool>) typeof(AutoCSer.Reflection.InvokeMethodReturn <, ,>).MakeGenericType(typeof(Serializer), this.PropertyInfo.PropertyType, typeof(bool)).GetMethod("getTypeObjectReturnType", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                    bool isCustom = false;

                    method = SerializeMethodCache.GetMemberMethodInfo(this.PropertyInfo.PropertyType, ref isCustom);
                    if (isCustom)
                    {
                        customSerializeMethod = (Action <object, Serializer>) typeof(AutoCSer.Reflection.InvokeMethodRef1 <,>).MakeGenericType(PropertyInfo.PropertyType, typeof(Serializer)).GetMethod("getObjectType", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                    else
                    {
                        serializeMethod = (Action <Serializer, object>) typeof(AutoCSer.Reflection.InvokeMethod <,>).MakeGenericType(typeof(Serializer), PropertyInfo.PropertyType).GetMethod("getTypeObject", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { method });
                    }
                }
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="field">字段信息</param>
        public void PushBox(FieldIndex field)
        {
            Label      end            = default(Label);
            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(field.Member.FieldType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse, end = generator.DefineLabel());
            }
            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(field.Member.FieldType, ref isCustom);

            if (isCustom)
            {
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldflda, field.Member);
                generator.Emit(OpCodes.Ldarg_0);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
            }
            generator.call(method);

            if (isOutputMethod != null)
            {
                generator.MarkLabel(end);
            }
        }
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="field">字段信息</param>
        /// <param name="attribute">XML序列化成员配置</param>
        public void Push(FieldIndex field, MemberAttribute attribute)
        {
            Label      end            = default(Label);
            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(field.Member.FieldType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse, end = generator.DefineLabel());
            }

            string name = field.AnonymousName;

            nameStart(name, attribute);
            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(field.Member.FieldType, ref isCustom);

            if (isCustom)
            {
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldflda, field.Member);
                generator.Emit(OpCodes.Ldarg_0);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
            }
            generator.call(method);

            WriteName(generator, OpCodes.Ldloc_0, name, true);

            if (isOutputMethod != null)
            {
                generator.MarkLabel(end);
            }
        }
示例#6
0
        /// <summary>
        /// 添加属性
        /// </summary>
        /// <param name="property">属性信息</param>
        /// <param name="propertyMethod">函数信息</param>
        /// <param name="attribute">XML序列化成员配置</param>
        public void Push(PropertyIndex property, MethodInfo propertyMethod, MemberAttribute attribute)
        {
            Label      end            = default(Label);
            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(property.Member.PropertyType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse_S, end = generator.DefineLabel());
            }

            nameStart(property.Member.Name, attribute);
            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(property.Member.PropertyType, ref isCustom);

            if (isCustom)
            {
                LocalBuilder loadMember = generator.DeclareLocal(property.Member.PropertyType);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
                generator.Emit(OpCodes.Stloc_0);
                generator.Emit(OpCodes.Ldloca_S, loadMember);
                generator.Emit(OpCodes.Ldarg_0);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_0);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 1);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_1);
                }
                generator.call(propertyMethod);
            }
            generator.call(method);

            generator.charStreamSimpleWriteNotNull(OpCodes.Ldloc_0, SerializeMethodCache.GetNameEndPool(property.Member.Name), property.Member.Name.Length + 3);

            if (isOutputMethod != null)
            {
                generator.MarkLabel(end);
            }
        }
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="field">字段信息</param>
        /// <param name="attribute">XML序列化成员配置</param>
        public void Push(FieldIndex field, MemberAttribute attribute)
        {
            Label end = generator.DefineLabel();

            generator.memberMapIsMember(OpCodes.Ldarg_0, field.MemberIndex);
            generator.Emit(OpCodes.Brfalse, end);

            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(field.Member.FieldType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_1);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse, end);
            }
            string name = field.AnonymousName;

            SerializeMemberDynamicMethod.WriteName(generator, OpCodes.Ldloc_0, name, false);

            if (attribute != null && attribute.ItemName != null)
            {
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldstr, attribute.ItemName);
                generator.Emit(OpCodes.Stfld, SerializeMemberDynamicMethod.ItemNameField);
            }
            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(field.Member.FieldType, ref isCustom);

            if (isCustom)
            {
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.Emit(OpCodes.Ldflda, field.Member);
                generator.Emit(OpCodes.Ldarg_1);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_1);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.Emit(OpCodes.Ldfld, field.Member);
            }
            generator.call(method);

            SerializeMemberDynamicMethod.WriteName(generator, OpCodes.Ldloc_0, name, true);

            generator.MarkLabel(end);
        }
        /// <summary>
        /// 添加属性
        /// </summary>
        /// <param name="property">属性信息</param>
        /// <param name="propertyMethod">函数信息</param>
        /// <param name="attribute">XML序列化成员配置</param>
        public void Push(PropertyIndex property, MethodInfo propertyMethod, MemberAttribute attribute)
        {
            Label end = generator.DefineLabel();

            generator.memberMapIsMember(OpCodes.Ldarg_0, property.MemberIndex);
            generator.Emit(OpCodes.Brfalse, end);

            MethodInfo isOutputMethod = SerializeMethodCache.GetIsOutputMethod(property.Member.PropertyType);

            if (isOutputMethod != null)
            {
                generator.Emit(OpCodes.Ldarg_1);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.call(propertyMethod);
                generator.call(isOutputMethod);
                generator.Emit(OpCodes.Brfalse, end);
            }
            SerializeMemberDynamicMethod.WriteName(generator, OpCodes.Ldloc_0, property.Member.Name, false);

            if (attribute != null && attribute.ItemName != null)
            {
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldstr, attribute.ItemName);
                generator.Emit(OpCodes.Stfld, SerializeMemberDynamicMethod.ItemNameField);
            }
            bool       isCustom = false;
            MethodInfo method   = SerializeMethodCache.GetMemberMethodInfo(property.Member.PropertyType, ref isCustom);

            if (isCustom)
            {
                LocalBuilder loadMember = generator.DeclareLocal(property.Member.PropertyType);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.call(propertyMethod);
                generator.Emit(OpCodes.Stloc_0);
                generator.Emit(OpCodes.Ldloca_S, loadMember);
                generator.Emit(OpCodes.Ldarg_1);
            }
            else
            {
                generator.Emit(OpCodes.Ldarg_1);
                if (isValueType)
                {
                    generator.Emit(OpCodes.Ldarga_S, 2);
                }
                else
                {
                    generator.Emit(OpCodes.Ldarg_2);
                }
                generator.call(propertyMethod);
            }
            generator.call(method);

            SerializeMemberDynamicMethod.WriteName(generator, OpCodes.Ldloc_0, property.Member.Name, true);

            generator.MarkLabel(end);
        }