Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Annotations in Unity assemblies are not understood by R# as usual #337

Closed
aybe opened this issue Jan 24, 2018 · 1 comment
Closed

Annotations in Unity assemblies are not understood by R# as usual #337

aybe opened this issue Jan 24, 2018 · 1 comment
Labels
Milestone

Comments

@aybe
Copy link

aybe commented Jan 24, 2018

Beside being a lame design decision to have attributes in Unity itself, R# does not process them as usual.

Example:

public sealed class ColorComponentProperties
{
    public SerializedProperty Name { get; }
    public SerializedProperty Minimum { get; }
    public SerializedProperty Maximum { get; }
    public SerializedProperty Value { get; }

    public ColorComponentProperties(
        [NotNull] SerializedProperty name,
        [NotNull] SerializedProperty minimum,
        [NotNull] SerializedProperty maximum,
        [NotNull] SerializedProperty value)
    {
        if (name == null)
            throw new ArgumentNullException(nameof(name));

        if (minimum == null)
            throw new ArgumentNullException(nameof(minimum));

        if (maximum == null)
            throw new ArgumentNullException(nameof(maximum));

        if (value == null)
            throw new ArgumentNullException(nameof(value));

        Name = name;
        Minimum = minimum;
        Maximum = maximum;
        Value = value;
    }
}

If you add [PublicApi] to the class itself, R# normally will stop bugging you for all public properties; this happens when you use the NuGet package as well as manually adding annotations to a project.

In Unity projects however, R# does not react the same, it still sees those public properties as 'could be made private'.

Note that this happens with default settings on Options/Code annotations.

Thanks !

@citizenmatt citizenmatt added this to the Rider 2018.1 milestone Feb 18, 2018
@citizenmatt
Copy link
Member

This is because the attributes that Unity has included in UnityEngine.dll are an old version. Specifically, the [PublicAPI] attribute is marked with [MeansImplicitUse], whereas it should be marked with [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)].

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants