我有一些只用于包含数据的类。例如
public class EntityAdresse : IEntityADRESSE
{
public string Name1 { get; set; }
public string Strasse { get; set; }
public string Plz { get; set; }
public string Ort { get; set; }
public string NatelD { get; set; }
public string Mail { get; set; }
public int Id_anrede { get; set; }
public string Telefon { get; set; }
public int Id_adr { get; set; }
public int Cis_adr { get; set; }
}
这代表一个地址。就像我说的,它只包含数据。没有方法(我知道界面在这里没有意义......)
现在我需要为所有这些实体类实现 ToString 并且它们有很多。
我的问题是:C# 中是否有一个元编程功能可以自动生成这个 tostring 方法?我不想为这些类中的每一个编写样板代码。
或者,我也可以编写一个 perl 或 python 脚本来生成代码。但我更喜欢直接在 C# 中进行。