C
C#7mo ago
Shell-Caster

✅ 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
Angius
Angius7mo ago
Are both in the same project?
Shell-Caster
Shell-CasterOP7mo ago
no
Angius
Angius7mo ago
If so, then just... do private classes are private to the assembly, project Still available anywhere else in the project Unless the class is nested
Shell-Caster
Shell-CasterOP7mo ago
I know of some ways to get access to it if its not private but I can't seem to get it with reflection
Angius
Angius7mo ago
No need to use reflection A private class can just be used It's private to the project So available anywhere within the project
Shell-Caster
Shell-CasterOP7mo ago
I edited the message, Its a different project for context I am making a mod Is there a way to do it with reflection?
Angius
Angius7mo ago
You would have to go through the assembly
Shell-Caster
Shell-CasterOP7mo ago
what do you mean by go through the asssembly?
Angius
Angius7mo ago
typeof(SomePublicClass).Assembly IIRC This will contain data of the project that contains that public class
Shell-Caster
Shell-CasterOP7mo ago
the class is public but the instance is private and I already have access to the class
Angius
Angius7mo ago
Well, is the instance stored in a field? Property?
Shell-Caster
Shell-CasterOP7mo ago
Classname previousPlayerHeldBy;
Angius
Angius7mo ago
So a field
Shell-Caster
Shell-CasterOP7mo ago
yes
Angius
Angius7mo ago
Should be as simple as googling "c# get private field reflections" then
Shell-Caster
Shell-CasterOP7mo ago
I have googled for hours
Angius
Angius7mo ago
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
Shell-Caster
Shell-CasterOP7mo ago
I'm just bad at googling I guess thank you for the help
Want results from more Discord servers?
Add your server