CLI ref structs and inheritance

D

DaTurk

Hi,

I'm writing a CLI layer into my application, and I have several ref
structs. Now, I've come into a situation that screams for a common
interface, but because the structs are ref, I didn't see a reason why
I couldn't have the structs implementing this interface. ANd it does
work, but I'm concerned about the reprecussions of doing this. Is
this good programming practice? And what will the resulting struct
translate to in c#. I mean it is a ref struct, so I would imagine it
would be what, a boxed something? Oh, and before you ask, the reason
I haven't converted these objects to classes is just because it would
take a very large change in the design of the application which is
quite large at this point. Please advise.

Thanks in advance.
 
T

Tamas Demjen

DaTurk said:
I'm writing a CLI layer into my application, and I have several ref
structs. Now, I've come into a situation that screams for a common
interface, but because the structs are ref, I didn't see a reason why
I couldn't have the structs implementing this interface. ANd it does
work, but I'm concerned about the reprecussions of doing this. Is
this good programming practice?

Apart from the fact that by default struct members are public and class
members are private, a ref struct is identical to a ref class. If you
explicitly set the visibility (to public, private, protected, or
internal), they work the same way and generate the same code.
And what will the resulting struct translate to in c#.

No, ref class and ref struct both translate to C# class. value class and
value struct both translate to C# struct.
I mean it is a ref struct, so I would imagine it
would be what, a boxed something?

Nope, ref struct is not a value type, it doesn't get boxed. It's a
reference type, a C# class.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top