c# - .NET Tools: Extract Interface and Implement Wrapper Class -


is there tool can generate extract , generate interfaces existing classes?

i know visual studio extract interface existing class. however, generate wrapper class implements functionality.

i believe tremendously unit testing.

example existing class:

public class thirdpartyclass {    public void method1(){}    public void method2(){} } 

this can generated visual studio (extract interface):

public interface ithirdpartyclass {    void method1();    void method2(); } 

i go 1 step further:

public class thirdpartyclasswrapper : ithirdpartyclass {    private tpc = new thirdpartyclass();    public void method1()    {        tpc.method1();    }    public void method2()    {        tpc.method2();    } } 

update:

this useful static classes. morten points out can use stub, however, break coupling if possible.

found way around non-sealed classes.

1 - inherit external class

class mywrapper : externalclass 

2 - extract interface public methods

class mywrapper : externalclass, iexternalclass 

3 - remove inheritance external class

class mywrapper : iexternalclass 

4 - hint on class name members interface not being implemented. alt + enter on , let resharper automatically implement them

5 - use code template wrap properties

    { return $innercomponent$.$name$; }     set { $innercomponent$.$name$ = value; } 

6 - use code template wrap methods

return $innercomponent$.$name$($signature$); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -