Search code examples
c#.net.net-3.5tokensharpmap

.Net 3.5 VS 2008 invalid token 'out' error


I am trying to compile SharpMap for .Net 3.5, I have sorted through most of the errors and the only error I get at the moment is:

Invalid token 'out' in class, struct, or interface member declaration

Invalid token '>' in class, struct, or interface member declaration

Type expected

The error is situated at the beginning (line 36) of this file. Here is the code (error in first line).

public interface ISpatialIndexItem<out TOid>
{
    /// <summary>
    /// Gets the object's identifier
    /// </summary>
    TOid ID { get; }

    /// <summary>
    /// Gets the spatial extent of the object
    /// </summary>
    Envelope Box { get; }
}

Also, I was unable to find out what is TOid and what library it is coming from. I am using VS 2008 .Net 3.5 and I can't upgrade due to specifics of the project I am working on.


Solution

  • Covariant and contravariant generic type parameters (the out) were new in .NET 4.0 and C# 4, so you can't use that. You could just remove the out, but some other pieces may then refuse to work :/ There isn't an easy fix for that, except perhaps manual casting.

    TOid isn't coming from anywhere; it is the generic type parameter. By comparison, it is the T in List<T>; it is whatever the caller wants it to be. If the caller cites ISpatialIndexItem<int>, then TOid is int.