MCPcopy Create free account
hub / github.com/apache/fory / generate_file

Method generate_file

compiler/fory_compiler/generators/csharp.py:513–555  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

511 return [self.generate_file()]
512
513 def generate_file(self) -> GeneratedFile:
514 lines: List[str] = []
515 namespace_name = self.get_csharp_namespace()
516
517 lines.append(self.get_license_header("//"))
518 lines.append("")
519 lines.append("using System;")
520 lines.append("using System.Collections.Generic;")
521 lines.append("using Apache.Fory;")
522 lines.append("using S = Apache.Fory.Schema.Types;")
523 lines.append("")
524 lines.append(f"namespace {namespace_name};")
525 lines.append("")
526
527 for enum in self.schema.enums:
528 if self.is_imported_type(enum):
529 continue
530 lines.extend(self.generate_enum(enum))
531 lines.append("")
532
533 for union in self.schema.unions:
534 if self.is_imported_type(union):
535 continue
536 lines.extend(self.generate_union(union))
537 lines.append("")
538
539 for message in self.schema.messages:
540 if self.is_imported_type(message):
541 continue
542 lines.extend(self.generate_message(message, parent_stack=[]))
543 lines.append("")
544
545 lines.extend(self.generate_module_class())
546 lines.append("")
547
548 file_name = self._module_file_name()
549 ns_path = self._namespace_path(namespace_name)
550 if ns_path:
551 path = f"{ns_path}/{file_name}"
552 else:
553 path = file_name
554
555 return GeneratedFile(path=path, content="\n".join(lines))
556
557 def _resolve_named_type(
558 self, name: str, parent_stack: Optional[List[Message]] = None

Callers 1

generateMethod · 0.95

Calls 12

get_csharp_namespaceMethod · 0.95
is_imported_typeMethod · 0.95
generate_enumMethod · 0.95
generate_unionMethod · 0.95
generate_messageMethod · 0.95
generate_module_classMethod · 0.95
_module_file_nameMethod · 0.95
_namespace_pathMethod · 0.95
GeneratedFileClass · 0.90
get_license_headerMethod · 0.80
extendMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected