C
C#2y ago
MrScautHD

❔ 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!
37 Replies
MrScautHD
MrScautHDOP2y ago
Is there a way to get acces?
Buddy
Buddy2y ago
Internal means only that assembly can access it. So only the framework 'Easel' can access it. And you are not recommended to use it any other way.
FusedQyou
FusedQyou2y ago
You can probably just use reflection to call it Not sure if it works for internal methods This probably works:
typeof(Time).GetMethod("Initialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Invoke(null, new object[] { });
typeof(Time).GetMethod("Initialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Invoke(null, new object[] { });
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. Just keep in mind private or internal probably means whatever library you use probably does not intent for you to use it Might even break in the future
MrScautHD
MrScautHDOP2y ago
the method get not called
FusedQyou
FusedQyou2y ago
amio
amio2y ago
It's a horrible thing to do anyway
MrScautHD
MrScautHDOP2y ago
i tried it with a brake point it get not called
amio
amio2y ago
Do not call unavailable members with reflection, things will break because they don't expect it
FusedQyou
FusedQyou2y ago
Well idk Like I said, if it's accessor is private, internal, file, whatever, it probably is not supposed to be called anyway.
MrScautHD
MrScautHDOP2y ago
they just did it because the framework thought not about the server
FusedQyou
FusedQyou2y ago
Isn't there some source code somewhere? Perhaps you can copy the method, make your own, and do whatever it's supposed to yourself Assuming whatever it's supposed to do is not call more non public stuff
MrScautHD
MrScautHDOP2y ago
but then i need everytime when it updates make a own update too...
FusedQyou
FusedQyou2y ago
Also I have no idea what you mean with this. If you get an error, share the error.
MrScautHD
MrScautHDOP2y ago
i got no error its just like the method get not called
FusedQyou
FusedQyou2y ago
Well, then considering it's active, perhaps suggest the devs to make the method publicly available. Then it might not be found. You should check that.
MrScautHD
MrScautHDOP2y ago
the dev want to add in generel a support for servers but the prority of other things are higher :/
FusedQyou
FusedQyou2y ago
Then perhaps you can make a pull request yourself and turn it public I assume a simple change will be looked at quickly if it's so important If not, it would probably have a good reason
MrScautHD
MrScautHDOP2y ago
nah its not just this everything works like that by him SceneManager UpdateManager...
FusedQyou
FusedQyou2y ago
Noo idea what you mean
MrScautHD
MrScautHDOP2y ago
nvm but do you know why it does not call the method with the reflection?
FusedQyou
FusedQyou2y ago
No, reflection can be unreliable Might be the compiler inlining the method or simply something happening the the method which causes it to not exist Might be the call itself not being done properly Maybe the method is actually public, or maybe it's not static and you simply need to change the bindingflags If you have no idea how it works or how to fix it, maybe don't use it
MrScautHD
MrScautHDOP2y ago
ok i got it work thxx
FusedQyou
FusedQyou2y ago
How did you fix it?
MrScautHD
MrScautHDOP2y ago
no you one did work but C# disable the debugger on this methods so it get called but the debugger does not print things or something out from this method
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
arion
arion2y ago
Things are usually internal or private for a reason. Using reflection to circumvent that should mean that you fully understand that you're going against the intention of the person who implemented the original members, like the guys above said, things break when touched incorrectly. If you do choose to go further into reflection, you can cache method calls by creating a delegate (it cuts down on the time needed for executing that method / property info at the small expense of a heap allocation)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Buddy
Buddy2y ago
It's internal for a reason, the library contributors / owner does not want people to use said thing. Don't do it any other way but the official way. Unexpected things can happen.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
arion
arion2y ago
Your framework you use seems to be calling that method here: https://github.com/piegfx/Easel/blob/db37e800faa9eeecf9e93eb51c8d432d56f7d590/Easel/EaselGame.cs#L173 which is public if field is null in that, wouldnt the NRE trigger at the if statement? there's the null check further down inside of the if check inside
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
arion
arion2y ago
lmao
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MrScautHD
MrScautHDOP2y ago
?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MrScautHD
MrScautHDOP2y ago
i not wanna start the graphic things but what ever the owner of it made it for me so its now splited 🙂
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server