private IMsgPackConverter TryGenerateArrayConverter(Type type) { var arrayInterface = GetGenericInterface(type, typeof(IList <>)); if (arrayInterface != null) { var converterType = typeof(ArrayConverter <,>).MakeGenericType(type, arrayInterface.GenericTypeArguments[0]); return(GeneratedConverters.GetOrAdd(converterType, x => (IMsgPackConverter)GetObjectActivator(x)())); } arrayInterface = GetGenericInterface(type, typeof(IReadOnlyList <>)); if (arrayInterface != null) { var converterType = typeof(ReadOnlyListConverter <,>).MakeGenericType(type, arrayInterface.GenericTypeArguments[0]); return(GeneratedConverters.GetOrAdd(converterType, x => (IMsgPackConverter)GetObjectActivator(x)())); } return(null); }
private IMsgPackConverter TryGenerateMapConverter(Type type) { var mapInterface = GetGenericInterface(type, typeof(IDictionary <,>)); if (mapInterface != null) { var converterType = typeof(MapConverter <, ,>).MakeGenericType( type, mapInterface.GenericTypeArguments[0], mapInterface.GenericTypeArguments[1]); return(GeneratedConverters.GetOrAdd(converterType, x => (IMsgPackConverter)GetObjectActivator(x)())); } mapInterface = GetGenericInterface(type, typeof(IReadOnlyDictionary <,>)); if (mapInterface != null) { var converterType = typeof(ReadOnlyMapConverter <, ,>).MakeGenericType( type, mapInterface.GenericTypeArguments[0], mapInterface.GenericTypeArguments[1]); return(GeneratedConverters.GetOrAdd(converterType, x => (IMsgPackConverter)GetObjectActivator(x)())); } return(null); }
private IMsgPackConverter TryGenerateNullableConverter(Type type) { var typeInfo = type.GetTypeInfo(); if (!typeInfo.IsGenericType || typeInfo.GetGenericTypeDefinition() != typeof(Nullable <>)) { return(null); } var converterType = typeof(NullableConverter <>).MakeGenericType(typeInfo.GenericTypeArguments[0]); return(GeneratedConverters.GetOrAdd(converterType, x => (IMsgPackConverter)GetObjectActivator(x)())); }