Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since it seems you have access to the source, the easiest approach to expose that variable is to add a public getter to the class in which it resides. An instance of that class will have access to the internal variable.</p> <p><strong>EDIT</strong>: (Added code examples)</p> <p>It is all about where the code accessing the internal value exists. Hopefully the example below will illustrate this for you. Assume that you have a solution with two projects, one called ExternalAssembly, the other MyApplication. MyApplication has a reference to ExternalAssembly to access its classes.</p> <p>Project: ExternalAssembly</p> <pre><code>namespace ExternalAssembly { public class MyClass { internal string hiddenString; public MyClass() { this.hiddenString = "This is my value."; } public string Exposed { get { return this.hiddenString; } } } public class MyClass2 { private MyClass classInstance; public MyClass2() { this.classInstance = new MyClass(); } public string Exposed2 { get { return this.classInstance.hiddenString; } } } } </code></pre> <p>Project: MyApplication</p> <pre><code>namespace MyApplication { using ExternalAssembly; public class CallInternalTest() { MyClass classInstance = new MyClass(); MyClass2 class2Instance = new MyClass2(); // this will fail since hiddenString is an internal variable Console.WriteLine(classInstance.hiddenString); // this will succeed since Exposed is a public member Console.WriteLine(classInstance.Exposed); // this will also succeed since Exposed2 is a public member Console.WriteLine(class2Instance.Exposed2); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload