Skip Navigation Links



Code Generation Improvements in ReSharper 7

Author : Dmitri Nesteruk      Blog :JetBrains .NET Tools Blog      Date: 7/25/2012 1:29:41 PM


If there was a competition between different ReSharper subsystems on which one produces most value relative to developer effort, the Generate action would win that competition outright. And, needless to say, in the 7.0 release we have added a couple of new features and improvements to ReSharper’s intuitive code generator.

Generate Partial Methods

Many code-generating frameworks produce code made using partial classes, with the assumption that developers can augment generated functionality by implementing partial methods when needed. For example, the Entity Framework does this (in non-Code-First scenarios, of course) by defining entity classes as partial.

ReSharper now supports this scenario. To use it, create a partial declaration of a class, then choose Generate|Partial Methods:

Now, simply pick the partial methods that you want to implement:

All the partial methods are consequently stubbed out in the target class, ready for you to implement.

Improvements in Generate Equality Members

When comparing types, many of our users wanted to control the way type checks were performed. So, by popular demand, the Generate Equality Members dialog now has three different options for implementing the type comparison:

Depending on which of the three options you choose in the above, the condition for checking the type in the Equals() method will appear as one of the following:

  • Type exactly same as this:

  • Type exactly as owner type:

  • Type is of owner type or subtype:

Generate Equality Comparer

In addition to the inline equality implementation for a particular class, ReSharper 7 comes with a brand-new action called Generate Equality Comparer. The goal of this action is to generate a separate class that implements the IEqualityComparer<T> interface. This is useful for creating specific comparison criteria, as well as for instances where an IEqualityComparer is explicitly required by a particular API.

For example, given a simple Person class with two properties, we can fire up the action:

and, after picking the members for comparison, Person gets the following private inner class:

In addition, the option to generate the static instance of the comparer adds the following field to the Person class:

Support for INotifyPropertyChanged

And one last thing… if you’ve got a class that implements the INotifyPropertyChanged or inherits from a class that supports property change notifications (e.g., Prism’s NotificationObject), the Generate|Properties action offers an option to implement properties with change notification calls:

By the way, support for INotifyPropertyChanged in ReSharper 7 is more than just generation, so make sure to read more about this.

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(80)

sankarshan(11)

Milind(7)

Srinivasan Sampathkumar(3)

AMJAD KHAN(2)

Cynthia Z(2)

Fidarose Isha(2)

Firoze Shakir Photographerno1(2)

Harshil(2)

MUNZ TDT(2)

R.D. Bhalekar(2)

RWABhagidari.blogspot.com(2)

Sameena Prathap(2)

Sunthosh Kumar(2)

The Guy in the Hat ™(2)

Vashi Chandiramani(2)

vskesavarao(2)

Aarthi(1)

Abha Iyengar(1)

Abhishek Mukherjee(1)

Abraham Tharakan(1)

Aditya Tibrewala(1)

admin(1)

Always Happy(1)

Amar Ashok Jajoo(1)

anouradha bakshi(1)

Anu Lal(1)

Anu Varma(1)

Archana Kumar(1)

aseemrastogi2(1)

Beyond(1)

Bhushavali N(1)

Champa(1)

Chandrika Shubham(1)

churumuri(1)

churumuri(1)

CM(1)

Creativity(1)

dawdayogesh(1)

Debolina Raja Gupta(1)

Deeps(1)

Dew(1)

Dimple Maheshwari(1)

Disha(1)

Everything(1)

Govind Kumar(1)

Harimohan(1)

Harini Padmanabhan(1)

Heena Jain(1)

Hemu(1)

iBeingMe(1)

Indrani(1)

IS(1)

Iti(1)

J P Joshi(1)

k(1)

Kalamwali Bai(1)

Krishna Rao(1)

Krithi Karthi(1)

Kunal Singh(1)

Lluvia....(1)

Madhavi Madhurakavi(1)

mêlée(1)

mervin anto(1)

Mohd Salim(1)

Mythreyi(1)

NG(1)

Nisheeth Ranjan(1)

Nivedita Thadani(1)

Nivedita Thadani(1)

Nupur(1)

Pari Vasisht(1)

Pheno Menon(1)

pinksocks(1)

pixie(1)

Prasanta Bora(1)

Preety(1)

R-A-J(1)

Raja(1)

rajkumar r(1)

Rakesh HP(1)

Raksha(1)

ravi dabas(1)

Ray Titus(1)

Ritesh Agarwal(1)

rm(1)

RNA Corp(1)

Sabina Fatima Hussain(1)

Sameena Prathap(1)

Sandhya(1)

Saravanan Sivaraman(1)

sayedkhadri(1)

Shankha(1)

Shankha(1)

Shobha(1)

Shobhaa De(1)

sidhu352(1)

Smi..(1)

Sneha Sharma(1)

soraya nulliah(1)

Sriram Khé(1)

sumana Mukhopadhyay(1)

Susan Deborah(1)

swapnil kochetaa(1)

Tarang Sinha(1)

TCYonline.com(1)

Umasree(1)

vanya(1)

Vasudev Ram(1)

Vidya Sury(1)

vishesh unni raghunathan(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com