[Mono-dev] Mono 2.8 regression

Tom Spink tspink at gmail.com
Mon Dec 20 05:11:59 EST 2010


Hello,

You could propagate the abstract method type parameter out to the
class definition:

///
public abstract class A<T>
{
  public abstract Func<string, int, T> GetXXX();
}
///

Then, override as follows:

///
public class C<T> : A<T>
{
  Func<string, int, T> xxx;

  public override Func<string, int, T> GetXXX()
  {
    return xxx;
  }
}
///

(or if you want to be absolutely terrible you could do this cast instead:)

///
public override Func<string,int,S> GetXXX<S>()
{
  return (Func<string,int,S>)(object)xxx;
}
///

(but if you ever tell anyone I told you to do that...)

-- Spink

On 20 December 2010 09:27, Federico Di Gregorio <fog at initd.org> wrote:
> On 20/12/2010 10:15, Jb Evain wrote:
>> On Mon, Dec 20, 2010 at 10:01 AM, Federico Di Gregorio <fog at initd.org> wrote:
>>> > I'd like to have someone tell me «Eck! Whay did you do that? That's wrong!».
>> Eck! Why did you do that? That's wrong!
>>
>> (You're welcome ;)
>>
>>> > test.cs(15,16): error CS0030: Cannot convert type
>>> > `System.Func<string,int,T>' to `System.Func<string,int,S>'
>> Right, in the code you posted, there's no relation between T and S. So
>> naturally, you can't convert from one to the other. Just as you can't
>> convert Func<string, int> to Func<string, string>.
>>
>> So It's not a regression, it's more like a bug fix.
>
> Yep, the full subject was "Mono 2.8 regression _in my code_". :)
>
> Now, there is any way to force such a cast (I am _sure_ S and T are
> exactly the same type)? If not, alas, I can write slightly more
> complicated code to do the same thing...
>
> federico
>
> --
> Federico Di Gregorio                                       fog at initd.org
>  I terminali seriali sono in via di estinzione (infatti quello che
>   c'era si è estinto)                                 -- Simone Caldana
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>



-- 
Tom Spink


More information about the Mono-devel-list mailing list