tin
tin
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
then I'm just gonna copy paste the implementation of GetComponent(){ return GetComponent(level);} I guess
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
hmm ok thats unfortunate
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
basically asking if there is any allocation happening
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Ok, sorry for coming back again. I think this is really the last time. Will this incur boxing at runtime when I want to call that function? Because I will have to now explicitly cast everything as that interface to make it work right?
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
helped me a lot
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
ok, nevertheless thank you for answering my questions!
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
ah ok haha, if that is the only way I maybe will just write GetComponent(level) for the implementations
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Maybe one more question in case you know that too. If I now have another method
struct Attack : IUpgradableAttack<T>{
public string Describe(){
var comp = GetComponent();
}
}
struct Attack : IUpgradableAttack<T>{
public string Describe(){
var comp = GetComponent();
}
}
throws an error, since GetComponent is not implemented and it somehow does not manage to use the default implementation from the interface. Prepending the interface name also does not work. Is there a way to use the default implementation without boxing?
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
thank you for helping!
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
I understood my mistake
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Just tried it 🙂
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Yup thanks!
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Defining the interface as above works. However, when I implement a struct which implements that interface (and does not implement GetAttack), then C# start bugging me
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
Thanks for answering. Basically what I'd like to do is to have
interface IUpgradableAttack<T> : IAttack<T>{
int level {get; set;}
T GetAttack(int level);
T GetAttack(){
return GetAttack(level);
}
}
interface IUpgradableAttack<T> : IAttack<T>{
int level {get; set;}
T GetAttack(int level);
T GetAttack(){
return GetAttack(level);
}
}
so that I do not have to implement GetAttack when I have already implemented GetAttack(int level)
26 replies
CC#
Created by tin on 3/4/2024 in #help
Using a default implementation on an interface
If I just put the default implementation inside of IUpgradableAttack, then when implementing that interface the compiler tells me I still need to implement GetAttack (even though there should be a default implementation)
26 replies