C
C#2y ago
MrScautHD

❔ 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;
}
}
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;
}
}
16 Replies
MrScautHD
MrScautHD2y ago
Guys how can i call a non static method in a interface?
Thinker
Thinker2y ago
You can't™️
MrScautHD
MrScautHD2y ago
ouff
Thinker
Thinker2y ago
That method comes from the interface, not the type ConfigRegistry itself
MrScautHD
MrScautHD2y ago
yea but i extend from it
Thinker
Thinker2y ago
And in general you shouldn't do this in interfaces, an interface should be a contract and nothing else and also you can just shorten the definition of Initialize to
void Initialize();
void Initialize();
MrScautHD
MrScautHD2y ago
oh yea thx
Thinker
Thinker2y ago
What you could do is have an abstract class RegistryBase<B> which implements the interface and defines the Register method
MrScautHD
MrScautHD2y ago
ah yea good idea btw i not want that Initialize need added just as a option
Thinker
Thinker2y ago
ah
MrScautHD
MrScautHD2y ago
is it possible without body?
Thinker
Thinker2y ago
well, sure, then you could give it an empty body
MrScautHD
MrScautHD2y ago
like small how you did it? ok yea well
Thinker
Thinker2y ago
void Initialize() {}
void Initialize() {}
MrScautHD
MrScautHD2y ago
👍
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.