public PropertySerializationInfo(PropertyInfo info, string name, JsonFormatterAttribute formatterInfo) #endif { Info = info; MemberName = name; FormatterInfo = formatterInfo; MemberNameByteLengthWithQuotation = NullableStringFormatter.CalcByteLength(name); IsFormatterDirect = DirectTypeEnumHelper.FromTypeAndFormatter(info.PropertyType, FormatterInfo?.FormatterType); }
public ShouldSerializeFieldSerializationInfo(FieldInfo info, MethodInfo shouldSerialize, string name, JsonFormatterAttribute formatterInfo) #endif { Info = info; ShouldSerialize = shouldSerialize; MemberName = name; MemberNameByteLengthWithQuotation = NullableStringFormatter.CalcByteLength(name); FormatterInfo = formatterInfo; IsFormatterDirect = DirectTypeEnumHelper.FromTypeAndFormatter(info.FieldType, FormatterInfo?.FormatterType); }
static FormatterCache() { Type tType = typeof(T); JsonFormatterAttribute customAttribute = tType.GetTypeInfo().GetCustomAttribute <JsonFormatterAttribute>(); if (customAttribute == null) { return; } try { if (tType.IsGenericType) { Utf8JsonAttributeFormatterResolver.FormatterCache <T> .formatter = (IJsonFormatter <T>)Activator.CreateInstance( customAttribute.FormatterType.MakeGenericType(tType.GenericTypeArguments)); } else { if (customAttribute.FormatterType.IsGenericType) { Utf8JsonAttributeFormatterResolver.FormatterCache <T> .formatter = (IJsonFormatter <T>)Activator.CreateInstance( customAttribute.FormatterType.MakeGenericType(typeof(T))); } else { Utf8JsonAttributeFormatterResolver.FormatterCache <T> .formatter = (IJsonFormatter <T>)Activator.CreateInstance( customAttribute.FormatterType ); } } } catch (Exception ex) { throw new InvalidOperationException("Can not create formatter from JsonFormatterAttribute, check the target formatter is public and has constructor with right argument. FormatterType:" + customAttribute.FormatterType.Name, ex); } }