Search Unity

Resolved Will Unity build if I use "dynamic"? OR how to pass generic through interface?

Discussion in 'Scripting' started by Ne0mega, Sep 10, 2021.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    EDIT: Ive already changed the pattern so no "dynamic" is needed, but still would welcome insight.

    I used the keyword dynamic in an interface, and now am trying to pass a Dictionary<string, dynamic> through it.

    Everything looks good, and in fact "dynamic" is working for somethings, however I get a build compile error:

    https://www.4beginner.com/Exception...Microsoft.CSharp.RuntimeBinder.Binder.Convert

    when trying to pass it through an interface.
    EDIT: looks like I cant pass it at all.

    Everybody says install NuGet and the Micrososft.CSharp package, but, if it is not compiling for me, it must not be in Unity or in any other packages, so I want to make sure it will build before I continue with this programming pattern.
     
    Last edited: Sep 10, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    I know there are people who have used the dynamic keyword and lived to brag about it, but there are a lot more people posting here who have endless difficulties with it, since like any late-binding technology, it requires workarounds to prevent constructor code stripping, it (probably) won't work at all with AOT compilation targets (iOS and/or Android), and all manner of other issues.

    The only case I would consider it is if you are ONLY targeting Windows machines, and you are willing to go through all the anti-stripping steps, plus go through them in the future when Unity changes and now starts stripping essential constructors, which happens from time to time.

    Good Lord, that should be the LAST thing you should ever try. What a disaster of uselessness. Our team tried using NuGet for years and it was a constant hassle with getting dependencies wrong, unexpected updates, source control conflicts, ceaseless tinkering with our CI / CD system, it was AWFUL. Do not want.
     
    Ne0mega likes this.