What does the Access Modifier option actually do in a RESX file?
Asked Answered
H

1

6

When modifying a RESX file, I've noticed the "Access Modifier" option in the top toolbar.

enter image description here

There are three different options: public, internal, and no code generation. I'm guessing these determine which applications have access to these resource files, but I'm not exactly sure what the difference between the three options are.

  1. I would assume public resources can be accessed from any project within the solution.

  2. I would assume internal resources can only be accessed by the project in which the resource is defined.

  3. I don't know what no code generation does.

What do the three options actually mean?

Hereditable answered 13/1, 2017 at 15:29 Comment(1)
Along the resx file you get a class named after your resource file with properties to easily access the resources in your resx file. The Access Modifier is for the visibility of this generated class. Or in case of 3 that you won't get such a class and have to do the hardwork at getting the resources out of the resx yourself. Like creating a Resourcmanager, loading the resource file, locating the entry etc.Carburize
R
4

Your assumptions about 1 and 2 are correct.

Try setting the access modifier of a resource item which is used outside of the project in which it was defined from 'Public' to 'Internal' and then build your project again. You will get compiler errors similar to :

error CS0122: 'Resource' is inaccessible due to its protection level

  1. 'No code generation' means a designer file like 'Resource.Designer.cs' doesn't get created:

enter image description here

Rodrickrodrigez answered 29/1, 2019 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.