/// <summary> /// 获取属性成员集合 /// </summary> /// <param name="properties">属性成员集合</param> /// <param name="typeAttribute">类型配置</param> /// <returns>属性成员集合</returns> public static LeftArray <KeyValue <PropertyIndex, MethodInfo> > GetProperties(PropertyIndex[] properties, SerializeAttribute typeAttribute) { LeftArray <KeyValue <PropertyIndex, MethodInfo> > values = new LeftArray <KeyValue <PropertyIndex, MethodInfo> >(properties.Length); foreach (PropertyIndex property in properties) { if (property.Member.CanRead) { 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)) { SerializeMemberAttribute attribute = property.GetAttribute <SerializeMemberAttribute>(typeAttribute.IsBaseTypeAttribute); if (typeAttribute.IsAttribute ? (attribute != null && attribute.IsSetup) : (attribute == null || attribute.IsSetup)) { MethodInfo method = property.Member.GetGetMethod(true); if (method != null && method.GetParameters().Length == 0) { values.Add(new KeyValue <PropertyIndex, MethodInfo>(property, method)); } } } } } return(values); }
/// <summary> /// 获取字段成员集合 /// </summary> /// <param name="fields"></param> /// <param name="typeAttribute">类型配置</param> /// <returns>字段成员集合</returns> public static LeftArray <FieldIndex> GetFields(FieldIndex[] fields, SerializeAttribute typeAttribute) { 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)) { SerializeMemberAttribute attribute = field.GetAttribute <SerializeMemberAttribute>(typeAttribute.IsBaseTypeAttribute); if (typeAttribute.IsAttribute ? (attribute != null && attribute.IsSetup) : (attribute == null || attribute.IsSetup)) { values.Add(field); } } } return(values); }