C
C#2y ago
cap5lut

✅ Make method implemented in interface accessible from implementing type

i have an interface
interface ICL
{
public IEnumerable<ICLPlatform> GetPlatforms()
{
// code
}
}
interface ICL
{
public IEnumerable<ICLPlatform> GetPlatforms()
{
// code
}
}
and an implementing struct
struct CLAdapter : ICL
{
}
struct CLAdapter : ICL
{
}
now GetPlatforms() isnt reachable via new CLAdapter().GetPlatforms(), how can i make that accessible? i tried implementing it in the adapter by simply casting this to ICL, but then i run into stack overflows
/// <inheritdoc/>
public IEnumerable<ICLPlatform> GetPlatforms()
{
return ((ICL)this).GetPlatforms();
}
/// <inheritdoc/>
public IEnumerable<ICLPlatform> GetPlatforms()
{
return ((ICL)this).GetPlatforms();
}
2 Replies
Sossenbinder
Sossenbinder2y ago
It's a default interface implementation, that's only seen on the interface, it's not part of the implementing class var adapter = new CLAdapter(); adapter.GetPlatforms();
ICL castAdapter = adapter; castAdapter.GetPlatforms(); Second usage would work I'm actually not entirely sure how you would work around this, the SO exception is due to the function just calling itself on and on, but I never really work with default interface implementations, so not entirely sure how you would be able to redirect it to the DII
cap5lut
cap5lutOP2y ago
hmmm, guess ill have to do it differently 😒 thanks for ur help, thought i was missing something very simple here
Want results from more Discord servers?
Add your server