在源中可以找到提示:
从DefaultContractResolver.cs,行1254:
private void SetPropertySettingsFromAttributes(JsonProperty property,object attributeProvider,string name,Type declaringType,MemberSerialization memberSerialization,out bool allowNonPublicAccess) { ... // resolve converter for property // the class type might have a converter but the property converter takes presidence property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider);
并从JsonSerializerInternalReader.cs,line 348:
private JsonConverter GetConverter(JsonContract contract,JsonConverter memberConverter,JsonContainerContract containerContract,JsonProperty containerProperty) { JsonConverter converter = null; if (memberConverter != null) { // member attribute converter converter = memberConverter; } else if (containerProperty != null && containerProperty.ItemConverter != null) { converter = containerProperty.ItemConverter; } else if (containerContract != null && containerContract.ItemConverter != null) { converter = containerContract.ItemConverter; } else if (contract != null) { JsonConverter matchingConverter; if (contract.Converter != null) // class attribute converter converter = contract.Converter; else if ((matchingConverter = Serializer.GetMatchingConverter(contract.UnderlyingType)) != null) // passed in converters converter = matchingConverter; else if (contract.InternalConverter != null) // internally specified converter converter = contract.InternalConverter; } return converter; }