Multiple Rectangle type.


I put all my logic into a separate library and have a second MonoGame project which uses it. The library has a Rectangle struct and MongoGame has also one. Is there an easy way to use the two seemingly? I can add an implicit operator to my own Rectangle struct and convert it automatically but then I would have a dependency on the MonoGame library. I would like to avoid that.

If you want to reference monogame datatypes, you need to have a reference to monogame :slight_smile:

one thing you could do is leave your lib as it is, and if you use it from a monogame project, you could just add a class extension for the conversion from that project. Or make some monogame wrapper of your library for that purpose

1 Like

Specify with full namespace.

Microsoft.Xna.Framework.Rectangle a;
YourLibraryNamespace.Rectangle b;


One common way to do this is to have a third library with the rectangle code in that is imported into both your separate library and monogame. You would have to be compiling your own version of monogame from source (which is easy), and then cut and paste the rectangle code out of monogame into your shared third library.

1 Like

Thanks, yeah this makes sense or I can make another version of the library that uses the monogame types.