* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class CSharp extends CodeGeneratorAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.cs'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\CSharp($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $code = 'public class ' . $name; if (!empty($generics)) { $code.= '<' . implode(', ', $generics) . '>'; } if (!empty($extends)) { $code.= ' extends ' . $extends; } $code.= "\n"; $code.= '{' . "\n"; foreach ($properties as $name => $property) { /** @var Code\Property $property */ $code.= $this->indent . 'public ' . $property->getType() . ' ' . ucfirst($name) . ' { get; set; }' . "\n"; } $code.= '}' . "\n"; return $code; } protected function writeMap(string $name, string $type, MapType $origin): string { $subType = $this->generator->getType($origin->getAdditionalProperties()); $code = 'public class ' . $name . ' : Dictionary' . "\n"; $code.= '{' . "\n"; $code.= '}' . "\n"; return $code; } protected function writeReference(string $name, string $type, ReferenceType $origin): string { $code = 'public class ' . $name . ' : ' . $type . "\n"; $code.= '{' . "\n"; $code.= '}' . "\n"; return $code; } protected function writeHeader(TypeAbstract $origin): string { $code = ''; if (!empty($this->namespace)) { $code.= 'namespace ' . $this->namespace . "\n"; $code.= '{' . "\n"; } $imports = $this->getImports($origin); if (!empty($imports)) { $code.= "\n"; $code.= implode("\n", $imports); $code.= "\n"; } $code.= "\n"; $comment = $origin->getDescription(); if (!empty($comment)) { $code.= '/// ' . "\n"; $code.= '/// ' . $comment . "\n"; $code.= '/// ' . "\n"; } return $code; } protected function writeFooter(TypeAbstract $origin): string { if (!empty($this->namespace)) { return '}' . "\n"; } else { return ''; } } private function getImports(TypeAbstract $origin): array { $imports = []; if (TypeUtil::contains($origin, MapType::class)) { $imports[] = 'using System.Collections.Generic;'; } return $imports; } } __halt_compiler();----SIGNATURE:----LhpIhDYJxCFn07jUAvngwps6tCbkNHH5LxjPDDh40G3BMJbN1qwRYr3UYfWZmgIaJ1yediEL2mU4gXazleU+YlmxsAmRA31v6aInDhwV6HeS9qHiuMyP/l3jireMK+Fz+T1eA0UI6dKPbhXcJ8Jtg8intiiur/sy8qyrS62Lu+qj3Zs03KuMeLHwId2k01mdX9j18raOxK29Gg3P6k+tzzrimfju5PBFmg2Ec1HHt2jh1+/vEyIXHMIKgPFgfjx4aUZuPuTTjOtAL8HcoFzGolzIftk29vQ2UT/9sfCVb2bHMnUL+zAn04usWrym/rYnvYgh6LQapq4fCIiGm0PGPgmMgZ3FRWKUFkM9ieaueUHdcT5gf2eXdjNwAR72ve6d1mM+vGbyheeXqzq/90GVZ3OCj7jptDHNG4szQ9L1bOqxxwS6XGlpzWEypEdWJPipybxXs2jByZAMz0hAFtE2X8kWYboEh4Qf1aTLBE4UruAfAc3xffB1S5QPjox16cYms+6X0KT0XGBdQhuI/2JETJkhTnxAehSUk0VeYBBiiejvfm3j2U/UzaCywp7zCDDALv2uaoewYtZzJ6xS20KE7E3RJeZO8lv+xAf1zy9AGSCPgKoPidZdu2xAqpHBRQKw9JHQViZQRuc4O8HCiOWdNCGbQ5UEVN6tennkOY0m704=----ATTACHMENT:----NzE2Nzg3MTI3MDU0MzYxMSA2NTcwNzQ3OTczNjM1MzI4IDEwNjE2MzMyNDA3MjUyMzA=