Пример #1
0
        /// <summary>
        /// 获取属性成员集合
        /// </summary>
        /// <param name="properties">属性成员集合</param>
        /// <param name="typeAttribute">类型配置</param>
        /// <returns>属性成员集合</returns>
        public static LeftArray <KeyValue <PropertyIndex, MethodInfo> > GetProperties(PropertyIndex[] properties, JsonDeSerializeAttribute typeAttribute)
        {
            LeftArray <KeyValue <PropertyIndex, MethodInfo> > values = new LeftArray <KeyValue <PropertyIndex, MethodInfo> >(properties.Length);

            foreach (PropertyIndex property in properties)
            {
                if (property.Member.CanWrite)
                {
                    Type type = property.Member.PropertyType;
                    if (!type.IsPointer && (!type.IsArray || type.GetArrayRank() == 1) && !property.IsIgnore && !typeof(Delegate).IsAssignableFrom(type) && !property.Member.IsDefined(typeof(IgnoreMemberAttribute), typeAttribute.IsBaseTypeAttribute))
                    {
                        JsonDeSerializeMemberAttribute attribute = property.GetAttribute <JsonDeSerializeMemberAttribute>(typeAttribute.IsBaseTypeAttribute);
                        if (typeAttribute.IsAttribute ? (attribute != null && attribute.IsSetup) : (attribute == null || attribute.IsSetup))
                        {
                            MethodInfo method = property.Member.GetSetMethod(true);
                            if (method != null && method.GetParameters().Length == 1)
                            {
                                values.Add(new KeyValue <PropertyIndex, MethodInfo>(property, method));
                            }
                        }
                    }
                }
            }
            return(values);
        }
Пример #2
0
        /// <summary>
        /// 获取字段成员集合
        /// </summary>
        /// <param name="fields"></param>
        /// <param name="typeAttribute">类型配置</param>
        /// <param name="defaultMember">默认解析字段</param>
        /// <returns>字段成员集合</returns>
        public static LeftArray <FieldIndex> GetFields(FieldIndex[] fields, JsonDeSerializeAttribute typeAttribute, ref FieldIndex defaultMember)
        {
            LeftArray <FieldIndex> values = new LeftArray <FieldIndex>(fields.Length);

            foreach (FieldIndex field in fields)
            {
                Type type = field.Member.FieldType;
                if (!type.IsPointer && (!type.IsArray || type.GetArrayRank() == 1) && !field.IsIgnore && !typeof(Delegate).IsAssignableFrom(type) && !field.Member.IsDefined(typeof(IgnoreMemberAttribute), typeAttribute.IsBaseTypeAttribute))
                {
                    JsonDeSerializeMemberAttribute attribute = field.GetAttribute <JsonDeSerializeMemberAttribute>(typeAttribute.IsBaseTypeAttribute);
                    if (typeAttribute.IsAttribute ? (attribute != null && attribute.IsSetup) : (attribute == null || attribute.IsSetup))
                    {
                        if (attribute != null && attribute.IsDefault)
                        {
                            defaultMember = field;
                        }
                        values.Add(field);
                    }
                }
            }
            return(values);
        }