public FuncAsyncConverter GetConverter()

in src/Microsoft.Azure.WebJobs.Extensions.Kafka/Trigger/KafkaEventDataConvertManager.cs [32:75]


        public FuncAsyncConverter GetConverter<TAttribute>(Type typeSource, Type typeDest) where TAttribute : Attribute
        {
            if (typeof(IKafkaEventData).IsAssignableFrom(typeSource))
            {
                if (typeDest == typeSource)
                {
                    return ConvertToSame;
                }
                else if (typeDest == typeof(string))
                {
                    return ConvertToString;
                }
                else if (typeDest == typeof(byte[]))
                {
                    return ConvertToByteArray;
                }
                else if (typeSource.IsGenericType)
                {
                    var sourceGenericTypes = typeSource.GetGenericArguments();
                    var sourceValueType = sourceGenericTypes.Last();
                    if (sourceValueType == typeDest)
                    {
                        return ConvertToSameGenericSourceType;
                    }
                    else if (typeof(IKafkaEventData).IsAssignableFrom(typeDest) && typeDest.IsGenericType && typeDest.GetGenericArguments().Last() == sourceValueType)
                    {
                        var genericMethod = this.GetType().GetMethod(nameof(ConvertKafkaEventDataType), BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(sourceValueType);
                        var converter = (FuncAsyncConverter)genericMethod.CreateDelegate(typeof(FuncAsyncConverter));
                        return converter;
                    }
                }
                else if (typeof(IKafkaEventData).IsAssignableFrom(typeDest) && typeDest.IsGenericType && typeSource == typeof(IKafkaEventData))
                {
                    // Handles the scenario where the source == IKafkaEventData and the destination is of type KafkaEventData
                    return ConvertFromIKafkaEventToGenericItem;
                }
                else if (SerializationHelper.IsDesSerType(typeDest))
                {
                    return ConvertFromKafkaEventDataValueProperty;
                }
            }

            return this.converterManager?.GetConverter<TAttribute>(typeSource, typeDest);
        }