/* * This file is part of the Protevus Platform. * * (C) Protevus * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import 'package:protevus_runtime/runtime.dart'; /// Prefix string for List types in type checking. const String _listPrefix = "List<"; /// Prefix string for Map types in type checking. const String _mapPrefix = "Map(dynamic input) { try { var typeString = T.toString(); // Handle nullable types if (typeString.endsWith('?')) { if (input == null) { return null as T; } else { typeString = typeString.substring(0, typeString.length - 1); } } // Handle List types if (typeString.startsWith(_listPrefix)) { if (input is! List) { throw TypeError(); } // Cast List to various element types if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List")) { return List.from(input) as T; } else if (typeString.startsWith("List>")) { return List>.from(input) as T; } } // Handle Map types else if (typeString.startsWith(_mapPrefix)) { if (input is! Map) { throw TypeError(); } final inputMap = input as Map; // Cast Map to various value types if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; } } // If no specific casting is needed, return the input as T return input as T; } on TypeError { // If a TypeError occurs during casting, throw a TypeCoercionException throw TypeCoercionException(T, input.runtimeType); } }