28 Ağustos 2012 Salı

generate toString() automatically in Visual Studio

I am looking for a way to override toString() methods of my beans as i did in Eclipse..
here is a discussion about it: http://stackoverflow.com/questions/4932136/is-there-a-tostring-generator-available-in-visual-studio-2010

Pressing a dot, selecting override and toString() generates something like that:


public override string  ToString()
{
  return base.ToString();
}


However, what i want is a long string which is a concatanation of the bean's attributes.. I do not want to use reflection because of performance issues.. So, the solution is installing Autocode 4.0 http://visualstudiogallery.msdn.microsoft.com/48eeb43f-cb46-4680-b7df-11e73cf894ca
http://www.devprojects.net/download

After installation (which is running the downloaded .msi file), just press ctrl + enter to see the Autocode window in Visual Studio.. ( http://www.devprojects.net/blog/article/start-using-autocode )



Select tostr in the window and the following code will be genarated automatically:



override public string ToString()
        {
            string str = String.Empty;
            str = String.Concat(str, "ID = ", ID, "\r\n");
            str = String.Concat(str, "EskiID = ", EskiID, "\r\n");
            str = String.Concat(str, "Aktif = ", Aktif, "\r\n");
            str = String.Concat(str, "VersiyonSayisi = ", VersiyonSayisi, "\r\n");
            str = String.Concat(str, "Tanimi = ", Tanimi, "\r\n");
            return str;
        }



Hiç yorum yok:

Yorum Gönder