I would like to create a dynamic proxy to an existing type, but add an implementation of a new interface, that isn’t already declared on the target type. I can’t figure out how to achieve this. Any ideas?
Share
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.
You can use the overload of
ProxyGenerator.CreateClassProxy()that has theadditionalInterfacesToProxyparameter. For example, if you had a class with a string name property and wanted to add anIEnumerable<char>to it that enumerates the name’s characters, you could do it like this:Note that the
Nameproperty doesn’t have to be virtual here, if you don’t want to proxy it.