Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexscigalszky/interfaceextentions

Examples of extension methods of parametrized interfaces
https://github.com/alexscigalszky/interfaceextentions

csharp-code extensionmethods interfaces parametrized

Last synced: 13 days ago
JSON representation

Examples of extension methods of parametrized interfaces

Awesome Lists containing this project

README

        

# Extention methods using Classes and Interfaces

This repository shows how with C# we can extend parametrized classes and interfaces

## IMPORTANT

Look at the double implementation in the class ´Wrapper´. That's the key.

```C#
public class Wrapper :
IWrapper, // Interface inheritance, parameterized Interface
IWrapper // Interface inheritance, parameterized Class
// no matter if Request implements IRequest.
{

}
```

If the class Wrapper doesn't implement the class parametrized interfaces, the tests ´Use_Interface_Interface_Extension_Test´ and ´Use_Interface_Class_Extension_Test´ won't compile.
C# doesn't know how to cast th line

```C#

IWrapper wrapper = new Wrapper();

```

And you will see the error

```

Error CS0266
Cannot implicitly convert
type 'InterfaceExtentions.Impl.Wrapper'
to 'InterfaceExtentions.Interfaces.IWrapper'.
An explicit conversion exists (are you missing a cast?)

```