WriteLine in Visual Studio like LinqPad

In LinqPad, I have to write

Console.WriteLine(result)

      

in Visual Studio I need to create something special for each case like

result.ToList().ForEach(x=> Console.WriteLine(x));

      

but that doesn't work for all cases.

I have a way to extend, a project in Visual Studio that can do the same Magic as LinqPad?

+3


source to share


2 answers


Have a look at ObjectDumper which is also available as nuget . With this package, you can dump complex structures to the console very easily. Get what TextWriter

your console requires using the Console.Out

as parameter . Here's an example:



ObjectDumperExtensions.Dump(root, "root", Console.Out);

      

+1


source


You can write your own helper for all applications.

quick example:



class Car
{
    public string Id;
    public string Name;
    public override string ToString()
    {
        return String.Concat(Id, Name);
    }
}
public static class Helper
{
    public static void WriteToConsole<T>(this IList<T> collection)
    {
        Console.WriteLine(string.Join("\t", collection.ToArray()));
    }
}
class Program
{
    static void Main(string[] args)
    {
        List<Car> cars = new List<Car>();
        cars.Add(new Car() { Id = "1", Name = "Polonez Caro" });

        Helper.WriteToConsole(cars);
        Console.ReadKey();
    }
}

      

0


source







All Articles