C#
C#

help

Root Question Message

MrScautHD
MrScautHD2/20/2023
❔ How can i acces to a Method that is internal?

Hello i use a Framework called Easel, and i try to acces to the Time.Initialize() Method to create a Timer on the Server side too.

If anyone has a idea todo it let me pls know!
MrScautHD
MrScautHD2/20/2023
Is there a way to get acces?
Buddy
Buddy2/20/2023
Internal means only that assembly can access it.
Buddy
Buddy2/20/2023
So only the framework 'Easel' can access it.
Buddy
Buddy2/20/2023
And you are not recommended to use it any other way.
FusedQyou
FusedQyou2/20/2023
You can probably just use reflection to call it
FusedQyou
FusedQyou2/20/2023
Not sure if it works for internal methods
FusedQyou
FusedQyou2/20/2023
This probably works:
typeof(Time).GetMethod("Initialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Invoke(null, new object[] { });
FusedQyou
FusedQyou2/20/2023
Using reflection, gets method Initialize from type Time, which must be static and non public (so internal works), and then invokes it without an instance reference, nor any arguments.
FusedQyou
FusedQyou2/20/2023
Just keep in mind private or internal probably means whatever library you use probably does not intent for you to use it
FusedQyou
FusedQyou2/20/2023
Might even break in the future
MrScautHD
MrScautHD2/20/2023
the method get not called
FusedQyou
FusedQyou2/20/2023
amio
amio2/20/2023
It's a horrible thing to do anyway
MrScautHD
MrScautHD2/20/2023
i tried it with a brake point
MrScautHD
MrScautHD2/20/2023
it get not called
amio
amio2/20/2023
Do not call unavailable members with reflection, things will break because they don't expect it
FusedQyou
FusedQyou2/20/2023
Well idk
FusedQyou
FusedQyou2/20/2023
Like I said, if it's accessor is private, internal, file, whatever, it probably is not supposed to be called anyway.
MrScautHD
MrScautHD2/20/2023
they just did it because the framework thought not about the server
FusedQyou
FusedQyou2/20/2023
Isn't there some source code somewhere?
FusedQyou
FusedQyou2/20/2023
Perhaps you can copy the method, make your own, and do whatever it's supposed to yourself
FusedQyou
FusedQyou2/20/2023
Assuming whatever it's supposed to do is not call more non public stuff
MrScautHD
MrScautHD2/20/2023
but then i need everytime when it updates
MrScautHD
MrScautHD2/20/2023
make a own update too...
FusedQyou
FusedQyou2/20/2023
Also I have no idea what you mean with this. If you get an error, share the error.
MrScautHD
MrScautHD2/20/2023
i got no error
MrScautHD
MrScautHD2/20/2023
its just like the method get not called
FusedQyou
FusedQyou2/20/2023
Well, then considering it's active, perhaps suggest the devs to make the method publicly available.
FusedQyou
FusedQyou2/20/2023
Then it might not be found. You should check that.
MrScautHD
MrScautHD2/20/2023
the dev want to add in generel a support for servers
MrScautHD
MrScautHD2/20/2023
but
MrScautHD
MrScautHD2/20/2023
the prority of other things are higher
MrScautHD
MrScautHD2/20/2023
:/
FusedQyou
FusedQyou2/20/2023
Then perhaps you can make a pull request yourself and turn it public
FusedQyou
FusedQyou2/20/2023
I assume a simple change will be looked at quickly if it's so important
FusedQyou
FusedQyou2/20/2023
If not, it would probably have a good reason
MrScautHD
MrScautHD2/20/2023
nah its not just this
MrScautHD
MrScautHD2/20/2023
everything works like that
MrScautHD
MrScautHD2/20/2023
by him
MrScautHD
MrScautHD2/20/2023
SceneManager
MrScautHD
MrScautHD2/20/2023
UpdateManager...
FusedQyou
FusedQyou2/20/2023
Noo idea what you mean
MrScautHD
MrScautHD2/20/2023
nvm
MrScautHD
MrScautHD2/20/2023
but do you know why it does not call the method with the reflection?
FusedQyou
FusedQyou2/20/2023
No, reflection can be unreliable
FusedQyou
FusedQyou2/20/2023
Might be the compiler inlining the method or simply something happening the the method which causes it to not exist
FusedQyou
FusedQyou2/20/2023
Might be the call itself not being done properly
FusedQyou
FusedQyou2/20/2023
Maybe the method is actually public, or maybe it's not static and you simply need to change the bindingflags
FusedQyou
FusedQyou2/20/2023
If you have no idea how it works or how to fix it, maybe don't use it
MrScautHD
MrScautHD2/20/2023
ok i got it work
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy