This my be basic, but personally, I am stumped.
I am taking over a C# project that was previously not very well organized. Namespaces are pretty scattered throughout the code. This, to be specific, is a Unity project, but this is really just a C# issue.
There is a type (or class) in a file deep within nested directories that cannot be referred to in another file elsewhere in the project.
If the class were MyClass
, it would look like:
File 1
------
public class MyClass
{
// Stuff inside.
}
and
File 2
------
using ManyThings;
namespace SomeNamespace.NestedNamespace { // These came before me.
public class SomethingElse
{
private MyClass _myClass; // <-- the type "MyClass" cannot be found.
}
}
So I (naively) thought that maybe if I added a namespace around file 1, it would help:
File 1
------
namespace FindMe
{
public class MyClass
{
// Stuff inside.
}
}
and
File 2
------
using ManyThings;
using FindMe; // <-- The namespace FindMe cannot be found.
// If I name it global::FindMe, it changes nothing.
namespace SomeNamespace.NestedNamespace {
public class SomethingElse
{
private MyClass _myClass; // <-- the type "MyClass" STILL cannot be found.
}
}
I also tried something like global::FindMe
, just in case. But it was not found either. Rider tells me: Cannot resolve symbol 'FindMe'
. Unity tells me: The type or namespace name 'FindMe' could not be found in the global namespace (are you missing an assembly reference?)
.
I must be missing something obvious, but what?
Furthermore, in Rider, the contents of the "Refactor" menu are pretty much all greyed out when I try to use it on the class MyClass
. I don't know if that's significant. I tried restarting after invalidating the cache.
Again, this is a huge project, with many unused files. I'm trying to clean it up. This class needs to be kept. This is why I'm not sharing the actual code. It looks... icky.
But what am I missing?