c# - Method input parameter as namespace -
let's have these objects
namespace myresponses.interfaces.iinterface1 { partial class exresponse { object1 myobj; bool flag; } } namespace myresponses.interfaces.iinterface2 { partial class exresponse { object2 myobj; bool flag; } } namespace myresponses.interfaces.iinterface3 { partial class exresponse { object3 myobj; bool flag; } }
and need method check flags in exresponse objects. method receive object inside myresponses.interfaces namespace.
something like:
bool checkflaginresponse(myresponses.interfaces response, type responsetype) { return (response responsetype).flag; }
i call this?
checkflaginresponse(myexresponse, myexresponse.gettype())
it sounds broken design, if have similar types same members (and same simple name) no type relationship between them.
if generated code , types declared partial
types in generated code, potentially fix making them implement interface:
public interface iflag { bool flag { get; } } namespace myresponses.interfaces.iinterface1 { public partial class exresponse : iflag {} } namespace myresponses.interfaces.iinterface2 { public partial class exresponse : iflag {} } // etc
then can use iflag
needs access flag - response classes implement interface.
alternatively, if really have (and if you're using .net 4, sounds you're not), use dynamic typing:
bool checkflaginresponse(dynamic response) { return response.flag; }
Comments
Post a Comment