* @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:----Px+H5azRrUMoJSgg+u8FFpIUk7C9sbqzrimh424hGQp3kOjxwPRe58jp6Xqogl7gJKx9U2sNEubLiDAQHqXfbqQPI+ps8ZwHpNXF+BGL9U5Qd7OUZjLsU5KdKA6TxYVJT7UnXB6mXCLZe+5+icVlAoLAAglKgQkG5HcHdiWHCQlhiD6M4mzBeqmIJu4uL40sPERTykWIDud9Y69lv+7x52THh2eEN01W9wTNWAfm3uvtFfnFJDXCKCc5Ubdn6KMJHXmCJyN+l5N/5te/oNR665QM1D5jews7/tK/9N/rtm69o7mvFbZ2/x1LPmch2p5M4vUJdCVs99GdsrS3JWKkVEiBfF3dxLpFKWNFA8mHRfC4OE2NqtUksWKCr9YpdYJ2Hj/LUMNo6BnDkWFwikZH9B9g9cHx9L7cUkJA5SELBcjlN1c1s2ZrqS4V6g6ZfrWEe0aVUHdVq8KnsCtrQzXqq7oVMbFaxYz02LTUN0gz3NcCCvHZr215u+eYrJZmwCD5Yu4TDf8SjUj5qc3O6n25zOXbXFSkxJhX0kGsgProgztBybmUxj4Moq5F5See/iHBx37ufwWt6RxSaTa0+w+/TTvKmmxN6a2ZswKKi6I2nK43AFkRwncl2A/D2M1qPIfIbhmqpYQF8bEPqQCzfFRywmf+42BOHEcEJFAyAxZUcnQ=----ATTACHMENT:----MTM4NTg2ODM5NTc2NTIzNyA1NjU1Mzk5MzYwMDMzNjg3IDIwMDUxMjY4NzIwODkwMA==