First off, sorry for the probably confusing title, feel free to change it whenever somebody knows a more appropriate one.
I'm in the process of porting a math library from C++ to C#. Porting the actual code was done in a couple of days. However, I've been struggling to solve all the bugs introduced by the fact that C# classes are reference types versus C++ classes being value types.
Let me explain: If I have a Class Foo in C++ that has nested class Bar, and if I assign an existing instance of Bar to Foo, I'm essentially copying it, if the C++ compiler knows a way to do so (IF I'm not using pointers, of course)
If I do the same in C# I assign a reference. This leads to incredibly hard to find side effects. If, in C#, my code later modifies my Bar instance after assigning it to Foo, then of course the Foo.Bar objects gets modified as well. Not good.
So my question is: Is there an easy way, or a best practice approach, to find the positions in my code that assign a reference when I was assuming I assigned a copy? I even considered creating a new object every time the getter is called on an object, and copying the values there. Of course this would mean that I can never have a reverence to an object again. Again, not good.
So basically what I'm asking is: How can I find every occurrence of the assign operator (=) where the TARGET is a reference type? It's those lines of code I need to change.
I've tried to do it manually by simply searching for the '=' character, but after searching thousands and thousands lines of code, but I'm still missing the occasional assignment target.