- Home /
Dynamic keyword (.NET 4.X) for iOS - alternatives? Or workarounds?
Hi,
I want to use the dynamic keyword (e.g. could be a float, or an int, or a string, etc).
Is there a workaround for this, because it doesn't seem supported and the workaround detailed in this issue does not work - https://issuetracker.unity3d.com/issues/il2cpp-notsupportedexceptions-exception-is-thrown-in-build-with-newtonsoft-dot-json-plugin
I don't know why the issue got closed, there wasn't a reason when it got marked "Not Fixed".
Thank you.
Answer by Chris9465 · Sep 01, 2021 at 07:29 PM
710 people following this question. 0 answers. Bump.
I will say as of right now though--pursuing this avenue is a waste of time and resources. Implement statically typed functions for your code. It may be difficult depending on how much you have, but because IL2CPP is an AOT compiler, it will most likely never support any kind of dynamic type not known at compile time.
You could cast the item to an Object at compile time and then cast the Object to whatever type you need later.
Well, most people do not actually follow the question because people are counted who follow any of the used tags. Since the tag "C#" is used you get tons of people being autosubscribed to this question.
Answer by Bunny83 · Sep 01, 2021 at 08:26 PM
What Chris said in his answer is pretty spot on. However I think I should point out some facts about the dynamic type. The dynamic type was never meant to be used as a normal managed type. It was introduced to simplify bridging with other untyped languages or to work with COM object interfaces.
Please read this documentation carefully. The dynamic type is essentially the same thing as "object", just with some additional compiler magic and runtime boilerplate. This makes this type rather dangerous and also slow and a huge performance issue. Almost all type and member checks are essentially delayed and implemented in runtime code which makes the usage extremely slow. Since the dynamic type is essentially the type "object", it means that primitive types are most likely boxed and generate garbage. Even if it doesn't, it's most likely by some orders of magnitude slower. It makes debugging much more difficult since the compiler can not really help you with any potential issues. So you really should stay away from the dynamic type whenever possible.
If it's absolutely necessary for iOS, maybe Swift would be a better language to learn and build their app in.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
create a dynamic menu 1 Answer