vendredi 26 mai 2023

Retrieving whole C# class implementation as a string in code [duplicate]

How to retrieve whole class in C# as a string.

What I mean by that is:

This is my class

public class MyClass
{
    public int MyProperty { get; set; }

    public void MyMethod()
    {
        Console.WriteLine("Inside MyMethod");
        Console.WriteLine("Hello, World!");
        Console.ReadLine();
    }
}

And I would like to output this implementation as a string.

Console.WriteLine(MyClassString)

Expected result:

"""public class MyClass
{
    public int MyProperty { get; set; }

    public void MyMethod()
    {
        Console.WriteLine("Inside MyMethod");
        Console.WriteLine("Hello, World!");
        Console.ReadLine();
    }
}"""




Aucun commentaire:

Enregistrer un commentaire