I'm new to StackOverflow.
I'm working on a C# WinForms project including a self-made DLL. I have several variables in my DLL that are used in my project. However, I would like these variables accessible to my project but readonly. They could only be modified by the DLL internally.
Naturally, I made custom getters/setters on these variables. My DLL correctly generates, my project correctly compiles, but on execution it freezes when trying to access a DLL variable (no error messages).
Here's some of my code:
DLL:
namespace ProductSelection
{
public class Products{
// First called by ReadFile
public static int Count
{
get
{
return Count;
}
set
{
Count = value;
}
}
// Called by ReadSystemConfiguration
internal static bool ReadFile(string File)
{
try
{
// (..)
//JSON Array read from file
JArray array = (JArray)jsondata["products"];
Count = array.Count;
// (..)
}
catch(){}
}
// Called by project
public static bool ReadSystemConfiguration(string File)
{
try
{
// (..)
ReadFile(string File);
}
catch (){}
}
}
}
Project main Form class:
using ProductSelection;
namespace MyProject
{
public partial class F_Main : Form
{
// Variables
public static Products F_Products = new Products();
// Constructor
public F_Main()
{
InitializeComponent();
// (..)
Products.ReadSystemConfiguration("File.txt");
}
}
}
Without the getter/setter (just public static int Count;)my code runs perfectly, but Count can be modified in my project. I tried to put private set or internal set but nothing worked.
How can I be able to this:
int value = Products.Count;
But not this:
Products.Count = 5;
Thank you very much for your help !
Nicola.