Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Visual Studio - IDE0044 Make field readonly

Discussion in 'Code Editors & IDEs' started by Deleted User, Nov 24, 2018.

?

What do you do in the case described below?

Poll closed Apr 6, 2019.
  1. I ignore the warning because it's not code related.

    40.0%
  2. I make the field readonly.

    0 vote(s)
    0.0%
  3. I choose "encapsulate" and use the property.

    0 vote(s)
    0.0%
  4. I choose "encapsulate" but still use the field.

    0 vote(s)
    0.0%
  5. I suppress the warning.

    40.0%
  6. Depends (please, elaborate, thank you).

    20.0%
  1. Deleted User

    Deleted User

    Guest

    I'm new at using Visual Studio. Each time I write a private variable in a script the first letters of the name I give to it is underlined because I use lowercase letters.

    The proposed fixes are:
    1. make field readonly,
    2. encapsulate field: "" (and use property),
    3. encapsulate field: "" (but still use field),
    4. suppress IDE0044 either in Source or in Suppression File.
    I hesitate between:
    1. ignoring the warning because it's not code related (my default choice for now),
    2. making the field readonly,
    3. suppressing IDE044.
    What should I do? :)

    Sans-titre-1.jpg
     
    Last edited by a moderator: Nov 24, 2018
    BIGNIKita likes this.
  2. DiD92

    DiD92

    Joined:
    Feb 11, 2019
    Posts:
    1
    Be aware that marking a field readonly will make Unity unable to serialize it, so even if it may be detected by the IDE as a candidate for being marked readonly, doing so may break your code because you'll loose serialization capabilities for it.
     
  3. Deleted User

    Deleted User

    Guest

    Thanks for the advice. :)
     
  4. andrewhoke

    andrewhoke

    Joined:
    Aug 29, 2018
    Posts:
    22
    Those can be ignored in 90% of cases. Visual Studio doesn't know about all the ways Unity interacts with your source files, such as Editor serialization.