# convert<T> method

1. @override

T? convert<T>(

1. Object? source,
2. Class<T> targetType, [
3. String? qualifiedName

])
override

Converts the given `source` object to the specified `targetType`.

Returns `null` if the conversion fails or if `source` is `null`.

### Example:

    final port = conversionService.convert<int>('8080', Class<int>());
    final date = conversionService.convert<DateTime>('2025-01-01', Class<DateTime>());

    final port = conversionService.convert<int>('8080', Class<int>(), 'dart.core.int');
    final date = conversionService.convert<DateTime>('2025-01-01', Class<DateTime>(), 'dart.core.DateTime');

The `T` type parameter represents the expected return type.

## Implementation

    @override
    T? convert<T>(Object? source, Class<T> targetType, [String? qualifiedName]) {
      Class? fromQualified = qualifiedName != null ? Class.fromQualifiedName(qualifiedName) : null;
      Class? fromSource = source != null ? _getSourceType(source) : null;
      final sourceType = fromQualified ?? fromSource;
      final result = convertTo<T>(source, targetType, sourceType);

      if(result != null) {
        return result as T;
      } else {
        return result as T?;
      }
    }