Extracting an Interface from .NEt System Classes

When using Visual Studio, it is easy to extract an interface from a class that I wrote myself. I right-click on the class and select "Refactoring", then select "Extract Interface".

Suppose for a second that I wanted to create a ConfigurationManager wrapper and write some tests around it. A quick way to do this is to extract the interface from the ConfigurationManager by right-clicking it, then Go to Definition, and then from the class select Refactoring, then select Extract Interface. Then I just create my wrapper class, inherit from my newly created interface, and then implement it, and I have a great starting point for my wrapper class.

However, extracting an interface from any .NET system classes is not possible, possibly because it is just metadata about the classes, not the classes themselves (or I'm doing it wrong).

Is there an easy way to do what I'm trying to accomplish? I want me not to waste time typing what I do not need to print.

thank

+3
source share
1 answer

The problem is not so much to extract the interface - you can also do it β€œmanually”, but you cannot tell the CLR that the system configuration manager implements this interface, because this (meta) information is stored in a framework assembly that you cannot to change.

EDIT:

" ", " ". Visual Studio ( ) . .

  • class interface
  • /
  • public override ( )

, . .

+3

Source: https://habr.com/ru/post/1741730/


All Articles