Comments (1)
Thank you for the feedback but the proposal doesn't work with inherited types.
Let's take the IStream
/StreamAdapter
as an example
public class StreamAdapter : AbstractionAdapter<Stream>, IStream
{
}
Having an instance of IStream
we can easy cast it to AbstractionAdapter<Stream>
and call UnsafeConvert()
.
Let's see at inherited type IBufferedStream
/BufferedStreamAdapter
public class BufferedStreamAdapter : StreamAdapter, IBufferedStream
{
}
An instance of IBufferedStream
cannot be casted to AbstractionAdapter<BufferedStream>
because BufferedStreamAdapter
doesn't derives from AbstractionAdapter<BufferedStream>
but from StreamAdapter
and there is no multiple inheritance in .NET.
To make it possible we have to derive from AbstractionAdapter<BufferedStream>
und implement all members of IStream
anew although they are implemented in StreamAdapter
already.
public class BufferedStreamAdapter : AbstractionAdapter<BufferedStream>, IBufferedStream
{
// all member of IStream have to be implemented yet again (or rather copied from StreamAdapter)
}
And if you want to remove UnsafeConvert
from IntelliSense then we have to implement the interface IAbstraction<T>
explicitly.
That means, instead of
public new BufferedStream UnsafeConvert()
{
return Implementation;
}
we use
BufferedStream IAbstraction<BufferedStream>.UnsafeConvert()
{
return Implementation;
}
That should be enough.
If I am missing something then feel free to fork the repo and try some new ideas. I am thankful for any help.
Until then I will wait for the following proposal that opens up new ways for writing this kind of abstractions: https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md
from thinktecture.abstractions.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thinktecture.abstractions.