There is no equivalent of what you say about Java and Eclipse.
@RawitasKrungkaew answer is good.
If you don't want to use JSON, you can use reflexion with an extension method to have reusability:
In some class
public override string ToString()
{
return this.GetPropertiesAsText();
}
PropertiesListerHelper.cs
using System.Reflection;
static public class PropertiesListerHelper
{
static private bool IsProcessing;
static public string GetPropertiesAsText(this object instance)
{
if ( IsProcessing )
return $"<Reentrancy in {instance.GetType().Name}.ToString()>";
IsProcessing = true;
try
{
string result = "";
var list = instance.GetType().GetProperties().OrderBy(item => item.Name);
foreach ( var property in list )
{
var value = property.GetValue(instance);
result += $"{property.Name} = {(value == null ? "<null>" : value)}, ";
}
return result.TrimEnd(", ".ToArray());
}
catch ( Exception ex )
{
return $"<Exception in {instance.GetType().Name}.ToString(): {ex.Message}>";
}
finally
{
IsProcessing = false;
}
}
}
So the behavior works even if the class design is changing.
You can adapt the method to format the output as you want, for example:
foreach ( var property in list )
{
var value = property.GetValue(instance);
result += $"{property.Name} = {(value == null ? "<null>" : value)}"
+ Environment.NewLine;
}
return result.TrimEnd(Environment.NewLine.ToArray());
The management of the case of reentrancy may be improved because it can cause stack overflow on forms for example.