I have been taught to include the company name and project in namespaces: MyCompany.MyProject.Board. But my file structure is: Assets\Scripts\Board, so Rider complains because the namespace doesn’t match the file location. So my first question is: how should I be doing file structures and namespaces?
Secondly, the following code refuses to recognise my Board class, and forces me to prefix it with the namespace so I end up having to type Board.Board.
using MyGame.Board;
namespace MyGame.Game
{
public class Agent
{
private Board.Board board;
}
}
It’s normal namespace behavior. You have namespace MyGame.Board with Board class inside so if you use in other file MyGame.Game you are already in the MyGame namespace and we don’t know if you are calling Board as a namespace or Board as a class. It’s why you are forced to u see Board.Board as type.
I just recently finished compiling a class library with 21 separate dlls that all use a single namespace. I haven’t had any problems with it. I haven’t used Rider yet, but Visual Studio doesn’t complain, and I would be willing to bet that you could supress Rider from finger wagging via some configuration setting if you prefer different namespace structure.
Here is an example of what I understand from the above topic.
namespace MyGame.Board
{
public class Board
{
}
}
using MyGame.Board;
namespace MyGame.Game
{
public class Agent
{
private Board board; // Error CS0118 'Board' is a namespace but is used like a type
}
}
Yes, I have no issue with your answer. I’m sure that is indeed the problem.
I was only suggesting to ShiftyGames that they are not required to use a rigid namespace structure if it will help them to define namespaces in a way that is more convenient and does not cause the issue in the first place.
Use the same folder naming as in the namespace. If you have a Scripts in there or a Runtime folder that should not be part of the namespace you can right click that folder in Rider and uncheck the „Namespace provider“ flag.