0
votes

I am trying to use something like this for my Hololens project

public struct FD
{
    public FD(string name, IEnumerable<double> ce)
    {
        Name = name;
        CE = new ReadOnlyCollection<double>(new List<double>(ce));
    }
    public readonly string Name;
    public readonly IReadOnlyList<double> CE;       
}

However Unity does not seem to use .NET 4.5 and therfore there is no IReadOnlyList.

Something similar happened to me in the past with Unity not supporting some features I wanted. However once they pass out of the Unity Editor they can be compiled -or so I remember

So how about this?

public struct FD
{
    public FD(string name, IEnumerable<double> ce)
    {
        Name = name;
        CE = new ReadOnlyCollection<double>(new List<double>(ce));
    }
    public readonly string Name;
#if UNITY_EDITOR
    public readonly IList<double> CE;
#else
    public readonly IReadOnlyList<double> CE;
#endif   
}

In this case when using the unity editor only a IList is consider but once after that the IReadOnlyList is used. What do you think about this? Or what is your approach to use IReadOnlyList with a Hololens project?

1
Too bad it's not supported but maybe just store the list as an enumerabe?Aluan Haddad

1 Answers

1
votes

If you're using an up-to-date version of Unity you can configure your project to use .NET 4.5+ features.

  1. Go to 'Edit' -> 'Project settings' -> 'Player'.

  2. In the settings tab look for 'Other Settings' -> 'Configuration' -> 'Scripting Runtime Version'. Set this to '.NET 4.x Equivalent.'

As of Unity 2018.1 this mode is considered stable and 'ready for widespread use.' As well as IReadOnlyList you can use good stuff like async/await and other modern features.