C
C#8mo 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
Angius8mo ago
Are both in the same project?
Shell-Caster
Shell-CasterOP8mo ago
no
Angius
Angius8mo 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-CasterOP8mo 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
Angius8mo 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-CasterOP8mo 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
Angius8mo ago
You would have to go through the assembly
Shell-Caster
Shell-CasterOP8mo ago
what do you mean by go through the asssembly?
Angius
Angius8mo ago
typeof(SomePublicClass).Assembly IIRC This will contain data of the project that contains that public class
Shell-Caster
Shell-CasterOP8mo ago
the class is public but the instance is private and I already have access to the class
Angius
Angius8mo ago
Well, is the instance stored in a field? Property?
Shell-Caster
Shell-CasterOP8mo ago
Classname previousPlayerHeldBy;
Angius
Angius8mo ago
So a field
Shell-Caster
Shell-CasterOP8mo ago
yes
Angius
Angius8mo ago
Should be as simple as googling "c# get private field reflections" then
Shell-Caster
Shell-CasterOP8mo ago
I have googled for hours
Angius
Angius8mo 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-CasterOP8mo ago
I'm just bad at googling I guess thank you for the help
Want results from more Discord servers?
Add your server