SiliconStudio / xenko

Old repo for Xenko Game Engine. Please use https://github.com/xenko3d/xenko instead.
http://xenko.com
1.54k stars 344 forks source link

Check [NotNull] in the game studio #662

Open stefnotch opened 6 years ago

stefnotch commented 6 years ago

The use case would be making sure that every entity has all required components. For example, a player controller component (move the player with the keyboard) needs a camera.

public class PlayerControllerComponent: SyncScript
{
    //Game Studio doesn't seem to check this, which makes it rather useless
    [NotNull]
    public CameraComponent Camera { get; set; }
}

Though, only public properties which can be edited in the game studio should be checked.

Kryptos-FR commented 6 years ago

That is not the purpose of NotNull. It is a design-time only attribute used to let ReSharper do a static analysis to detect wrong usages of nullability.

See: https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html

stefnotch commented 6 years ago

@Kryptos-FR Oh, I assumed that it didn't have anything to do with that [NotNull] attribute, since it's defined inside SiliconStudio.Core.Annotations.

Well, what would be an alternative to achieve what I want to achieve? It's not that uncommon that a component needs a reference to another component to work properly.

Checking it in code would require me to write a lot of extra code that I would prefer to avoid writing. Also, it would be a runtime check rather than a game-studio-time check.

Dependency injection would be one alternative that I can think of right now.