internal BinaryConverter DetermineConverter(Type parentClassType, Type runtimePropertyType, MemberInfo memberInfo) { BinaryConverter converter = null !; // Priority 1: attempt to get converter from BinaryConverterAttribute on property. if (memberInfo != null) { Debug.Assert(parentClassType != null); BinaryConverterAttribute converterAttribute = (BinaryConverterAttribute) GetAttributeThatCanHaveMultiple(parentClassType !, typeof(BinaryConverterAttribute), memberInfo); if (converterAttribute != null) { converter = GetConverterFromAttribute(converterAttribute, typeToConvert: runtimePropertyType, classTypeAttributeIsOn: parentClassType !, memberInfo); } } if (converter == null) { converter = GetConverter(runtimePropertyType); Debug.Assert(converter != null); } if (converter is BinaryConverterFactory factory) { converter = factory.GetConverterInternal(runtimePropertyType, this); // A factory cannot return null; GetConverterInternal checked for that. Debug.Assert(converter != null); } // 非空类型转换器处理可空类型,引发异常 if (runtimePropertyType.IsNullableType() && !converter.TypeToConvert.IsNullableType()) { ThrowHelper.ThrowInvalidOperationException_ConverterCanConvertNullableRedundant(runtimePropertyType, converter); } return(converter); }