Class: Makit::Cli::Generators::Templates::Dotnet::ProgramCs

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/cli/generators/templates/dotnet_templates.rb

Overview

Template generator for .NET Program.cs main entry point files

Generates a basic C# console application with a Main method that outputs “Hello, World!” to the console. The namespace is derived from the project name by capitalizing and joining segments.

Examples:

program = ProgramCs.new("my-console-app")
csharp_content = program.render

Instance Method Summary collapse

Constructor Details

#initialize(project_name) ⇒ ProgramCs

Initialize a new Program.cs template generator

Parameters:

  • project_name (String)

    the name of the .NET project



64
65
66
# File 'lib/makit/cli/generators/templates/dotnet_templates.rb', line 64

def initialize(project_name)
  @project_name = project_name
end

Instance Method Details

#renderString

Render the Program.cs C# source code content

Returns:

  • (String)

    the complete C# source code with namespace and Main method



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/makit/cli/generators/templates/dotnet_templates.rb', line 71

def render
  "    namespace \#{@project_name.split(/[-_]/).map(&:capitalize).join};\n\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Console.WriteLine(\"Hello, World!\");\n        }\n    }\n  CSHARP\nend\n"