C
C#

help

✅ Make method implemented in interface accessible from implementing type

Ccap5lut3/30/2023
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();
}
SSossenbinder3/30/2023
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
Ccap5lut3/30/2023
hmmm, guess ill have to do it differently 😒 thanks for ur help, thought i was missing something very simple here

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ ASP.NET, MongoDB, C#does anyone have experience with c#, mongodb and ASP.NET? I have a project and I need to get data to✅ Is there a working code editor for blazor server?i found one for blazor wasm https://github.com/serdarciplak/BlazorMonaco but that one does not work ✅ Multiple inheritance questionI have a partial class webform that is inheriting a base page class. Inside it there are multiple re❔ How to automatically set version of project to know what version deployed on specific server?The problem is that there is bunch of clients with different versions of .net core and netfx projecthow to make a target that will disappear after shooting a couple of times this is my scripts i havebut it doesnt seem to want to destroy https://paste.mod.gg/mppnwkqnmukq/2❔ ✅ Choosing an appropriate data structureSo I have a list of objects and I want one in the list to be active and the rest to be inactive. I ❔ Saving User DataI have it set up through properties, but I'm having a lot of trouble with showing it on other forms Unsupported statement value type: Microsoft.DotNet.DesignTools.Client.CodeDom.CodeBodyTextStatementhttps://github.com/Jordan-Belfort-88/Audio-Player-1.0/blob/master/Audio%20Player/Form1.Designer.cs IAssert.Raises<> in xUnitI'm trying to create tests for certain events. However it seems that xUnit assumes that I use EventH❔ I have an API function and I want to know what exception it can throw. How can I do that?This is not said in the documentationAmbiguity between 2 things idk how to fixGot an error message all of a sudden saying this when everything was working perfect before so i und❔ Problem populating DatagridI'm trying to populate a datagrid where certain columns are populated with information that is read ❔ Avisynth script maker thingIm trying to make a script that creates AVS files for every file in a Directory based on a template.❔ How to work with Hwnd in c#I want to open programs using Process.Start but all those programs have empty MainWindowHandle and M