4

This is not a duplicated question. I've already searched on SO but I need a different thing.

Is today a way to access an internal class from Razor View, I know that the assembly must be visible and is it yet.

No properties nor methods declared in an "internal" class are accessible from Views by default. I need a way to override this.

Thanks.

User907863
  • 417
  • 1
  • 6
  • 16
  • for what reason you want to do so ? Are you looking for accessing a method /property ? – Shyju Jul 24 '12 at 12:38
  • 2
    It is indifferent. No properties nor methods declared in an "internal" class are accessible from Views by default. I need a way to override this. Thanks. – User907863 Jul 24 '12 at 13:10
  • *I know that the assembly must be visible and is it yet.* Are you mean the `InternalsVisibleTo` attribute? http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx – VJAI Jul 24 '12 at 17:08
  • 1
    I have the same problem. I have a Constants class where all global accessible Constants are stored and need to reference it in the Razor view but I don't want to make the Constants class visible to other assemblies. Anyone solved this yet? – JD Stuart Oct 15 '12 at 19:03

1 Answers1

1

In most cases you can change the class from internal to public. You can use the InternalsVisibleTo when that isn't desirable.

In the case of .Designer.cs files that are auto-generated with resource (.resx) files, you can change the "Access Modifier" to "public" by opening the resx file in the "Designer" view:

If all else fails, you should be able to use reflection to get what you need. See the top answer here for details on that

Best of luck!

GSerg
  • 76,472
  • 17
  • 159
  • 346
stepdo
  • 11
  • 1
  • Seems unfortunately that the InternalsVisibleTo doesn't help with the Razor engine since it generates public classes run time from which the model is exposed. This means that the accessibility level will differ and generate a compile error within Razor, regardless of whether or not InternalsVisible is used or not. – Almund Sep 17 '15 at 19:03