user2136963
user2136963

Reputation: 2606

How to pass IComparer to SortedDictionary in .net?

Comparison class:

#pragma strict
public class TEffectComparator implements IComparer
{
    public function TEffectComparator()
    {

    }
    public static function Compare (f,s)
    {
        if(!f||!s)
            return 0;
        var fe=get_var(f,"essential");
        var se=get_var(s,"essential");
        var t:boolean=op_GreaterThan((fe as TEssential),(se as TEssential));
        if(t==true)
            return 1;
        return -1;
    }
}

This produces error:

var s:SortedDictionary.<TEssential,Object> = new SortedDictionary.<TEssential,Object> (new TEffectComparator());

Assets/effects/terminal/apply_movement.js(21,32): BCE0004: Ambiguous reference 'constructor': System.Collections.Generic.SortedDictionary..constructor(System.Collections.Generic.IDictionary.), System.Collections.Generic.SortedDictionary..constructor(System.Collections.Generic.IComparer.).

It seems, that my ide can't distinguish between IComparer and IDictionary in this case. Why?

#pragma strict
public class TEffectComparator implements IComparer.<TEssential>
{
    public function TEffectComparator()
    {

    }
    public static function Compare (f,s)
    {
        if(!f||!s)
            return 0;
        var fe=get_var(f,"essential");
        var se=get_var(s,"essential");
        var t:boolean=op_GreaterThan((fe as TEssential),(se as TEssential));
        if(t==true)
            return 1;
        return -1;
    }
}

Throws

Assets/scripts/TEffectComparator.js(2,43): BCE0138: 'System.Collections.IComparer' is not a generic definition.

Upvotes: 1

Views: 115

Answers (1)

user2136963
user2136963

Reputation: 2606

As Lee said, System.Collections.Generic.IComparer< T > should be used there, not System.Collections.IComparer.

Upvotes: 1

Related Questions