c# - How to guarantee two conditions in a return type -
i have method return type inherits specific type , implements specific interface.
that following method treturn? getdata(); can return object following 2 classes, such can handle returned object either tbase object or iexpected one.
class1 : tbase, iexpected class2 : tbase, iexpected nb : possible solution have common class nothing :
class12base : tbase, iexpected class1 : class12base class2 : class12base class12base getdata(); ..but can't modify class 1 nor 2.
you can't, i'm afraid. can document , careful in implementation, , pick one of relevant types act return type, that's there :(
(i'm assuming don't want make method generic in return type , constrain type parameter... put burden onto caller specify type...)
Comments
Post a Comment