✅ How do I reference a specific private instance of a class
I would like to know how I could reference a specific instance of a class, if the class is private and I'm in a different class
18 Replies
Are both in the same project?
no
If so, then just... do
private
classes are private to the assembly, project
Still available anywhere else in the project
Unless the class is nestedI know of some ways to get access to it if its not private but I can't seem to get it with reflection
No need to use reflection
A private class can just be used
It's private to the project
So available anywhere within the project
I edited the message, Its a different project
for context I am making a mod
Is there a way to do it with reflection?
You would have to go through the assembly
what do you mean by go through the asssembly?
typeof(SomePublicClass).Assembly
IIRC
This will contain data of the project that contains that public classthe class is public but the instance is private
and I already have access to the class
Well, is the instance stored in a field? Property?
Classname previousPlayerHeldBy;
So a field
yes
Should be as simple as googling "c# get private field reflections" then
I have googled for hours
You're either lying or you're not googling well
https://www.c-sharpcorner.com/blogs/setting-and-getting-private-variable-of-a-class-without-properties
Second result under the very search query I mentioned
I'm just bad at googling I guess
thank you for the help