public IsAllowedToBeSerialized ( YAXSerializationFields serializationFields, bool dontSerializePropertiesWithNoSetter ) : bool | ||
serializationFields | YAXSerializationFields | The serialization fields. |
dontSerializePropertiesWithNoSetter | bool | |
return | bool |
public bool IsAllowedToBeSerialized(YAXSerializationFields serializationFields, bool dontSerializePropertiesWithNoSetter)
{
if (dontSerializePropertiesWithNoSetter && m_isProperty && !m_propertyInfoInstance.CanWrite)
return false;
if (serializationFields == YAXSerializationFields.AllFields)
return !IsAttributedAsDontSerialize;
else if (serializationFields == YAXSerializationFields.AttributedFieldsOnly)
return !IsAttributedAsDontSerialize && IsAttributedAsSerializable;
else if (serializationFields == YAXSerializationFields.PublicPropertiesOnly)
return !IsAttributedAsDontSerialize && m_isProperty && ReflectionUtils.IsPublicProperty(m_propertyInfoInstance);
else
throw new Exception("Unknown serialization field option");
}
/// <summary> /// Gets the sequence of fields to be serialized for the specified type. This sequence is retreived according to /// the field-types specified by the user. /// </summary> /// <param name="typeWrapper">The type wrapper for the type whose serializable /// fields is going to be retreived.</param> /// <returns>the sequence of fields to be serialized for the specified type</returns> private IEnumerable<MemberWrapper> GetFieldsToBeSerialized(UdtWrapper typeWrapper) { foreach (var member in typeWrapper.UnderlyingType.GetMembers(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { char name0 = member.Name[0]; if ((Char.IsLetter(name0) || name0 == '_') && (member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Field)) { if((typeWrapper.IsCollectionType || typeWrapper.IsDictionaryType)) //&& typeWrapper.IsAttributedAsNotCollection) if(ReflectionUtils.IsPartOfNetFx(member)) continue; var memInfo = new MemberWrapper(member, this); if (memInfo.IsAllowedToBeSerialized(typeWrapper.FieldsToSerialize)) { yield return memInfo; } } } }