Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Visual Studio - IDE0044 Make field readonly

Discussion in 'External Tools' started by APSchmidt, 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. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,447
    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: Nov 24, 2018
  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. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,447
    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.
     
unityunity