C#
C#

help

Root Question Message

MrScautHD
MrScautHD2/20/2023
❔ Can i not call a non static Method in a interface?

public interface IRegistry<B> {

    public virtual void Initialize() {
        
    }
    
    public T Register<T>(string name, Dictionary<string, object> registryList, T config) where T : B {
        registryList.Add(name, config);
        
        return config;
    }
}
MrScautHD
MrScautHD2/20/2023
Guys how can i call a non static method in a interface?
thinker227
thinker2272/20/2023
You can't™️
MrScautHD
MrScautHD2/20/2023
ouff
thinker227
thinker2272/20/2023
That method comes from the interface, not the type ConfigRegistry itself
MrScautHD
MrScautHD2/20/2023
yea but i extend from it
thinker227
thinker2272/20/2023
And in general you shouldn't do this in interfaces, an interface should be a contract and nothing else
thinker227
thinker2272/20/2023
and also you can just shorten the definition of Initialize to
void Initialize();
MrScautHD
MrScautHD2/20/2023
oh yea thx
thinker227
thinker2272/20/2023
What you could do is have an abstract class RegistryBase<B> which implements the interface and defines the Register method
MrScautHD
MrScautHD2/20/2023
ah yea
MrScautHD
MrScautHD2/20/2023
good idea
MrScautHD
MrScautHD2/20/2023
btw
MrScautHD
MrScautHD2/20/2023
i not want that Initialize need added
MrScautHD
MrScautHD2/20/2023
just as a option
thinker227
thinker2272/20/2023
ah
MrScautHD
MrScautHD2/20/2023
is it possible without body?
thinker227
thinker2272/20/2023
well, sure, then you could give it an empty body
MrScautHD
MrScautHD2/20/2023
like small how you did it?
MrScautHD
MrScautHD2/20/2023
ok
MrScautHD
MrScautHD2/20/2023
yea well
thinker227
thinker2272/20/2023
void Initialize() {}
MrScautHD
MrScautHD2/20/2023
👍
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy