loading...
Cover image for C# Godfather Characters Console Application

C# Godfather Characters Console Application

kironroy profile image Kiron Roy ・2 min read

This small console application is created with the help of this YouTube tutorial by Claudio Bernasconi. Also on DEV
I based my program on the Godfather Trilogy.

Repository here.


Code

Program.cs

Main entry to of the application

using CommandDotNet;

namespace GodfatherCharacters
{
    class Program
    {
        static int Main(string[] args)
        {
            AppRunner<GodfatherChars> appRunner = new AppRunner<GodfatherChars>();
            return appRunner.Run(args);
        }
    }
}

GodfatherChars.cs

This class has two methods that display the List of the films and the actors.

using CommandDotNet.Attributes;
using ConsoleTables;
using GodfatherCharacters.Data;
using System.Linq;

namespace GodfatherCharacters
{
    public class GodfatherChars
    {
        [ApplicationMetadata(Description = "Lists the films")]
        public void Films()
        {
            ConsoleTable
                .From(Movies.GetMovies())
                .Write();
        }

        [ApplicationMetadata(Description = "Lists the individual mafisos")]
        public void Mafioso(string family = "")
        {
            var characters = Characters.GetCharacters()
                .Where(mafiso => mafiso.Family.Contains(family));

            ConsoleTable
               .From(characters)
               .Write();
        }
    }
}

I created a directory called Data: with two classes: Character.cs, Movie.cs.

📁 Data
- Characters.cs
- Movies.cs

Characters class has three properties and a static class that has three pieces of data. This will be printed out to the console when the command dotnet GodfatherCharacters.dll mafioso is run in Powershell.

using System.Collections.Generic;

namespace GodfatherCharacters.Data
{
    public class Character
    {
        public string FullName { get; set; }
        public string PlayedBy { get; set; }
        public string Family { get; set; }
    }

    public static class Characters
    {
        public static IEnumerable<Character> GetCharacters()
        {
            yield return new Character
            {
                FullName = "Vito Corleone",
                PlayedBy = "Marlon Brando",
                Family = "Corleone"
            };

            yield return new Character
            {
                FullName = "Emilio Barzini",
                PlayedBy = "Richard Conte",
                Family = "Barzini"
            };

            yield return new Character
            {
                FullName = "Bruno Tattaglia",
                PlayedBy = "Tony Giorgio",
                Family = "Tattaglia"
            };

        }
    }

}

Movies class has two properties and a static class that has three pieces of data. This will be printed out to the console when the command dotnet GodfatherCharacters.dll films is run in Powershell.

using System;
using System.Collections.Generic;
using System.Text;

namespace GodfatherCharacters.Data
{
    public class Movie
    {
        public string Title { get; set; }
        public int YearReleased { get; set; }
    }

    public static class Movies
    {
        public static IEnumerable<Movie> GetMovies() 
        {
            yield return new Movie
            {
                Title = "The Godfather",
                YearReleased = 1972
            };

            yield return new Movie
            {
                Title = "The Godfather, Part II",
                YearReleased = 1974
            };

            yield return new Movie
            {
                Title = "The Godfather, Part III",
                YearReleased = 1990
            };

        }
    }
}


The Console Application printout.

Access to the Actors and Characters they play
Type this command in Powershell
 dotnet .\GodfatherCharacters.dll masifo
Output
-----------------------------------------------
| FullName        | PlayedBy      | Family    |
-----------------------------------------------
| Vito Corleone   | Marlon Brando | Corleone  |
-----------------------------------------------
| Emilio Barzini  | Richard Conte | Barzini   |
-----------------------------------------------
| Bruno Tattaglia | Tony Giorgio  | Tattaglia |
-----------------------------------------------
Access the Films and Release Date
Type this command in Powershell
 dotnet .\GodfatherCharacters.dll films
Output
------------------------------------------
| Title                   | YearReleased |
------------------------------------------
| The Godfather           | 1972         |
------------------------------------------
| The Godfather, Part II  | 1974         |
------------------------------------------
| The Godfather, Part III | 1990         |
------------------------------------------

Posted on by:

Discussion

pic
Editor guide