Thursday, 26 September 2013

In C#, should I use struct to wrap an object in order to fulfill additional interfaces?

In C#, should I use struct to wrap an object in order to fulfill
additional interfaces?

There is an existing class from a third-party library I want to reuse, but
it does not implement some of the required interfaces. I'm thinking of
wrapping it inside a struct to fulfill the required interfaces (basically
like how Scala does it). The reason why I prefer struct over class for
this use case is because it only stores one thing: the wrapped object, and
it probably won't incur performance penalties? But I'm not sure if boxing
would occur if I pass a struct to some method that takes in an interface?
And are there any other drawbacks about this approach?

No comments:

Post a Comment