Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/alexscigalszky/interfaceextentions
- Owner: AlexScigalszky
- Created: 2023-08-13T21:50:05.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-08-13T21:56:56.000Z (over 1 year ago)
- Last Synced: 2024-11-05T18:12:09.248Z (2 months ago)
- Topics: csharp-code, extensionmethods, interfaces, parametrized
- Language: C#
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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?)```