Can I add a dynamic method to an interface in c#?
So the interface method doesn’t exist but exists on the underlying class and I want to call it via an interface.
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That kind of defeats the point of an interface. If you want it on some of the classes and not others then you can implement it that way, but you will have to cast it to the known class type first.
You could probably use some reflection to check in the under-laying class type has the method you want to call if you want to be really fussy about it (and avoid knowing the type to cast)