Skip to content

generate_csharp

Converts a VBL Aquarium model into a C# struct.

generate_csharp(model_classes)

Generate a C# file containing structs for the given model classes.

Parameters:

Name Type Description Default
model_classes list[type[VBLBaseModel]]

The model classes to generate C# structs for.

required

Returns:

Type Description
str

The C# file as a string.

Source code in src/vbl_aquarium/utils/generate_csharp.py
def generate_csharp(model_classes: list[type[VBLBaseModel]]) -> str:
    """Generate a C# file containing structs for the given model classes.

    Args:
        model_classes: The model classes to generate C# structs for.

    Returns:
        The C# file as a string.
    """
    # Parse each model class.
    output = ["using System;"] + [_parse_model(model_class) for model_class in model_classes]

    # Add `using UnityEngine;` if Unity classes are present.
    for segment in output:
        if any(unity_class in segment for unity_class in get_unity_model_class_names()):
            output.insert(1, "using UnityEngine;")
            break

    # Return the complete C# file.
    return "\n".join(output)